--- projects/cms/source/reports/rrdgraphing/graph.pl 2002/05/21 16:47:16 1.6 +++ projects/cms/source/reports/rrdgraphing/graph.pl 2002/06/20 13:46:54 1.7 @@ -2,7 +2,6 @@ # # i-scream central monitoring system -# http://www.i-scream.org.uk # Copyright (C) 2000-2002 i-scream # # This program is free software; you can redistribute it and/or @@ -27,7 +26,7 @@ # Generates graphs from rrd databases for i-scream data. # # $Author: tdb $ -# $Id: graph.pl,v 1.6 2002/05/21 16:47:16 tdb Exp $ +# $Id: graph.pl,v 1.7 2002/06/20 13:46:54 tdb Exp $ #------------------------------------------------------------ ## TODO @@ -35,7 +34,7 @@ # -- allow configurable periods of graphs # -- comments, types, etc -my($version) = '$Id: graph.pl,v 1.6 2002/05/21 16:47:16 tdb Exp $'; +my($version) = '$Id: graph.pl,v 1.7 2002/06/20 13:46:54 tdb Exp $'; $| = 1; @@ -136,11 +135,11 @@ foreach my $machine (@rrddirlist) { if($rrd =~ /^(cpu)\.rrd$/) { my(@data); my(@rawdata); - push @data, "LINE2:$1:idle:idle#00FF00:idle cpu"; - push @data, "LINE2:$1:user:user#0000FF:user cpu"; - push @data, "LINE2:$1:kernel:kernel#00FFFF:kernel cpu"; - push @data, "LINE2:$1:swap:swap#FF00FF:swap cpu"; - push @data, "LINE2:$1:iowait:iowait#FF0000:iowait 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", \@data, \@rawdata); } @@ -149,29 +148,31 @@ foreach my $machine (@rrddirlist) { my(@rawdata); # we don't actually want to display free memory, # although we need it to do inuse... - push @data, "NONE:$1:free:free#CCCCFF:free memory"; - push @data, "LINE2:$1:total:total#0000FF:total memory"; + push @data, "NONE:$1:free:free#CCCCFF:NONE:free memory"; + push @data, "LINE2:$1:total:total#0000FF:NONE:total memory"; # calculate inuse push @rawdata, "CDEF:inuse=total,free,-"; # and add it to the graph - push @rawdata, "AREA:inuse#CCCCFF:memory in use"; + push @rawdata, "AREA:inuse#CCCCFF:memory in use\\l"; push @rawdata, "--base=1024"; + # add some nice values to the legend + &addlegend(\@rawdata, "inuse"); &makegraph($machine, $1, "Memory Usage for $machine", \@data, \@rawdata); } if($rrd =~ /^(load)\.rrd$/) { my(@data); - push @data, "LINE2:$1:load1:load1#CCCCFF:1 minute load average"; - push @data, "LINE2:$1:load5:load5#7777FF:5 minute load average"; - push @data, "LINE2:$1:load15:load15#0000FF:15 minute load average"; + push @data, "LINE2:$1:load1:load1#CCCCFF:OK:1 minute load average"; + push @data, "LINE2:$1:load5:load5#7777FF:OK:5 minute load average"; + push @data, "LINE2:$1:load15:load15#0000FF:OK:15 minute load average"; &makegraph($machine, $1, "Loads for $machine", \@data); } if($rrd =~ /^(proc)\.rrd$/) { my(@data); - push @data, "LINE2:$1:cpu:cpu#00FF00:cpu processes"; - push @data, "LINE2:$1:sleeping:sleeping#0000FF:sleeping processes"; - push @data, "LINE2:$1:stopped:stopped#00FFFF:stopped processes"; - push @data, "LINE2:$1:total:total#FF00FF:total processes"; - push @data, "LINE2:$1:zombie:zombie#FF0000:zombie processes"; + 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, "LINE2:$1:total:total#FF00FF:OK:total processes"; + push @data, "LINE2:$1:zombie:zombie#FF0000:OK:zombie processes"; &makegraph($machine, $1, "Processes on $machine", \@data); } if($rrd =~ /^(swap)\.rrd$/) { @@ -179,25 +180,27 @@ foreach my $machine (@rrddirlist) { my(@rawdata); # we don't actually want to display free swap, # although we need it to do inuse... - push @data, "NONE:$1:free:free#CCCCFF:free swap"; - push @data, "LINE2:$1:total:total#0000FF:total swap"; + push @data, "NONE:$1:free:free#CCCCFF:NONE:free swap"; + push @data, "LINE2:$1:total:total#0000FF:NONE:total swap"; # calculate inuse push @rawdata, "CDEF:inuse=total,free,-"; # and add it to the graph - push @rawdata, "AREA:inuse#CCCCFF:swap in use"; + push @rawdata, "AREA:inuse#CCCCFF:swap in use\\l"; push @rawdata, "--base=1024"; + # add some nice values to the legend + &addlegend(\@rawdata, "inuse"); &makegraph($machine, $1, "Swap Usage for $machine", \@data, \@rawdata); } if($rrd =~ /^(users)\.rrd$/) { my(@data); - push @data, "AREA:$1:count:count#CCCCFF:user count"; + push @data, "AREA:$1:count:count#CCCCFF:OK:user count"; &makegraph($machine, $1, "User Count for $machine", \@data); } if($rrd =~ /^(disk)-(\S+).rrd$/) { my(@data); my(@rawdata); - push @data, "LINE2:$1-$2:kbytes:kbytes#0000FF:total size"; - push @data, "AREA:$1-$2:used:used#CCCCFF:used"; + push @data, "LINE2:$1-$2:kbytes:kbytes#0000FF:NONE:total size"; + push @data, "AREA:$1-$2:used:used#CCCCFF:OK:used"; push @rawdata, "--base=1024"; my($type) = $1; my($name) = $2; @@ -213,11 +216,10 @@ foreach my $machine (@rrddirlist) { my($baserrd) = $1; my($i) = 0; while( -f "$rrddir/$machine/$baserrd\_$i.rrd" ) { - push @data, "LINE2:$baserrd\_$i:size:size$i" . &get_colour($i) . ":queue$i size "; + push @data, "LINE2:$baserrd\_$i:size:size$i" . &get_colour($i) . ":OK:queue$i size "; ++$i; } - push @data, "LINE2:$baserrd\_0:total:total#FF0000:packets/sec - currently"; - push @rawdata, "GPRINT:total:LAST:%lf %spackets/sec"; + push @data, "LINE2:$baserrd\_0:total:total#FF0000:OK:packets/sec"; my($comment); if(-f "$rrddir/$machine/$baserrd.def") { open(DEF, "$rrddir/$machine/$baserrd.def"); @@ -295,8 +297,9 @@ exit(0); # $title = the title for the graph # (eg. kernow CPU usage) # $dataref = a reference to an array containing information for the graph -# elements of format: "gtype:rrdname:dsname:name#colour:comment with spaces" +# elements of format: "gtype:rrdname:dsname:name#colour:legend:comment with spaces" # (if gtype is "NONE" only a DEF of 'name' will be defined, no line will be plotted) +# (if legend is "NONE" the latest/average/max/min legend won't be printed) # $rawcmdref = a reference to an array containing raw rrd commands # elements a single command each, no spaces # @@ -314,12 +317,17 @@ sub makegraph() { } my(@rrdcmd); foreach my $dataitem (@data) { - # dataitem should be: "gtype:rrdname:dsname:name#colour:comment with spaces" + # dataitem should be: "gtype:rrdname:dsname:name#colour:legend:comment with spaces" # (if gtype is "NONE" only a DEF of 'name' will be defined, no line will be plotted) - if($dataitem =~ /^(\S+):(\S+):(\S+):(\S+)#(.{6}):(.*)$/) { + # (if legend is "NONE" the latest/average/max/min legend won't be printed) + if($dataitem =~ /^(\S+):(\S+):(\S+):(\S+)#(.{6}):(\S+):(.*)$/) { push @rrdcmd, "DEF:$4=$rrddir/$machine/$2.rrd:$3:AVERAGE"; if($1 ne "NONE") { - push @rrdcmd, "$1:$4#$5:$6"; + push @rrdcmd, "$1:$4#$5:$7\\s"; + if($6 ne "NONE") { + # add some nice values to the legend + &addlegend(\@rrdcmd, $4); + } } } } @@ -351,6 +359,16 @@ sub makegraph() { &log("created $imgdir/$machine/$type-1y.png\n") unless $err_1y; &error("Error generating 1y graph for $machine/$type: $err_1y\n") if $err_1y; return; +} + +# subroutine to add a legend +# accepts reference to an array and a name +sub addlegend() { + my($dataref, $name) = @_; + push @$dataref, "GPRINT:$name:LAST:latest=\%lf\\r"; + push @$dataref, "GPRINT:$name:AVERAGE:average=\%lf"; + push @$dataref, "GPRINT:$name:MAX:max=\%lf"; + push @$dataref, "GPRINT:$name:MIN:min=\%lf\\r"; } # hacky subroutine to return a colour