[check_postgres] New action: warm_standby

david.barbion at adeoservices.com david.barbion at adeoservices.com
Tue Jun 28 13:29:05 UTC 2011


Hello,

I've created a small patch for check_postgres.pl that adds a new action: 
warm_standby.
This action checks that the process pg_standby is running for the 
current cluster (depending on the PGPORT env var.).
This patch needs the perl module Proc::ProcessTable available at CPAN.

Any comments appreciated!

Best Regards,
David.

--- ./check_postgres.pl.orig    2011-06-27 11:56:55.000000000 +0200
+++ ./check_postgres.pl    2011-06-27 13:06:30.000000000 +0200
@@ -887,6 +887,7 @@
   txn_wraparound      => [1, 'See how close databases are getting to 
transaction ID wraparound.'],
   version             => [1, 'Check for proper Postgres version.'],
   wal_files           => [1, 'Check the number of WAL files in the 
pg_xlog directory'],
+ warm_standby        => [1, 'Check that postgresql is started in warm 
standby mode (pg_standby)'],
  };

  ## XXX Need to i18n the above
@@ -1410,6 +1411,9 @@
  ## Simple connection, warning or critical options
  check_connection() if $action eq 'connection';

+## Check warm_standby mode
+check_warm_standby() if $action eq 'warm_standby' ;
+
  ## Check the size of one or more databases
  check_database_size() if $action eq 'database_size';

@@ -3141,6 +3145,97 @@
  } ## end of check_connection


+sub is_parent_process {
+    my $process_table_ref = shift ;
+    my @process_table = @$process_table_ref ;
+    my $parent_pid = shift ;
+    my $child_pid = shift ;
+
+    return(0) if($child_pid == 1) ;
+
+    foreach my $p ( @process_table){
+        if ( $p->pid == $child_pid) {
+            # found !
+            if ($p->ppid == $parent_pid) {
+                return(1) ;
+            }else {
+                if (is_parent_process(\@process_table, $parent_pid, 
$p->ppid) == 1) {
+            return(1) ;
+                }
+            }
+        }
+    }
+    return(0) ;
+}
+
+sub check_warm_standby {
+
+    ## Check that postgresql is started in warm standby mode
+    ## Look at the process table for pg_standby command
+    ## No comparisons made: warning and critical are not allowed
+    ## Suports: Nagios, MRTG
+
+    my $postmaster_pid = 0;
+    my $pg_standby_pid = 0;
+    my $found = 0 ;
+
+    if ($opt{warning} or $opt{critical}) {
+        ndie msg('range-none');
+    }
+
+    # get current cluster port or default
+    my $port = $ENV{PGPORT} ;
+    $port = $opt{defaultport} if (!$port) ;
+
+    # FIX: We should return an error if this module not present
+    use Proc::ProcessTable ;
+
+    my $t = new Proc::ProcessTable;
+    #printf($FORMAT, "PID", "TTY", "STAT", "START", "COMMAND");
+    # First, look for the postmaster process at the specified PGPORT
+    foreach my $p ( @{$t->table} ){
+        #print $p->pid." ".$p->ppid." ".$p->cmndline."\n" ;
+        if ( $p->cmndline =~ /postmaster.*$port/) {
+            # found !
+            $postmaster_pid = $p->pid ;
+        }
+    }
+    if ($postmaster_pid == 0) {
+        add_critical "Postmaster PID not found for port $port" ;
+        return ;
+    }
+
+    # Then, look for the pg_standby
+    foreach my $p ( @{$t->table} ){
+        if ( $p->cmndline =~ /pg_standby/) {
+            # found !
+            $pg_standby_pid = $p->pid ;
+            if (is_parent_process(\@{$t->table}, $postmaster_pid, 
$pg_standby_pid) == 1) {
+        # pg_standby running
+        $found = $pg_standby_pid ;
+        }
+        }
+    }
+    if (!$found) {
+        add_critical "pg_standby not running" ;
+    }else {
+        add_ok "pg_standby($found) running" ;
+    }
+    ####
+    #$MRTG and do_mrtg({one => $ver ? 1 : 0});
+
+    #if ($ver) {
+    #    add_ok msg('version', $ver);
+    #}
+    #else {
+    #    add_unknown msg('invalid-query', $db->{slurp}[0]{v});
+    #}
+
+    return;
+
+} ## end of check_connection
+
+
  sub check_custom_query {

      ## Run a user-supplied query, then parse the results


Ce message et toutes les pièces jointes sont établis à l'attention exclusive de leurs destinataires et sont confidentiels. Si vous recevez ce message par erreur, merci de le détruire et d'en avertir immédiatement l'expéditeur. L'internet ne permettant pas d'assurer l'intégrité de ce message, le contenu de ce message ne représente en aucun cas un engagement de la part de Adeo Services.


More information about the Check_postgres mailing list