--- projects/cms/source/reports/rrdgraphing/graph.pl 2004/03/04 11:27:30 1.13 +++ projects/cms/source/reports/rrdgraphing/graph.pl 2005/06/15 10:41:25 1.17 @@ -2,7 +2,7 @@ # # i-scream central monitoring system -# http://www.i-scream.org.uk +# http://www.i-scream.org # Copyright (C) 2000-2002 i-scream # # This program is free software; you can redistribute it and/or @@ -22,12 +22,12 @@ # ----------------------------------------------------------- # i-scream graph generation script -# http://www.i-scream.org.uk +# http://www.i-scream.org # # Generates graphs from rrd databases for i-scream data. # # $Author: tdb $ -# $Id: graph.pl,v 1.13 2004/03/04 11:27:30 tdb Exp $ +# $Id: graph.pl,v 1.17 2005/06/15 10:41:25 tdb Exp $ #------------------------------------------------------------ ## TODO @@ -35,12 +35,8 @@ # -- allow configurable periods of graphs # -- comments, types, etc -BEGIN { - push (@INC, "/usr/local/packages/rrdtool/lib/perl5/site_perl/5.8.2/sun4-solaris"); -} +my($version) = '$Id: graph.pl,v 1.17 2005/06/15 10:41:25 tdb Exp $'; -my($version) = '$Id: graph.pl,v 1.13 2004/03/04 11:27:30 tdb Exp $'; - $| = 1; use strict; @@ -49,10 +45,11 @@ use RRDs; # define variables that will be read from the config # nb. keep this insync with the config file! -use vars qw{ - $imgdir $rrddir +use vars qw{ + $imgdir $rrddir $maxrrdage $maximgage $deleterrds $deleteimgs - $hex_slash $hex_underscore + $hex_slash $hex_underscore $hex_space $hex_colon $hex_bslash $hex_rbracket + $hex_lbracket $hex_plus $rrdstep $retry_wait $verbose $quiet }; @@ -143,10 +140,15 @@ foreach my $machine (@rrddirlist) { push @data, "STACK:$1:iowait:iowait#FF0000:OK:iowait cpu"; push @data, "STACK:$1:kernel:kernel#00FFFF:OK:kernel cpu"; push @data, "STACK:$1:user:user#0000FF:OK:user cpu "; - #push @data, "STACK:$1:idle:idle#00FF00:OK:idle cpu "; + push @data, "LINE2:$1:idle:idle#00FF00:OK:idle cpu "; push @rawdata, "--upper-limit=100"; &makegraph($machine, $1, "CPU Usage for $machine", "% cpu time", \@data, \@rawdata); } + if($rrd =~ /^(uptime)\.rrd$/) { + my(@data); + push @data, "LINE2:$1:uptime:uptime#0000FF:OK:uptime"; + &makegraph($machine, $1, "Uptime for $machine", "uptime in seconds", \@data); + } if($rrd =~ /^(mem)\.rrd$/) { my(@data); my(@rawdata); @@ -155,10 +157,10 @@ foreach my $machine (@rrddirlist) { push @data, "NONE:$1:free:free#CCCCFF:NONE:free memory"; push @data, "NONE:$1:total:total#0000FF:NONE:total memory\\n"; push @data, "NONE:$1:cache:cache#0000FF:NONE:cache memory\\n"; - # calculate peruse - note that we only use 'free' if it's less than total - # (this is to avoid negative percentages :) - push @rawdata, "CDEF:peruse=total,free,total,LT,free,0,IF,-,total,/,100,*"; - push @rawdata, "CDEF:percacuse=cache,total,LT,cache,0,IF,total,/,100,*"; + # calculate peruse - note that we only use 'free' if it's + # less or equal to total (this is to avoid negative percentages :) + push @rawdata, "CDEF:peruse=total,free,total,LE,free,0,IF,-,total,/,100,*"; + push @rawdata, "CDEF:percacuse=cache,total,LE,cache,0,IF,total,/,100,*"; # and add it to the graph push @rawdata, "AREA:peruse#CCCCFF:% memory in use"; &addlegend(\@rawdata, "peruse"); @@ -183,7 +185,7 @@ foreach my $machine (@rrddirlist) { push @data, "STACK:$1:zombie:zombie#FF0000:OK:zombie processes "; push @data, "STACK:$1:cpu:cpu#00FF00:OK:cpu processes "; push @data, "STACK:$1:sleeping:sleeping#0000FF:OK:sleeping processes"; - #push @data, "LINE2:$1:total:total#FF00FF:OK:total processes "; + push @data, "LINE2:$1:total:total#FF00FF:OK:total processes "; &makegraph($machine, $1, "Processes on $machine", "no. of processes", \@data); } if($rrd =~ /^(swap)\.rrd$/) { @@ -193,9 +195,9 @@ foreach my $machine (@rrddirlist) { # although we need it to work out peruse... push @data, "NONE:$1:free:free#CCCCFF:NONE:free swap"; push @data, "NONE:$1:total:total#0000FF:NONE:total swap\\n"; - # calculate peruse - note that we only use 'free' if it's less than total - # (this is to avoid negative percentages :) - push @rawdata, "CDEF:peruse=total,free,total,LT,free,0,IF,-,total,/,100,*"; + # calculate peruse - note that we only use 'free' if it's + # less or equal to total (this is to avoid negative percentages :) + push @rawdata, "CDEF:peruse=total,free,total,LE,free,0,IF,-,total,/,100,*"; # and add it to the graph push @rawdata, "AREA:peruse#CCCCFF:% swap in use"; push @rawdata, "--upper-limit=100"; @@ -245,6 +247,9 @@ foreach my $machine (@rrddirlist) { my($nicename) = $2; $nicename =~ s/$hex_slash/\//g; $nicename =~ s/$hex_underscore/_/g; + $nicename =~ s/$hex_bslash/\\/g; + $nicename =~ s/$hex_space/ /g; + $nicename =~ s/$hex_colon/:/g; &makegraph($machine, "$type-$name", "Disk Usage for $machine on $nicename", "% usage", \@data, \@rawdata); } if($rrd =~ /^(diskio)-(\S+)\.rrd$/) { @@ -253,7 +258,16 @@ foreach my $machine (@rrddirlist) { push @data, "AREA:$1-$2:rbytes:rbytes#00FF00:OK:read bytes "; push @data, "LINE2:$1-$2:wbytes:wbytes#0000FF:OK:write bytes"; push @rawdata, "--base=1024"; - &makegraph($machine, "$1-$2", "Disk IO for $machine on $2", "bytes per second", \@data, \@rawdata); + # some name tidying + my($type) = $1; + my($name) = $2; + my($nicename) = $2; + $nicename =~ s/$hex_slash/\//g; + $nicename =~ s/$hex_underscore/_/g; + $nicename =~ s/$hex_bslash/\\/g; + $nicename =~ s/$hex_space/ /g; + $nicename =~ s/$hex_colon/:/g; + &makegraph($machine, "$type-$name", "Disk IO for $machine on $nicename", "bytes per second", \@data, \@rawdata); } if($rrd =~ /^(net)-(\S+)\.rrd$/) { my(@data); @@ -261,7 +275,19 @@ foreach my $machine (@rrddirlist) { push @data, "AREA:$1-$2:rx:rx#00FF00:OK:received bytes "; push @data, "LINE2:$1-$2:tx:tx#0000FF:OK:transfered bytes"; push @rawdata, "--base=1024"; - &makegraph($machine, "$1-$2", "Network IO for $machine on $2", "bytes per second", \@data, \@rawdata); + # some name tidying + my($type) = $1; + my($name) = $2; + my($nicename) = $2; + $nicename =~ s/$hex_slash/\//g; + $nicename =~ s/$hex_underscore/_/g; + $nicename =~ s/$hex_bslash/\\/g; + $nicename =~ s/$hex_space/ /g; + $nicename =~ s/$hex_colon/:/g; + $nicename =~ s/$hex_rbracket/(/g; + $nicename =~ s/$hex_lbracket/)/g; + $nicename =~ s/$hex_plus/+/g; + &makegraph($machine, "$type-$name", "Network IO for $machine on $nicename", "bytes per second", \@data, \@rawdata); } if($rrd =~ /^(mailq)-(\S+)\.rrd$/) { my(@data); @@ -311,7 +337,7 @@ if($deleteimgs) { my(@imgdirlist) = sort grep { -d "$imgdir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); closedir DIR; - # look through each directoty, as they might + # look through each directory, as they might # contain images for a particular machine foreach my $machine (@imgdirlist) { # Read the contents of the directory