From 4f4f42cef252cc7ba855deea7f3027697fdca25a Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 26 Mar 2015 12:08:34 -0400 Subject: [PATCH] JBAS-573 eg-stats collector script tracking/updates 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 --- KCLS/admin-scripts/eg-updater.sh | 2 + .../eg-stats-collector-remote-log.pl | 113 +++++++++++++++++++++ KCLS/monitor-scripts/eg-stats-keepalive.sh | 9 ++ 3 files changed, 124 insertions(+) create mode 100755 KCLS/monitor-scripts/eg-stats-collector-remote-log.pl create mode 100755 KCLS/monitor-scripts/eg-stats-keepalive.sh diff --git a/KCLS/admin-scripts/eg-updater.sh b/KCLS/admin-scripts/eg-updater.sh index 4d8a3a99bd..e85920c724 100755 --- a/KCLS/admin-scripts/eg-updater.sh +++ b/KCLS/admin-scripts/eg-updater.sh @@ -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 index 0000000000..9806c5f0c3 --- /dev/null +++ b/KCLS/monitor-scripts/eg-stats-collector-remote-log.pl @@ -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 < + OpenSRF configuration file for Evergreen. + Default: /openils/conf/opensrf.xml + + --1 + Run once and stop + + --service= + Comma separated list of services to report on. If not supplied, all + services are reported. + + --delay= + 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 index 0000000000..31ef5b1858 --- /dev/null +++ b/KCLS/monitor-scripts/eg-stats-keepalive.sh @@ -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 + -- 2.11.0