--- projects/cms/source/reports/rrdgraphing/graph.pl 2002/10/21 13:02:58 1.11 +++ projects/cms/source/reports/rrdgraphing/graph.pl 2005/06/29 10:26:40 1.19 @@ -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.11 2002/10/21 13:02:58 tdb Exp $ +# $Id: graph.pl,v 1.19 2005/06/29 10:26:40 tdb Exp $ #------------------------------------------------------------ ## TODO @@ -35,7 +35,7 @@ # -- allow configurable periods of graphs # -- comments, types, etc -my($version) = '$Id: graph.pl,v 1.11 2002/10/21 13:02:58 tdb Exp $'; +my($version) = '$Id: graph.pl,v 1.19 2005/06/29 10:26:40 tdb Exp $'; $| = 1; @@ -45,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 $hex_hash $rrdstep $retry_wait $verbose $quiet }; @@ -101,10 +102,10 @@ if($opts{q}) { # Read the contents of the base directory # and pull out the list of subdirectories (except . and .. :) opendir(DIR, $rrddir); -my(@rrddirlist) = grep { -d "$rrddir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); +my(@rrddirlist) = sort grep { -d "$rrddir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); closedir DIR; -# look through each directoty, as they might +# look through each directory, as they might # contain rrds for a particular machine foreach my $machine (@rrddirlist) { # Read the contents of the directory @@ -135,14 +136,19 @@ foreach my $machine (@rrddirlist) { if($rrd =~ /^(cpu)\.rrd$/) { my(@data); my(@rawdata); + push @data, "AREA:$1:swap:swap#FF00FF:OK:swap cpu "; + 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, "LINE2:$1:idle:idle#00FF00:OK:idle cpu "; - push @data, "LINE2:$1:user:user#0000FF:OK:user cpu "; - push @data, "LINE2:$1:kernel:kernel#00FFFF:OK:kernel cpu"; - push @data, "LINE2:$1:swap:swap#FF00FF:OK:swap cpu "; - push @data, "LINE2:$1:iowait:iowait#FF0000:OK:iowait 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); @@ -150,16 +156,20 @@ foreach my $machine (@rrddirlist) { # although we need it to work out peruse... push @data, "NONE:$1:free:free#CCCCFF:NONE:free memory"; push @data, "NONE:$1:total:total#0000FF:NONE:total 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 @data, "NONE:$1:cache:cache#0000FF:NONE:cache memory\\n"; + # 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"; - push @rawdata, "--upper-limit=100"; - # add some nice values to the legend &addlegend(\@rawdata, "peruse"); + push @rawdata, "LINE2:percacuse#0000FF:% memory cache "; + &addlegend(\@rawdata, "percacuse"); + push @rawdata, "--upper-limit=100"; + push @rawdata, "--base=1024"; # put the total memory on the graph so we can map percentages to real values - push @rawdata, "GPRINT:total:LAST:Current total memory\\: \%.2lf %sMb\\c"; + push @rawdata, "GPRINT:total:LAST:Current total memory\\: \%.2lf %sb\\c"; &makegraph($machine, $1, "Memory Usage for $machine", "% memory in use", \@data, \@rawdata); } if($rrd =~ /^(load)\.rrd$/) { @@ -171,11 +181,11 @@ foreach my $machine (@rrddirlist) { } if($rrd =~ /^(proc)\.rrd$/) { my(@data); - push @data, "LINE2:$1:cpu:cpu#00FF00:OK:cpu processes "; - push @data, "LINE2:$1:sleeping:sleeping#0000FF:OK:sleeping processes"; - push @data, "LINE2:$1:stopped:stopped#00FFFF:OK:stopped processes "; + push @data, "AREA:$1:stopped:stopped#00FFFF:OK:stopped processes "; + 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:zombie:zombie#FF0000:OK:zombie processes "; &makegraph($machine, $1, "Processes on $machine", "no. of processes", \@data); } if($rrd =~ /^(swap)\.rrd$/) { @@ -185,16 +195,17 @@ 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"; + push @rawdata, "--base=1024"; # add some nice values to the legend &addlegend(\@rawdata, "peruse"); # put the total swap on the graph so we can map percentages to real values - push @rawdata, "GPRINT:total:LAST:Current total swap\\: \%.2lf %sMb\\c"; + push @rawdata, "GPRINT:total:LAST:Current total swap\\: \%.2lf %sb\\c"; &makegraph($machine, $1, "Swap Usage for $machine", "% swap in use", \@data, \@rawdata); } if($rrd =~ /^(users)\.rrd$/) { @@ -204,28 +215,29 @@ foreach my $machine (@rrddirlist) { } if($rrd =~ /^(paging)\.rrd$/) { my(@data); - push @data, "LINE2:$1:swapins:swapins#00FF00:OK:swap pages in "; - push @data, "LINE2:$1:swapouts:swapouts#0000FF:OK:swap pages out"; + push @data, "AREA:$1:pageins:pageins#00FF00:OK:pages paged in "; + push @data, "LINE2:$1:pageouts:pageouts#0000FF:OK:pages paged out"; &makegraph($machine, $1, "Paging on $machine", "pages per second", \@data); } - if($rrd =~ /^(disk)-(\S+).rrd$/) { + if($rrd =~ /^(disk)-(\S+)\.rrd$/) { my(@data); my(@rawdata); # we need this lot for our calculations, but we'll never show them - push @data, "NONE:$1-$2:kbytes:kbytes#0000FF:NONE:total size\\n"; + push @data, "NONE:$1-$2:total:total#0000FF:NONE:total size\\n"; push @data, "NONE:$1-$2:used:used#CCCCFF:NONE:used space"; push @data, "NONE:$1-$2:totalinodes:totalinodes#000000:NONE:total inodes"; push @data, "NONE:$1-$2:freeinodes:freeinodes#000000:NONE:free inodes"; # calculate peruse, add it to the graph, and add a legend - push @rawdata, "CDEF:peruse=used,kbytes,/,100,*"; + push @rawdata, "CDEF:peruse=used,total,/,100,*"; push @rawdata, "AREA:peruse#CCCCFF:% disk used "; &addlegend(\@rawdata, "peruse"); # put the total space on the graph so we can map percentages to real values - push @rawdata, "GPRINT:kbytes:LAST:Current total space\\: \%.2lf %sKb\\c"; + push @rawdata, "GPRINT:total:LAST:Current total space\\: \%.2lf %sb\\c"; # calculate perinodeuse, add it to the graph, and add a legend push @rawdata, "CDEF:perinodeuse=totalinodes,freeinodes,totalinodes,LT,freeinodes,0,IF,-,totalinodes,/,100,*"; push @rawdata, "LINE2:perinodeuse#FF4444:% inodes used"; push @rawdata, "--upper-limit=100"; + push @rawdata, "--base=1024"; &addlegend(\@rawdata, "perinodeuse"); # put the total inodes on the graph so we can map percentages to real values push @rawdata, "GPRINT:totalinodes:LAST:Current total inodes\\: \%.2lf %s\\c"; @@ -235,8 +247,55 @@ 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$/) { + my(@data); + my(@rawdata); + 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"; + # 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); + my(@rawdata); + 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"; + # 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_lbracket/(/g; + $nicename =~ s/$hex_rbracket/)/g; + $nicename =~ s/$hex_plus/+/g; + $nicename =~ s/$hex_hash/#/g; + &makegraph($machine, "$type-$name", "Network IO for $machine on $nicename", "bytes per second", \@data, \@rawdata); + } + if($rrd =~ /^(mailq)-(\S+)\.rrd$/) { + my(@data); + my(@rawdata); + push @data, "LINE2:$1-$2:size:size#0000FF:OK:messages"; + &makegraph($machine, "$1-$2", "Mail Queue ($2) Size for $machine", "messages in queue", \@data, \@rawdata); + } # probably a queue with a name like this :) if($rrd =~ /^(\d+)_0\.rrd$/) { my(@data); @@ -276,10 +335,10 @@ if($deleteimgs) { # Read the contents of the graphs directory # and pull out the list of subdirectories (except . and .. :) opendir(DIR, $imgdir); - my(@imgdirlist) = grep { -d "$imgdir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); + 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 @@ -399,7 +458,6 @@ sub addlegend() { push @$dataref, "GPRINT:$name:LAST:Current\\: \%8.2lf %s"; push @$dataref, "GPRINT:$name:AVERAGE:Average\\: \%8.2lf %s"; push @$dataref, "GPRINT:$name:MAX:Max\\: \%8.2lf %s\\n"; - #push @$dataref, "GPRINT:$name:MIN:Min\\: \%8.2lf %s\\n"; } # hacky subroutine to return a colour