/[pdpsoft]/trunk/nl.nikhef.ndpf.tools/nagios-ndpf-sensors/scripts/check_glite_load_monitor
ViewVC logotype

Contents of /trunk/nl.nikhef.ndpf.tools/nagios-ndpf-sensors/scripts/check_glite_load_monitor

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2585 - (show annotations) (download)
Wed Dec 19 10:55:15 2012 UTC (9 years, 1 month ago) by ronalds
File size: 4284 byte(s)
Release: 0.3.30
    - check_glite_load_monitor plot FTP connections for CreamCE
1 #!/usr/bin/perl
2
3 use strict;
4 use Getopt::Long;
5
6 my $verbose = 0;
7 my $debug = 0;
8 my $mode;
9
10 &GetOptions(
11 'verbose|v' => \$verbose,
12 'debug|d' => \$debug,
13 'wms' => sub { $mode = 'wms'; },
14 'cream' => sub { $mode = 'cream'; },
15 );
16
17 my %retcode = (
18 'OK' => 0,
19 'WARNING' => 1,
20 'CRITICAL' => 2,
21 'UNKNOWN' => 3
22 );
23
24 my $cmd = "";
25 if ( $mode eq "cream" ) {
26 $cmd = &get_path_for_file( "glite_cream_load_monitor", ( "/usr/bin", "/opt/glite/bin" ) );
27 if ( ! $cmd ) {
28 print "UNKNOWN: Could not find glite_cream_load_monitor\n";
29 exit $retcode{UNKNOWN};
30 }
31 $cmd .= " --test --show";
32 }
33 elsif ( $mode eq "wms" ) {
34 my $wmscfg = &get_path_for_file( "glite_wms.conf", ( "/etc/glite-wms", "/opt/glite/etc" ) );
35 my $par = "";
36 if ( $wmscfg ) {
37 ( $debug ) and print STDERR "WMS config file = $wmscfg\n";
38 $par = &get_wms_config_option( "${wmscfg}" );
39 }
40 else {
41 $par = '--oper jobSubmit '
42 . '--load1 10 --load5 10 --load15 10 '
43 . '--memusage 95 --swapusage 25 --diskusage 95 '
44 . '--fdnum 1000 --jdnum 1500 --ftpconn 300 ';
45 }
46 $cmd = &get_path_for_file( "glite_wms_wmproxy_load_monitor",
47 ( "/usr/sbin", "/opt/glite/sbin" ) );
48 if ( $cmd ) {
49 ( $debug ) and print STDERR "script = ${cmd}\n";
50 $cmd = "${cmd} $par ";
51 }
52 else {
53 print "UNKNOWN: Could not find glite_wms_wmproxy_load_monitor\n";
54 exit $retcode{UNKNOWN};
55 }
56 }
57 else {
58 print "UNKNOWN: mode ($mode) not defined or not recognized\n";
59 exit $retcode{UNKNOWN};
60 }
61
62 $debug and print STDERR "cmd: $cmd\n";
63
64
65 # locations for stdout/stderr of glite command
66 my $outfil = "/tmp/load-mon.$$.out";
67 my $errfil = "/tmp/load-mon.$$.err";
68
69 #
70 system( $cmd . "> $outfil 2> $errfil" );
71 my $ret = $? >> 8;
72
73 my $retval;
74 my $msg = "";
75 if ( $ret == 0 ) {
76 $msg = "OK";
77 $retval = $retcode{OK};
78 if ( $verbose ) {
79 open OUT, $outfil;
80 print STDERR ( <OUT> );
81 close OUT;
82 }
83 }
84 elsif ( $ret == 1 ) {
85 # read contents of stderr
86 open ERR, $errfil;
87 my @err = <ERR>;
88 close ERR;
89
90 # ... and make a short summary of trouble
91 my $errstr = '';
92 foreach my $error ( @err ) {
93 if ( $error =~ m/: ([0-9\.%]+).* for ([^:]+):\s*([0-9]+(\.[0-9]*)?)[%]?$/ ) {
94 $errstr .= "$2 = $3 (threshold $1); ";
95 }
96 }
97
98 $msg = "WARNING: $errstr";
99 $retval = $retcode{WARNING};
100 }
101 else {
102 $msg = "UNKNOWN: unexpected return value $ret";
103 $retval = $retcode{UNKNOWN};
104 }
105
106 # collect performance data
107 my $perfdata = "";
108 if ( $mode eq "cream" ) {
109 my ( $ftp_conn, $active_jobs );
110 foreach my $file ( $outfil, $errfil ) {
111 open PERF, $file;
112 while ( my $line = <PERF> ) {
113 if ( $line =~ /active jobs\: (\d+)$/ ) {
114 $active_jobs = $1;
115 # $perfdata .= sprintf " 'active jobs'=%d", $1;
116 }
117 elsif ( $line =~ /FTP Connection\: (\d+)$/ ) {
118 $ftp_conn = $1;
119 # $perfdata .= sprintf " FTP_conn=%d", $1;
120 }
121 }
122 close PERF;
123 $perfdata = sprintf "'active jobs'=%d FTP_conn=%d", $active_jobs, $ftp_conn;
124 }
125 }
126
127 ( ! $debug ) and unlink $outfil, $errfil;
128
129 print "$msg|$perfdata\n";
130 exit $retval;
131
132
133
134
135 sub get_wms_config_option {
136 my $cfgfile = $_[0];
137 my $wms_load_params = "";
138
139 if ( ! open WMSCFG, "$cfgfile" ) {
140 print STDERR "Cannot open $cfgfile: $!\n";
141 return $wms_load_params;
142 }
143
144 while ( <WMSCFG> ) {
145 if ( /^\s*jobSubmit.*(--oper jobSubmit.*)[\'\"];/ ) {
146 $wms_load_params = $1;
147 last;
148 }
149 }
150
151 close WMSCFG;
152
153 return $wms_load_params;
154 }
155
156
157 # find a file in a list of directories
158 # useful to deal with different locations of files for UMD and gLite 3.2
159 sub get_path_for_file($@) {
160 my ($file, @pathlist) = @_;
161
162 foreach my $dir ( @pathlist ) {
163 if ( -f "${dir}/$file" ) {
164 ( $debug ) and print STDERR "found file location: ${dir}/$file\n";
165 return "${dir}/$file";
166 }
167 }
168 ( $debug ) and print STDERR "could not find file location for $file\n";
169 return undef;
170 }

Properties

Name Value
svn:executable *

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28