JBAS-573 eg-stats collector script tracking/updates
authorBill Erickson <berickxx@gmail.com>
Thu, 26 Mar 2015 16:08:34 +0000 (12:08 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Use unix::syslog, which is already installed, instead of custom (?)
Logger module.  Remove CPU and RAM stats, since this are better
monitored via external monitoring (zabbix, nagios, etc.)

Install stats collector and keeplive script to /openils/bin

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/admin-scripts/eg-updater.sh
KCLS/monitor-scripts/eg-stats-collector-remote-log.pl [new file with mode: 0755]
KCLS/monitor-scripts/eg-stats-keepalive.sh [new file with mode: 0755]

index 4d8a3a9..e85920c 100755 (executable)
@@ -358,6 +358,8 @@ function copy_custom_files {
 
     $OSRF cp ./KCLS/utility-scripts/send-print-notices.pl /openils/bin/
 
+    $OSRF cp ./KCLS/monitor-scripts/* /openils/bin/
+
     # copy bin files which are not normally installed into place
     $OSRF cp ./Open-ILS/src/support-scripts/edi_fetcher.pl /openils/bin/
     $OSRF cp ./Open-ILS/src/support-scripts/edi_pusher.pl /openils/bin/
diff --git a/KCLS/monitor-scripts/eg-stats-collector-remote-log.pl b/KCLS/monitor-scripts/eg-stats-collector-remote-log.pl
new file mode 100755 (executable)
index 0000000..9806c5f
--- /dev/null
@@ -0,0 +1,113 @@
+#!/usr/bin/perl
+use strict; use warnings;
+use Getopt::Long;
+use XML::LibXML;
+use Unix::Syslog qw(:macros :subs);
+
+my ($config_file, $timeout, $run_once, $help, $services) = 
+    ('/openils/conf/opensrf.xml', 15, 0, 0, '');
+
+my $FACILITY = LOG_LOCAL5;
+my $LEVEL = LOG_INFO;
+my $LOG_TAG = 'eg-stats';
+
+GetOptions(
+    'config=s' => \$config_file,
+    '1' => \$run_once,
+    'service=s' => \$services,
+    'delay=i' => \$timeout,
+    'help' => \$help
+);
+
+help() && exit if ($help);
+
+openlog($LOG_TAG, 0, $FACILITY); 
+
+$services = $services ? [split(',', $services)] : [];
+
+my @apps;
+my $parser = XML::LibXML->new();
+
+# Return an XML::LibXML::Document object
+my $config = $parser->parse_file($config_file);
+
+@apps = $config->findnodes('/opensrf/default/apps/*');
+
+if (@$services) {
+    my @tmp_apps;
+    for my $s (@$services) {
+        for my $a (@apps) {
+            if ($a->nodeName eq $s) {
+                push @tmp_apps, $a;
+                last;
+            }
+        }
+    }
+    @apps = @tmp_apps;
+
+} else {
+    $services = [ map { $_->nodeName } @apps ];
+}
+
+do {
+
+    my @data = split /\n/s, `ps ax|grep OpenSRF`;
+    my %service_data;
+    for (@data) {
+        if (/OpenSRF (\w+) \[([^\]]+)\]/) {
+            my ($s,$t) = ($2,lc($1));
+            next unless (grep { $s eq $_ } @$services);
+            if (!exists($service_data{$s}{$t})) {
+                $service_data{$s}{$t} = 1;
+            } else {
+                $service_data{$s}{$t}++
+            }
+        }
+    }
+
+    for my $s ( @$services ) {
+        my ($node) = grep { $_->nodeName eq $s } @apps;
+        next unless ($node);
+
+        my $max_kids = $node->findvalue('unix_config/max_children');
+        my $imp_lang = $node->findvalue('language');
+
+        my $lcount = $service_data{$s}{listener} || 0;
+        my $dcount = $service_data{$s}{drone} || 0;
+
+        my $res = sprintf(
+            "[eg-stats] SERVICE ($s) : ".
+            "listener count: $lcount, drone count: $dcount/$max_kids");
+
+        syslog($FACILITY | $LEVEL, $res);
+    }
+
+    $run_once--;
+} while ($run_once != 0 && sleep($timeout));
+
+sub help {
+    print <<HELP;
+
+Evergreen Server Health Monitor
+
+    --config=<config_file>
+        OpenSRF configuration file for Evergreen.
+        Default: /openils/conf/opensrf.xml
+    
+    --1
+        Run once and stop
+
+    --service=<service name>
+        Comma separated list of services to report on. If not supplied, all
+        services are reported.
+
+    --delay=<seconds>
+        Delay time for collecting CPU stats.
+        Default: 5
+
+    --help 
+        Print this help message
+
+HELP
+}
+
diff --git a/KCLS/monitor-scripts/eg-stats-keepalive.sh b/KCLS/monitor-scripts/eg-stats-keepalive.sh
new file mode 100755 (executable)
index 0000000..31ef5b1
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/bash
+# make sure eg-stats collector is always running
+
+count=$(ps ax | grep eg-stats-collector-remote-log.pl | grep -v grep | wc -l)
+
+if [ $count -lt 1 ] ; then
+    /openils/bin/eg-stats-collector-remote-log.pl &
+fi
+