5 =head1 NAME $RCSfile: updatela.pl,v $
15 Andrew DeFaria <Andrew@ClearSCM.com>
23 Mon Dec 13 09:13:27 EST 2010
27 $Date: 2011/06/16 15:14:52 $
33 Usage updatela.pl: [-u|sage] [-ve|rbose] [-deb|ug]
37 -u|sage: Displays usage
40 -deb|ug: Output debug messages
42 -host [<host>|all]: Update host or all hosts (Default: all)
43 -fs [<fs>|all]: Update filesystem or all (Default: all)
47 This script will record the load average of a system
54 use Net::Domain qw(hostname);
58 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
66 my $VERSION = '$Revision: 1.29 $';
67 ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
69 my $clearadm = Clearadm->new;
70 my $clearexec = Clearexec->new;
74 # Given a host, formulate a loadavg record
75 sub snapshotLoad ($) {
78 my %system = %{$systemRef};
80 my ($status, @output);
82 $status = $clearexec->connectToServer (
83 $system{name}, $system{port}
86 error "Unable to connect to system $system{name}:$system{port}", 1
89 verbose "Snapshotting load on $system{name}";
92 system => $system{name},
97 ($status, @output) = $clearexec->execute ($cmd);
102 # Parsing uptime is odd. Sometimes we get output like
104 # 10:11:59 up 17 days, 22:11, 6 users, load average: 1.08, 1.10, 1.10
106 # And sometimes we get output like:
108 # 10:11:15 up 23:04, 0 users, load average: 0.00, 0.00, 0.00
110 # Notice that if the machine was up for less than a day you don't get the
111 # "x days" portion of output. There is no real controls on uptime to format
112 # the output better, so we parse for either format.
113 if ($output[0] =~ /up\s+(.+?),\s+(.+?),\s+(\d+) user.*load average:\s+(.+?),/) {
114 $load{uptime} = "$1 $2";
116 $load{loadavg} = "$4";
117 } elsif ($output[0] =~ /up\s+(.+?),\s+(\d+) user.*load average:\s+(.+?),/) {
118 $load{uptime} = "$1";
120 $load{loadavg} = "$3";
122 warning "Unable to parse output of uptime from $system{name}";
126 # On Windows sytems, Cygwin's uptime does not return a loadavg at all - it
127 # returns only 0! So we have load.vbs which give us the LoadPercentage
128 if ($system{type} =~ /windows/i) {
129 my $loadvbs = 'c:/cygwin/opt/clearscm/clearadm/load.vbs';
130 $cmd = "cscript /nologo $loadvbs";
132 ($status, @output) = $clearexec->execute ($cmd);
134 chop @output if $output[0] =~ /\r/;
139 $load{loadavg} = $output[0] / 100;
142 $clearexec->disconnectFromServer;
149 'usage' => sub { Usage },
150 'verbose' => sub { set_verbose },
151 'debug' => sub { set_debug },
153 ) or Usage "Invalid parameter";
155 Usage 'Extraneous options: ' . join ' ', @ARGV
159 verbose "$FindBin::Script V$VERSION";
163 foreach my $system ($clearadm->FindSystem ($host)) {
164 next if $$system{active} eq 'false';
166 my %load = snapshotLoad $system;
169 my ($err, $msg) = $clearadm->AddLoadavg (%load);
171 error $msg, $err if $err;
173 error "Unable to get loadavg for system $$system{name}", 1;
176 # Check if over threshold
177 my %notification = $clearadm->GetNotification ('Loadavg');
180 unless %notification;
182 if ($load{loadavg} >= $$system{loadavgThreshold}) {
184 error YMDHMS . " System: $$system{name} "
185 . "Loadavg $load{loadavg} "
186 . "Threshold $$system{loadavgThreshold}";
188 $clearadm->ClearNotifications ($$system{name});
196 =head1 CONFIGURATION AND ENVIRONMENT
198 DEBUG: If set then $debug is set to this level.
200 VERBOSE: If set then $verbose is set to this level.
202 TRACE: If set then $trace is set to this level.
210 L<Getopt::Long|Getopt::Long>
212 L<Net::Domain|Net::Domain>
214 =head2 ClearSCM Perl Modules
229 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
230 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearexec.pm">Clearexec</a><br>
231 <a href="http://clearscm.com/php/scm_man.php?file=lib/DateUtils.pm">DateUtils</a><br>
232 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
233 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
238 =head1 BUGS AND LIMITATIONS
240 There are no known bugs in this script
242 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
244 =head1 LICENSE AND COPYRIGHT
246 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.