#!/usr/bin/perl -T ## ## ## load average monitor ## ## (c)2001 Leo Fellermayr ## ########################################################## # Note: this needs a file, e. g. /var/log/loadavg.log, # where the system's load average is written # periodically in (probably cron's job? ;-) # "uptime" or "w" output is sufficient. # # last modification: 11.10.2001, lf ########################################################## # ----- used modules use GD; use Chart::LinesPoints; use strict; # ----- global constants my $logfile = '/var/log/loadavg.log'; # the logfile my $x_last_values = 20; # print last 20 values my $period = 900; # load average logging steps in sec. = 15 min. # ----- read load-average values from our $logfile my @loads = (); open (LOG, "<$logfile"); my @log = ; my @info = stat LOG; close (LOG); # reverse order (values are appended onto the eof) @log = reverse @log; my $lines = 0; # format the load average foreach (@log) { chomp $_; $_ =~ s/.*://g; $_ =~ s/,.*//g; $_ =~ s/ //g; push @loads, $_; $lines++; # only as much as needed ($x_last_values) last if ($lines eq $x_last_values); } # ----- calculate time intervals with unixdate & Co. my $interval; my @intervals = (); # $info[9] contains "file last modified" information, # so this is the last-update time of our logfile, too. my $starttime = $info[9]; my @interval_time = (); # ----- format time like hh:mm for (my $z = 0; $z < $lines; $z++) { $interval = $starttime - $z * $period; @interval_time = localtime ($interval); $interval = sprintf ("%02d:%02d", $interval_time[2], $interval_time[1]); push @intervals, $interval; } # ----- prepare image output my $g = Chart::LinesPoints->new($x_last_values * 40,250); $g->set ('title' => 'Load-Average auf ' . $ENV{'SERVER_NAME'}); $g->set('x_label' => "Uhrzeit"); $g->set('y_label' => "Load"); $g->set('grid_lines' => "true"); $g->set('colors' => [[0,153,0]]); $g->set('legend' => "false"); $g->add_dataset(@intervals); $g->add_dataset(@loads); # ----- output image $g->cgi_gif();