Faidon Liambotis has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/306866

Change subject: nagios: make check_sslxNN multithreaded
......................................................................

nagios: make check_sslxNN multithreaded

Run check_ssl (a native import, not a fork/exec) against each cn in a
different thread. This speeds the whole check considerably and makes the
check run under a second (e.g. from ~20s) even in extreme cases of
latency, not seen in our network.

This has not been tested with ePN and is potentially broken with it. ePN
is disabled in production nowadays, so it does not matter much.

Change-Id: Ib4b72f0cb431d59fde20324468078ac42c054335
---
M modules/nagios_common/files/check_commands/check_sslxNN
1 file changed, 25 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/66/306866/1

diff --git a/modules/nagios_common/files/check_commands/check_sslxNN 
b/modules/nagios_common/files/check_commands/check_sslxNN
index 53fe8f8..cb8c126 100755
--- a/modules/nagios_common/files/check_commands/check_sslxNN
+++ b/modules/nagios_common/files/check_commands/check_sslxNN
@@ -30,11 +30,12 @@
 
 use strict;
 use warnings;
+use threads;
 use Nagios::Plugin::Functions qw(nagios_exit max_state %STATUS_TEXT);
 
 # this is required to be in the same directory as us
 use FindBin qw($Bin);
-use lib ($Bin, "$Bin/plugins", "/usr/lib/nagios/plugins");
+use lib ( $Bin, "$Bin/plugins", "/usr/lib/nagios/plugins" );
 require "check_ssl";    ## no critic
 
 sub check_ssl {
@@ -46,26 +47,41 @@
 }
 
 sub run {
-    my ( @exits, @lines );
+    my @threads;
 
     foreach my $domain (DOMAINS) {
         foreach my $prefix ( '', 'en.', 'en.m.' ) {
             my $cn = $prefix . $domain;
 
             my @argv = ( @ARGV, '--cn', $cn );
-            my $e = check_ssl(@argv);
 
-            my $msg = $e->message;
-            $msg =~ s/^\w+ (.+)\n/$1/;
+            # spawn a thread to run the various check_ssls asynchronously
+            my $thr = threads->create(
+                { 'context' => 'list' },
+                sub {
+                    my $e = check_ssl(@argv);
 
-            # prepend with $cn and format in columns to ease debugging
-            $msg = sprintf( '%-30s %s', $cn, $msg );
+                    my $msg = $e->message;
+                    $msg =~ s/^\w+ (.+)\n/$1/;
 
-            push @lines, $msg;
-            push @exits, $e->return_code;
+                    # prepend with $cn and format in columns to ease debugging
+                    $msg = sprintf( '%-30s %s', $cn, $msg );
+
+                    return ( $msg, $e->return_code );
+                }
+            );
+            push @threads, $thr;
         }
     }
 
+    # join all the threads and collect all stdout/return code values
+    my ( @exits, @lines );
+    foreach my $thr (@threads) {
+        my ( $msg, $return_code ) = $thr->join();
+        push @lines, $msg;
+        push @exits, $return_code;
+    }
+
     # build a one-line summary (e.g. "70 OK, 2 WARNING") and set it first
     my %ec;
     $ec{$_}++ foreach @exits;

-- 
To view, visit https://gerrit.wikimedia.org/r/306866
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib4b72f0cb431d59fde20324468078ac42c054335
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Faidon Liambotis <fai...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to