--- projects/cms/source/reports/rrdgraphing/graph.pl 2003/03/10 11:34:43 1.12 +++ 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.12 2003/03/10 11:34:43 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.12 2003/03/10 11:34:43 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,15 +156,18 @@ 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"; + &addlegend(\@rawdata, "peruse"); + push @rawdata, "LINE2:percacuse#0000FF:% memory cache "; + &addlegend(\@rawdata, "percacuse"); push @rawdata, "--upper-limit=100"; push @rawdata, "--base=1024"; - # add some nice values to the legend - &addlegend(\@rawdata, "peruse"); # put the total memory on the graph so we can map percentages to real values push @rawdata, "GPRINT:total:LAST:Current total memory\\: \%.2lf %sb\\c"; &makegraph($machine, $1, "Memory Usage for $machine", "% memory in use", \@data, \@rawdata); @@ -172,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$/) { @@ -186,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"; @@ -206,7 +215,7 @@ foreach my $machine (@rrddirlist) { } if($rrd =~ /^(paging)\.rrd$/) { my(@data); - push @data, "LINE2:$1:pageins:pageins#00FF00:OK:pages paged in "; + 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); } @@ -238,24 +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, "LINE2:$1-$2:rbytes:rbytes#00FF00:OK:read bytes "; + 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); my(@rawdata); - push @data, "LINE2:$1-$2:rx:rx#00FF00:OK:received bytes "; + 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_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); @@ -295,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