]> git.evergreen-ils.org Git - contrib/equinox.git/blob - eg-stats/parse-eg-stats.pl
Adding eg-stats files for monitoring Evergreen services
[contrib/equinox.git] / eg-stats / parse-eg-stats.pl
1 #!/usr/bin/perl -w
2 package main;
3 use POSIX;
4 use strict;
5
6
7 #get date info
8 my ($SEC, $MIN, $HOUR, $DAY,$MONTH,$YEAR) = (localtime(time))[0,1,2,3,4,5,6];
9 $YEAR+=1900;
10 $MONTH++;
11 if ($DAY < 10) {
12    $DAY = "0".$DAY;
13 }
14 if ($MONTH < 10) {
15    $MONTH = "0".$MONTH;
16 }
17
18 my $posF = "/tmp/eg_stats_position.log";
19 my $statsF = "/var/log/evergreen/prod/$YEAR/$MONTH/$DAY/eg_stats.log";
20 my $pos; 
21 my $loc;
22 my $status = 0; #status is OK!
23 my $info = "";
24
25 #if it exists open it and get the current position
26 #if not set the current position to 0
27 if (-e $posF) {
28    open(DATA, "<$posF");
29    my @values = <DATA>;
30    if (@values != 2) { #make sure the array is the correct size
31       $pos = 0;
32    } else {
33       chomp($loc = $values[0]);
34       if ($loc ne $statsF) { #check to see that we are in the correct file
35          $pos = 0;
36       } else {
37          chomp($pos = $values[1]); 
38          #check to see if $pos is a valid positive integer(or 0), if not set to 0
39          if (!( $pos =~ /^\d+$/ )) { 
40             $pos = 0;
41          }
42       }
43    }
44    close DATA;
45 } else {
46    $pos = 0;
47 }
48 #parse the file and output for Nagios if necessary
49 if (-e $statsF) {
50    open(DATA, "<$statsF");
51    seek DATA, $pos, 0;
52    while(<DATA>) {
53       my($line) = $_;
54       chomp($line);
55       #check for lost controller first
56       if (($line =~ m/listener count: 0/) || ($line =~ m/controller count: 0/) || ($line =~ m/master count: 0/)){
57          if ($line =~ m/listener count: 0/) {
58             $info = $info."Lost a listener: $line - ";
59          }
60          if ($line =~ m/master count: 0/) {
61             $info = $info."Lost a master: $line - ";
62          }
63          if ($line =~ m/controller count: 0/) {
64             $info = $info."Lost a controller: $line - ";
65          }
66          $status = 2;
67       } 
68       #now check for drone ratio
69       if ($line =~ m/SERVICE/) {
70          my ($count) = $line =~ /drone count: (\d+\/\d+)/i;
71          my $ratio = eval($count);
72          my $pct = ceil($ratio * 100);
73          if ($ratio >= 0.75) {
74             $info = $info."Drone count is $pct % - $line - ";
75             $status = 1;
76          }
77          if ($ratio >= 0.9) {
78             $info = $info."Drone count is $pct % - $line - "; 
79             $status = 2;
80          }    
81       }
82       
83    }
84    $pos = tell DATA;
85    close DATA;
86 } else {
87    $pos = 0;
88 }
89
90 #update position info
91 open(DATA, ">$posF");
92 print DATA "$statsF\n$pos\n";
93 close DATA;
94
95 if ($info eq "") {
96    $info = "EG-STATS-COLLECTOR STATUS: OK!";
97 }
98
99 print $info;
100 exit $status;