root/lib/Resmon/Module/WALCHECK.pm

Revision 88b23a7d436bfc0816732f6186ba714462d4f56e, 1.5 kB (checked in by Mark Harrison <mark@omniti.com>, 10 years ago)

Adding a walcheck module for checking postgres replay mode. Modified slightly
from the one on crank-va-4 do deal with different log directories and logfile
names.

git-svn-id: https://labs.omniti.com/resmon/trunk@73 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

  • Property mode set to 100644
Line 
1 package Resmon::Module::WALCHECK;
2 use Resmon::Module;
3 use Resmon::ExtComm qw/cache_command/;
4 use vars qw/@ISA/;
5 @ISA = qw/Resmon::Module/;
6 use Time::Local;
7
8 # Sample config for resmon.conf
9 # WALCHECK {
10 #   check_pg_replay_mode  : logdir => /data/set/pgdb2/pgdata/82/pg_log
11 # }
12 #
13 # The logdir may also be in /data/postgres/82/pg_log. Check for a pg_log dir
14 # with postgresql-yyyy-mm-dd.log files in.
15
16 #########################
17 sub splittime {
18 my ($val,@list) = @_;
19 my @rv;
20
21 $val = abs($val);
22 foreach my $factor (@list){
23 push @rv,$val%$factor;
24 $val/=$factor;
25 }
26 push @rv,int($val);
27 return @rv;
28 }
29 #########################
30
31 sub handler {
32   my $arg = shift;
33   my $os = $arg->fresh_status();
34   return $os if $os;
35   my $logdir = $arg->{'logdir'};
36   opendir(D, $logdir);
37   my @files = sort grep /^postgresql-[\d-]+.log$/, readdir(D);
38   closedir(D);
39   my $wallog = $files[-1];
40
41   open(F, "<", "$logdir/$wallog");
42   while(<F>) {
43     if(/LOG:  restored log file/) {
44       ($year,$month,$day,$hour,$min) = ( $_ =~ /^(\d\d\d\d)-(\d\d)-(\d\d)\s(\d+):(\d+)/ );
45         $moo = 'moo';
46     }
47   }
48   close(F);
49
50   # subtract 1 to compensate for perl stupidity
51   my $proc = timegm(0,$min,$hour,$day,$month-1,$year);
52
53   my $now = time();
54   my @nn = localtime($now);
55   my $lnow = timegm(@nn);
56
57   my $diff =  $proc - $lnow;
58   my @tsplit = splittime($diff,60,60,24,7);
59
60   if ($diff < -3600)
61   {
62         return $arg->set_status( "BAD(pitr replay is $tsplit[2] hours, $tsplit[1] minutes behind)");
63   } else {
64         return $arg->set_status( "OK(pitr replay is $tsplit[2] hours, $tsplit[1] minutes behind)");
65   }
66 }
67
Note: See TracBrowser for help on using the browser.