ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/reports/rrdgraphing/graph.pl
(Generate patch)

Comparing projects/cms/source/reports/rrdgraphing/graph.pl (file contents):
Revision 1.6 by tdb, Tue May 21 16:47:16 2002 UTC vs.
Revision 1.7 by tdb, Thu Jun 20 13:46:54 2002 UTC

# Line 2 | Line 2
2  
3   #
4   # i-scream central monitoring system
5 # http://www.i-scream.org.uk
5   # Copyright (C) 2000-2002 i-scream
6   #
7   # This program is free software; you can redistribute it and/or
# Line 136 | Line 135 | foreach my $machine (@rrddirlist) {
135          if($rrd =~ /^(cpu)\.rrd$/) {
136              my(@data);
137              my(@rawdata);
138 <            push @data, "LINE2:$1:idle:idle#00FF00:idle cpu";
139 <            push @data, "LINE2:$1:user:user#0000FF:user cpu";
140 <            push @data, "LINE2:$1:kernel:kernel#00FFFF:kernel cpu";
141 <            push @data, "LINE2:$1:swap:swap#FF00FF:swap cpu";
142 <            push @data, "LINE2:$1:iowait:iowait#FF0000:iowait cpu";
138 >            push @data, "LINE2:$1:idle:idle#00FF00:OK:idle cpu";
139 >            push @data, "LINE2:$1:user:user#0000FF:OK:user cpu";
140 >            push @data, "LINE2:$1:kernel:kernel#00FFFF:OK:kernel cpu";
141 >            push @data, "LINE2:$1:swap:swap#FF00FF:OK:swap cpu";
142 >            push @data, "LINE2:$1:iowait:iowait#FF0000:OK:iowait cpu";
143              push @rawdata, "--upper-limit=100";
144              &makegraph($machine, $1, "CPU Usage for $machine", \@data, \@rawdata);
145          }
# Line 149 | Line 148 | foreach my $machine (@rrddirlist) {
148              my(@rawdata);
149              # we don't actually want to display free memory,
150              # although we need it to do inuse...
151 <            push @data, "NONE:$1:free:free#CCCCFF:free memory";
152 <            push @data, "LINE2:$1:total:total#0000FF:total memory";
151 >            push @data, "NONE:$1:free:free#CCCCFF:NONE:free memory";
152 >            push @data, "LINE2:$1:total:total#0000FF:NONE:total memory";
153              # calculate inuse
154              push @rawdata, "CDEF:inuse=total,free,-";
155              # and add it to the graph
156 <            push @rawdata, "AREA:inuse#CCCCFF:memory in use";
156 >            push @rawdata, "AREA:inuse#CCCCFF:memory in use\\l";
157              push @rawdata, "--base=1024";
158 +            # add some nice values to the legend
159 +            &addlegend(\@rawdata, "inuse");
160              &makegraph($machine, $1, "Memory Usage for $machine", \@data, \@rawdata);
161          }
162          if($rrd =~ /^(load)\.rrd$/) {
163              my(@data);
164 <            push @data, "LINE2:$1:load1:load1#CCCCFF:1 minute load average";
165 <            push @data, "LINE2:$1:load5:load5#7777FF:5 minute load average";
166 <            push @data, "LINE2:$1:load15:load15#0000FF:15 minute load average";
164 >            push @data, "LINE2:$1:load1:load1#CCCCFF:OK:1 minute load average";
165 >            push @data, "LINE2:$1:load5:load5#7777FF:OK:5 minute load average";
166 >            push @data, "LINE2:$1:load15:load15#0000FF:OK:15 minute load average";
167              &makegraph($machine, $1, "Loads for $machine", \@data);
168          }
169          if($rrd =~ /^(proc)\.rrd$/) {
170              my(@data);
171 <            push @data, "LINE2:$1:cpu:cpu#00FF00:cpu processes";
172 <            push @data, "LINE2:$1:sleeping:sleeping#0000FF:sleeping processes";
173 <            push @data, "LINE2:$1:stopped:stopped#00FFFF:stopped processes";
174 <            push @data, "LINE2:$1:total:total#FF00FF:total processes";
175 <            push @data, "LINE2:$1:zombie:zombie#FF0000:zombie processes";
171 >            push @data, "LINE2:$1:cpu:cpu#00FF00:OK:cpu processes";
172 >            push @data, "LINE2:$1:sleeping:sleeping#0000FF:OK:sleeping processes";
173 >            push @data, "LINE2:$1:stopped:stopped#00FFFF:OK:stopped processes";
174 >            push @data, "LINE2:$1:total:total#FF00FF:OK:total processes";
175 >            push @data, "LINE2:$1:zombie:zombie#FF0000:OK:zombie processes";
176              &makegraph($machine, $1, "Processes on $machine", \@data);
177          }
178          if($rrd =~ /^(swap)\.rrd$/) {
# Line 179 | Line 180 | foreach my $machine (@rrddirlist) {
180              my(@rawdata);
181              # we don't actually want to display free swap,
182              # although we need it to do inuse...
183 <            push @data, "NONE:$1:free:free#CCCCFF:free swap";
184 <            push @data, "LINE2:$1:total:total#0000FF:total swap";
183 >            push @data, "NONE:$1:free:free#CCCCFF:NONE:free swap";
184 >            push @data, "LINE2:$1:total:total#0000FF:NONE:total swap";
185              # calculate inuse
186              push @rawdata, "CDEF:inuse=total,free,-";
187              # and add it to the graph
188 <            push @rawdata, "AREA:inuse#CCCCFF:swap in use";
188 >            push @rawdata, "AREA:inuse#CCCCFF:swap in use\\l";
189              push @rawdata, "--base=1024";
190 +            # add some nice values to the legend
191 +            &addlegend(\@rawdata, "inuse");
192              &makegraph($machine, $1, "Swap Usage for $machine", \@data, \@rawdata);
193          }
194          if($rrd =~ /^(users)\.rrd$/) {
195              my(@data);
196 <            push @data, "AREA:$1:count:count#CCCCFF:user count";
196 >            push @data, "AREA:$1:count:count#CCCCFF:OK:user count";
197              &makegraph($machine, $1, "User Count for $machine", \@data);
198          }
199          if($rrd =~ /^(disk)-(\S+).rrd$/) {
200              my(@data);
201              my(@rawdata);
202 <            push @data, "LINE2:$1-$2:kbytes:kbytes#0000FF:total size";
203 <            push @data, "AREA:$1-$2:used:used#CCCCFF:used";
202 >            push @data, "LINE2:$1-$2:kbytes:kbytes#0000FF:NONE:total size";
203 >            push @data, "AREA:$1-$2:used:used#CCCCFF:OK:used";
204              push @rawdata, "--base=1024";
205              my($type) = $1;
206              my($name) = $2;
# Line 213 | Line 216 | foreach my $machine (@rrddirlist) {
216              my($baserrd) = $1;
217              my($i) = 0;
218              while( -f "$rrddir/$machine/$baserrd\_$i.rrd" ) {
219 <                push @data, "LINE2:$baserrd\_$i:size:size$i" . &get_colour($i) . ":queue$i size ";
219 >                push @data, "LINE2:$baserrd\_$i:size:size$i" . &get_colour($i) . ":OK:queue$i size ";
220                  ++$i;
221              }
222 <            push @data, "LINE2:$baserrd\_0:total:total#FF0000:packets/sec - currently";
220 <            push @rawdata, "GPRINT:total:LAST:%lf %spackets/sec";
222 >            push @data, "LINE2:$baserrd\_0:total:total#FF0000:OK:packets/sec";
223              my($comment);
224              if(-f "$rrddir/$machine/$baserrd.def") {
225                  open(DEF, "$rrddir/$machine/$baserrd.def");
# Line 295 | Line 297 | exit(0);
297   # $title     = the title for the graph
298   #              (eg. kernow CPU usage)
299   # $dataref   = a reference to an array containing information for the graph
300 < #              elements of format: "gtype:rrdname:dsname:name#colour:comment with spaces"
300 > #              elements of format: "gtype:rrdname:dsname:name#colour:legend:comment with spaces"
301   #              (if gtype is "NONE" only a DEF of 'name' will be defined, no line will be plotted)
302 + #              (if legend is "NONE" the latest/average/max/min legend won't be printed)
303   # $rawcmdref = a reference to an array containing raw rrd commands
304   #              elements a single command each, no spaces
305   #
# Line 314 | Line 317 | sub makegraph() {
317      }
318      my(@rrdcmd);
319      foreach my $dataitem (@data) {
320 <        # dataitem should be: "gtype:rrdname:dsname:name#colour:comment with spaces"
320 >        # dataitem should be: "gtype:rrdname:dsname:name#colour:legend:comment with spaces"
321          # (if gtype is "NONE" only a DEF of 'name' will be defined, no line will be plotted)
322 <        if($dataitem =~ /^(\S+):(\S+):(\S+):(\S+)#(.{6}):(.*)$/) {
322 >        # (if legend is "NONE" the latest/average/max/min legend won't be printed)
323 >        if($dataitem =~ /^(\S+):(\S+):(\S+):(\S+)#(.{6}):(\S+):(.*)$/) {
324              push @rrdcmd, "DEF:$4=$rrddir/$machine/$2.rrd:$3:AVERAGE";
325              if($1 ne "NONE") {
326 <                push @rrdcmd, "$1:$4#$5:$6";
326 >                push @rrdcmd, "$1:$4#$5:$7\\s";
327 >                if($6 ne "NONE") {
328 >                    # add some nice values to the legend
329 >                    &addlegend(\@rrdcmd, $4);
330 >                }
331              }
332          }
333      }
# Line 351 | Line 359 | sub makegraph() {
359      &log("created $imgdir/$machine/$type-1y.png\n") unless $err_1y;
360      &error("Error generating 1y graph for $machine/$type: $err_1y\n") if $err_1y;
361      return;
362 + }
363 +
364 + # subroutine to add a legend
365 + # accepts reference to an array and a name
366 + sub addlegend() {
367 +    my($dataref, $name) = @_;
368 +    push @$dataref, "GPRINT:$name:LAST:latest=\%lf\\r";
369 +    push @$dataref, "GPRINT:$name:AVERAGE:average=\%lf";
370 +    push @$dataref, "GPRINT:$name:MAX:max=\%lf";
371 +    push @$dataref, "GPRINT:$name:MIN:min=\%lf\\r";
372   }
373  
374   # hacky subroutine to return a colour

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines