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
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 unless $status;
88 verbose "Snapshotting load on $system{name}";
91 system => $system{name},
96 ($status, @output) = $clearexec->execute($cmd);
100 # Parsing uptime is odd. Sometimes we get output like
102 # 10:11:59 up 17 days, 22:11, 6 users, load average: 1.08, 1.10, 1.10
104 # And sometimes we get output like:
106 # 10:11:15 up 23:04, 0 users, load average: 0.00, 0.00, 0.00
108 # Notice that if the machine was up for less than a day you don't get the
109 # "x days" portion of output. There is no real controls on uptime to format
110 # the output better, so we parse for either format.
111 if ($output[0] =~ /up\s+(.+?),\s+(.+?),\s+(\d+) user.*load average:\s+(.+?),/) {
112 $load{uptime} = "$1 $2";
114 $load{loadavg} = "$4";
115 } elsif ($output[0] =~ /up\s+(.+?),\s+(\d+) user.*load average:\s+(.+?),/) {
116 $load{uptime} = "$1";
118 $load{loadavg} = "$3";
120 warning "Unable to parse output of uptime from $system{name}";
124 # On Windows sytems, Cygwin's uptime does not return a loadavg at all - it
125 # returns only 0! So we have load.vbs which give us the LoadPercentage
126 if ($system{type} =~ /windows/i) {
127 my $loadvbs = 'c:/cygwin/opt/clearscm/clearadm/load.vbs';
128 $cmd = "cscript /nologo $loadvbs";
130 ($status, @output) = $clearexec->execute($cmd);
132 chop @output if $output[0] =~ /\r/;
136 $load{loadavg} = $output[0] / 100;
139 $clearexec->disconnectFromServer;
146 'usage' => sub { Usage },
147 'verbose' => sub { set_verbose },
148 'debug' => sub { set_debug },
150 ) or Usage "Invalid parameter";
152 Usage 'Extraneous options: ' . join ' ', @ARGV if @ARGV;
155 verbose "$FindBin::Script V$VERSION";
159 for my $system ($clearadm->FindSystem($host)) {
160 next if $system->{active} eq 'false';
162 my %load = snapshotLoad $system;
165 my ($err, $msg) = $clearadm->AddLoadavg(%load);
167 error $msg, $err if $err;
169 error "Unable to get loadavg for system $system->{name}", 1;
172 # Check if over threshold
173 my %notification = $clearadm->GetNotification('Loadavg');
175 next unless %notification;
177 if ($load{loadavg} >= $system->{loadavgThreshold}) {
179 error YMDHMS . " System: $system->{name} "
180 . "Loadavg $load{loadavg} "
181 . "Threshold $system->{loadavgThreshold}";
183 $clearadm->ClearNotifications ($system->{name});
186 # Add graphs to system record
187 my ($loadavgsmall, $loadavg);
189 my $cmd = "plotloadavg.cgi generate=1 system=$system->{name} scaling=Hour points=24";
191 verbose "Generating loadavgsmall for $system->{name}";
192 my ($error, @output) = Execute("$cmd tiny=1 2>&1");
194 error 'Unable to generate loadavgsmall' . join("\n", @output), $error if $error;
196 $system->{loadavgsmall} = join '', @output;
198 verbose "Generating loadavg for $system->{name}";
199 ($error, @output) = Execute("$cmd 2>&1");
201 error 'Unable to generate loadavg' . join("\n", @output), $error if $error;
203 $system->{loadavg} = join '', @output;
205 my ($err, $msg) = $clearadm->UpdateSystem($system->{name}, %$system);
207 error "Unable to udpate system record $msg", $err if $err;
214 =head1 CONFIGURATION AND ENVIRONMENT
216 DEBUG: If set then $debug is set to this level.
218 VERBOSE: If set then $verbose is set to this level.
220 TRACE: If set then $trace is set to this level.
228 L<Getopt::Long|Getopt::Long>
230 L<Net::Domain|Net::Domain>
232 =head2 ClearSCM Perl Modules
247 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
248 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearexec.pm">Clearexec</a><br>
249 <a href="http://clearscm.com/php/scm_man.php?file=lib/DateUtils.pm">DateUtils</a><br>
250 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
251 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
256 =head1 BUGS AND LIMITATIONS
258 There are no known bugs in this script
260 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
262 =head1 LICENSE AND COPYRIGHT
264 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.