--- projects/cms/source/reports/rrdgraphing/graph.pl 2002/10/13 02:04:03 1.8 +++ projects/cms/source/reports/rrdgraphing/graph.pl 2002/10/21 13:02:58 1.11 @@ -2,6 +2,7 @@ # # 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 @@ -26,7 +27,7 @@ # Generates graphs from rrd databases for i-scream data. # # $Author: tdb $ -# $Id: graph.pl,v 1.8 2002/10/13 02:04:03 tdb Exp $ +# $Id: graph.pl,v 1.11 2002/10/21 13:02:58 tdb Exp $ #------------------------------------------------------------ ## TODO @@ -34,7 +35,7 @@ # -- allow configurable periods of graphs # -- comments, types, etc -my($version) = '$Id: graph.pl,v 1.8 2002/10/13 02:04:03 tdb Exp $'; +my($version) = '$Id: graph.pl,v 1.11 2002/10/21 13:02:58 tdb Exp $'; $| = 1; @@ -140,30 +141,33 @@ foreach my $machine (@rrddirlist) { 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); + &makegraph($machine, $1, "CPU Usage for $machine", "% cpu time", \@data, \@rawdata); } if($rrd =~ /^(mem)\.rrd$/) { my(@data); my(@rawdata); - # we don't actually want to display free memory, - # although we need it to do inuse... + # we don't actually want to display free or total memory, + # although we need it to work out peruse... push @data, "NONE:$1:free:free#CCCCFF:NONE:free memory"; - push @data, "LINE2:$1:total:total#0000FF:NONE:total memory\\n"; - # calculate inuse - push @rawdata, "CDEF:inuse=total,free,-"; + 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,*"; # and add it to the graph - push @rawdata, "AREA:inuse#CCCCFF:memory in use"; - push @rawdata, "--base=1024"; + push @rawdata, "AREA:peruse#CCCCFF:% memory in use"; + push @rawdata, "--upper-limit=100"; # add some nice values to the legend - &addlegend(\@rawdata, "inuse"); - &makegraph($machine, $1, "Memory Usage for $machine", \@data, \@rawdata); + &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 %sMb\\c"; + &makegraph($machine, $1, "Memory Usage for $machine", "% memory in use", \@data, \@rawdata); } if($rrd =~ /^(load)\.rrd$/) { my(@data); push @data, "LINE2:$1:load1:load1#CCCCFF:OK: 1 min load average"; push @data, "LINE2:$1:load5:load5#7777FF:OK: 5 min load average"; push @data, "LINE2:$1:load15:load15#0000FF:OK:15 min load average"; - &makegraph($machine, $1, "Loads for $machine", \@data); + &makegraph($machine, $1, "Loads for $machine", "load average", \@data); } if($rrd =~ /^(proc)\.rrd$/) { my(@data); @@ -172,41 +176,66 @@ foreach my $machine (@rrddirlist) { 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); + &makegraph($machine, $1, "Processes on $machine", "no. of processes", \@data); } if($rrd =~ /^(swap)\.rrd$/) { my(@data); my(@rawdata); - # we don't actually want to display free swap, - # although we need it to do inuse... + # we don't actually want to display free or total swap, + # although we need it to work out peruse... push @data, "NONE:$1:free:free#CCCCFF:NONE:free swap"; - push @data, "LINE2:$1:total:total#0000FF:NONE:total swap\\n"; - # calculate inuse - push @rawdata, "CDEF:inuse=total,free,-"; + 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,*"; # and add it to the graph - push @rawdata, "AREA:inuse#CCCCFF:swap in use"; - push @rawdata, "--base=1024"; + push @rawdata, "AREA:peruse#CCCCFF:% swap in use"; + push @rawdata, "--upper-limit=100"; # add some nice values to the legend - &addlegend(\@rawdata, "inuse"); - &makegraph($machine, $1, "Swap Usage for $machine", \@data, \@rawdata); + &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"; + &makegraph($machine, $1, "Swap Usage for $machine", "% swap in use", \@data, \@rawdata); } if($rrd =~ /^(users)\.rrd$/) { my(@data); push @data, "AREA:$1:count:count#CCCCFF:OK:user count"; - &makegraph($machine, $1, "User Count for $machine", \@data); + &makegraph($machine, $1, "User Count for $machine", "no. of users", \@data); } + 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"; + &makegraph($machine, $1, "Paging on $machine", "pages per second", \@data); + } if($rrd =~ /^(disk)-(\S+).rrd$/) { my(@data); my(@rawdata); - push @data, "LINE2:$1-$2:kbytes:kbytes#0000FF:NONE:total size\\n"; - push @data, "AREA:$1-$2:used:used#CCCCFF:OK:used space"; - push @rawdata, "--base=1024"; + # 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: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, "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"; + # 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"; + &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"; + # some name tidting my($type) = $1; my($name) = $2; my($nicename) = $2; $nicename =~ s/$hex_slash/\//g; $nicename =~ s/$hex_underscore/_/g; - &makegraph($machine, "$type-$name", "Disk Usage for $machine on $nicename", \@data, \@rawdata); + &makegraph($machine, "$type-$name", "Disk Usage for $machine on $nicename", "% usage", \@data, \@rawdata); } # probably a queue with a name like this :) if($rrd =~ /^(\d+)_0\.rrd$/) { @@ -218,7 +247,7 @@ foreach my $machine (@rrddirlist) { push @data, "LINE2:$baserrd\_$i:size:size$i" . &get_colour($i) . ":OK:queue$i size "; ++$i; } - push @data, "LINE2:$baserrd\_0:total:total#FF0000:OK:packets/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"); @@ -226,7 +255,7 @@ foreach my $machine (@rrddirlist) { chomp $comment if defined $comment; } $comment = "unknown queue" if not defined $comment; - &makegraph($machine, $baserrd, $comment, \@data, \@rawdata); + &makegraph($machine, $baserrd, $comment, "", \@data, \@rawdata); } } # have a last check, maybe we can remove the directory now? @@ -295,6 +324,8 @@ exit(0); # (eg. cpu) # $title = the title for the graph # (eg. kernow CPU usage) +# $vlabel = the vertical label to apply to the left side of the graph +# (eg. kb/s) # $dataref = a reference to an array containing information for the graph # 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) @@ -304,7 +335,7 @@ exit(0); # sub makegraph() { - my($machine, $type, $title, $dataref, $rawcmdref) = @_; + my($machine, $type, $title, $vlabel, $dataref, $rawcmdref) = @_; # pass in these arrays by reference my(@data) = @$dataref if defined $dataref; my(@rawcmd) = @$rawcmdref if defined $rawcmdref; @@ -333,6 +364,7 @@ sub makegraph() { push @rrdcmd, "--title=$title"; push @rrdcmd, "--imgformat=PNG"; push @rrdcmd, "--lower-limit=0"; + push @rrdcmd, "--vertical-label=$vlabel"; # not entirely convinced this is good... push @rrdcmd, "--alt-autoscale-max"; # add any further raw commands