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.5 by tdb, Tue May 21 15:01:43 2002 UTC vs.
Revision 1.12 by tdb, Mon Mar 10 11:34:43 2003 UTC

# Line 2 | Line 2
2  
3   #
4   # i-scream central monitoring system
5 + # http://www.i-scream.org.uk
6   # Copyright (C) 2000-2002 i-scream
7   #
8   # This program is free software; you can redistribute it and/or
# Line 97 | Line 98 | if($opts{q}) {
98      $verbose = 0;
99   }
100  
100
101   # Read the contents of the base directory
102   # and pull out the list of subdirectories (except . and .. :)
103   opendir(DIR, $rrddir);
# Line 135 | 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);
144 >            &makegraph($machine, $1, "CPU Usage for $machine", "% cpu time", \@data, \@rawdata);
145          }
146          if($rrd =~ /^(mem)\.rrd$/) {
147              my(@data);
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";
153 <            # calculate inuse
154 <            push @rawdata, "CDEF:inuse=total,free,-";
149 >            # we don't actually want to display free or total memory,
150 >            # although we need it to work out peruse...
151 >            push @data, "NONE:$1:free:free#CCCCFF:NONE:free memory";
152 >            push @data, "NONE:$1:total:total#0000FF:NONE:total memory\\n";
153 >            # calculate peruse - note that we only use 'free' if it's less than total
154 >            # (this is to avoid negative percentages :)
155 >            push @rawdata, "CDEF:peruse=total,free,total,LT,free,0,IF,-,total,/,100,*";
156              # and add it to the graph
157 <            push @rawdata, "AREA:inuse#CCCCFF:memory in use";
157 >            push @rawdata, "AREA:peruse#CCCCFF:% memory in use";
158 >            push @rawdata, "--upper-limit=100";
159              push @rawdata, "--base=1024";
160 <            &makegraph($machine, $1, "Memory Usage for $machine", \@data, \@rawdata);
160 >            # add some nice values to the legend
161 >            &addlegend(\@rawdata, "peruse");
162 >            # put the total memory on the graph so we can map percentages to real values
163 >            push @rawdata, "GPRINT:total:LAST:Current total memory\\: \%.2lf %sb\\c";
164 >            &makegraph($machine, $1, "Memory Usage for $machine", "% memory in use", \@data, \@rawdata);
165          }
166          if($rrd =~ /^(load)\.rrd$/) {
167              my(@data);
168 <            push @data, "LINE2:$1:load1:load1#CCCCFF:1 minute load average";
169 <            push @data, "LINE2:$1:load5:load5#7777FF:5 minute load average";
170 <            push @data, "LINE2:$1:load15:load15#0000FF:15 minute load average";
171 <            &makegraph($machine, $1, "Loads for $machine", \@data);
168 >            push @data, "LINE2:$1:load1:load1#CCCCFF:OK: 1 min load average";
169 >            push @data, "LINE2:$1:load5:load5#7777FF:OK: 5 min load average";
170 >            push @data, "LINE2:$1:load15:load15#0000FF:OK:15 min load average";
171 >            &makegraph($machine, $1, "Loads for $machine", "load average", \@data);
172          }
173          if($rrd =~ /^(proc)\.rrd$/) {
174              my(@data);
175 <            push @data, "LINE2:$1:cpu:cpu#00FF00:cpu processes";
176 <            push @data, "LINE2:$1:sleeping:sleeping#0000FF:sleeping processes";
177 <            push @data, "LINE2:$1:stopped:stopped#00FFFF:stopped processes";
178 <            push @data, "LINE2:$1:total:total#FF00FF:total processes";
179 <            push @data, "LINE2:$1:zombie:zombie#FF0000:zombie processes";
180 <            &makegraph($machine, $1, "Processes on $machine", \@data);
175 >            push @data, "LINE2:$1:cpu:cpu#00FF00:OK:cpu processes     ";
176 >            push @data, "LINE2:$1:sleeping:sleeping#0000FF:OK:sleeping processes";
177 >            push @data, "LINE2:$1:stopped:stopped#00FFFF:OK:stopped processes ";
178 >            push @data, "LINE2:$1:total:total#FF00FF:OK:total processes   ";
179 >            push @data, "LINE2:$1:zombie:zombie#FF0000:OK:zombie processes  ";
180 >            &makegraph($machine, $1, "Processes on $machine", "no. of processes", \@data);
181          }
182          if($rrd =~ /^(swap)\.rrd$/) {
183              my(@data);
184              my(@rawdata);
185 <            # we don't actually want to display free swap,
186 <            # although we need it to do inuse...
187 <            push @data, "NONE:$1:free:free#CCCCFF:free swap";
188 <            push @data, "LINE2:$1:total:total#0000FF:total swap";
189 <            # calculate inuse
190 <            push @rawdata, "CDEF:inuse=total,free,-";
185 >            # we don't actually want to display free or total swap,
186 >            # although we need it to work out peruse...
187 >            push @data, "NONE:$1:free:free#CCCCFF:NONE:free swap";
188 >            push @data, "NONE:$1:total:total#0000FF:NONE:total swap\\n";
189 >            # calculate peruse - note that we only use 'free' if it's less than total
190 >            # (this is to avoid negative percentages :)
191 >            push @rawdata, "CDEF:peruse=total,free,total,LT,free,0,IF,-,total,/,100,*";
192              # and add it to the graph
193 <            push @rawdata, "AREA:inuse#CCCCFF:swap in use";
193 >            push @rawdata, "AREA:peruse#CCCCFF:% swap in use";
194 >            push @rawdata, "--upper-limit=100";
195              push @rawdata, "--base=1024";
196 <            &makegraph($machine, $1, "Swap Usage for $machine", \@data, \@rawdata);
196 >            # add some nice values to the legend
197 >            &addlegend(\@rawdata, "peruse");
198 >            # put the total swap on the graph so we can map percentages to real values
199 >            push @rawdata, "GPRINT:total:LAST:Current total swap\\: \%.2lf %sb\\c";
200 >            &makegraph($machine, $1, "Swap Usage for $machine", "% swap in use", \@data, \@rawdata);
201          }
202          if($rrd =~ /^(users)\.rrd$/) {
203              my(@data);
204 <            push @data, "AREA:$1:count:count#CCCCFF:user count";
205 <            &makegraph($machine, $1, "User Count for $machine", \@data);
204 >            push @data, "AREA:$1:count:count#CCCCFF:OK:user count";
205 >            &makegraph($machine, $1, "User Count for $machine", "no. of users", \@data);
206          }
207 <        if($rrd =~ /^(disk)-(\S+).rrd$/) {
207 >        if($rrd =~ /^(paging)\.rrd$/) {
208              my(@data);
209 +            push @data, "LINE2:$1:pageins:pageins#00FF00:OK:pages paged in ";
210 +            push @data, "LINE2:$1:pageouts:pageouts#0000FF:OK:pages paged out";
211 +            &makegraph($machine, $1, "Paging on $machine", "pages per second", \@data);
212 +        }
213 +        if($rrd =~ /^(disk)-(\S+)\.rrd$/) {
214 +            my(@data);
215              my(@rawdata);
216 <            push @data, "LINE2:$1-$2:kbytes:kbytes#0000FF:total size";
217 <            push @data, "AREA:$1-$2:used:used#CCCCFF:used";
216 >            # we need this lot for our calculations, but we'll never show them
217 >            push @data, "NONE:$1-$2:total:total#0000FF:NONE:total size\\n";
218 >            push @data, "NONE:$1-$2:used:used#CCCCFF:NONE:used space";
219 >            push @data, "NONE:$1-$2:totalinodes:totalinodes#000000:NONE:total inodes";
220 >            push @data, "NONE:$1-$2:freeinodes:freeinodes#000000:NONE:free inodes";
221 >            # calculate peruse, add it to the graph, and add a legend
222 >            push @rawdata, "CDEF:peruse=used,total,/,100,*";
223 >            push @rawdata, "AREA:peruse#CCCCFF:% disk used  ";
224 >            &addlegend(\@rawdata, "peruse");
225 >            # put the total space on the graph so we can map percentages to real values
226 >            push @rawdata, "GPRINT:total:LAST:Current total space\\: \%.2lf %sb\\c";
227 >            # calculate perinodeuse, add it to the graph, and add a legend
228 >            push @rawdata, "CDEF:perinodeuse=totalinodes,freeinodes,totalinodes,LT,freeinodes,0,IF,-,totalinodes,/,100,*";
229 >            push @rawdata, "LINE2:perinodeuse#FF4444:% inodes used";
230 >            push @rawdata, "--upper-limit=100";
231              push @rawdata, "--base=1024";
232 +            &addlegend(\@rawdata, "perinodeuse");
233 +            # put the total inodes on the graph so we can map percentages to real values
234 +            push @rawdata, "GPRINT:totalinodes:LAST:Current total inodes\\: \%.2lf %s\\c";
235 +            # some name tidting
236              my($type) = $1;
237              my($name) = $2;
238              my($nicename) = $2;
239              $nicename =~ s/$hex_slash/\//g;
240              $nicename =~ s/$hex_underscore/_/g;
241 <            &makegraph($machine, "$type-$name", "Disk Usage for $machine on $nicename", \@data, \@rawdata);
241 >            &makegraph($machine, "$type-$name", "Disk Usage for $machine on $nicename", "% usage", \@data, \@rawdata);
242          }
243 +        if($rrd =~ /^(diskio)-(\S+)\.rrd$/) {
244 +            my(@data);
245 +            my(@rawdata);
246 +            push @data, "LINE2:$1-$2:rbytes:rbytes#00FF00:OK:read bytes ";
247 +            push @data, "LINE2:$1-$2:wbytes:wbytes#0000FF:OK:write bytes";
248 +            push @rawdata, "--base=1024";
249 +            &makegraph($machine, "$1-$2", "Disk IO for $machine on $2", "bytes per second", \@data, \@rawdata);
250 +        }
251 +        if($rrd =~ /^(net)-(\S+)\.rrd$/) {
252 +            my(@data);
253 +            my(@rawdata);
254 +            push @data, "LINE2:$1-$2:rx:rx#00FF00:OK:received bytes  ";
255 +            push @data, "LINE2:$1-$2:tx:tx#0000FF:OK:transfered bytes";
256 +            push @rawdata, "--base=1024";
257 +            &makegraph($machine, "$1-$2", "Network IO for $machine on $2", "bytes per second", \@data, \@rawdata);
258 +        }
259          # probably a queue with a name like this :)
260          if($rrd =~ /^(\d+)_0\.rrd$/) {
261              my(@data);
# Line 212 | Line 263 | foreach my $machine (@rrddirlist) {
263              my($baserrd) = $1;
264              my($i) = 0;
265              while( -f "$rrddir/$machine/$baserrd\_$i.rrd" ) {
266 <                push @data, "LINE2:$baserrd\_$i:size:size$i" . &get_colour($i) . ":queue$i size ";
266 >                push @data, "LINE2:$baserrd\_$i:size:size$i" . &get_colour($i) . ":OK:queue$i size ";
267                  ++$i;
268              }
269 <            push @data, "LINE2:$baserrd\_0:total:total#FF0000:packets/sec - currently";
219 <            push @rawdata, "GPRINT:total:LAST:%lf %spackets/sec";
269 >            push @data, "LINE2:$baserrd\_0:total:total#FF0000:OK:packets/sec ";
270              my($comment);
271              if(-f "$rrddir/$machine/$baserrd.def") {
272                  open(DEF, "$rrddir/$machine/$baserrd.def");
# Line 224 | Line 274 | foreach my $machine (@rrddirlist) {
274                  chomp $comment if defined $comment;
275              }
276              $comment = "unknown queue" if not defined $comment;
277 <            &makegraph($machine, $baserrd, $comment, \@data, \@rawdata);
277 >            &makegraph($machine, $baserrd, $comment, "", \@data, \@rawdata);
278          }
279      }
280      # have a last check, maybe we can remove the directory now?
# Line 293 | Line 343 | exit(0);
343   #              (eg. cpu)
344   # $title     = the title for the graph
345   #              (eg. kernow CPU usage)
346 + # $vlabel    = the vertical label to apply to the left side of the graph
347 + #              (eg. kb/s)
348   # $dataref   = a reference to an array containing information for the graph
349 < #              elements of format: "gtype:rrdname:dsname:name#colour:comment with spaces"
349 > #              elements of format: "gtype:rrdname:dsname:name#colour:legend:comment with spaces"
350   #              (if gtype is "NONE" only a DEF of 'name' will be defined, no line will be plotted)
351 + #              (if legend is "NONE" the latest/average/max/min legend won't be printed)
352   # $rawcmdref = a reference to an array containing raw rrd commands
353   #              elements a single command each, no spaces
354   #
355  
356   sub makegraph() {
357 <    my($machine, $type, $title, $dataref, $rawcmdref) = @_;
357 >    my($machine, $type, $title, $vlabel, $dataref, $rawcmdref) = @_;
358      # pass in these arrays by reference
359      my(@data) = @$dataref if defined $dataref;
360      my(@rawcmd) = @$rawcmdref if defined $rawcmdref;
# Line 313 | Line 366 | sub makegraph() {
366      }
367      my(@rrdcmd);
368      foreach my $dataitem (@data) {
369 <        # dataitem should be: "gtype:rrdname:dsname:name#colour:comment with spaces"
369 >        # dataitem should be: "gtype:rrdname:dsname:name#colour:legend:comment with spaces"
370          # (if gtype is "NONE" only a DEF of 'name' will be defined, no line will be plotted)
371 <        if($dataitem =~ /^(\S+):(\S+):(\S+):(\S+)#(.{6}):(.*)$/) {
371 >        # (if legend is "NONE" the latest/average/max/min legend won't be printed)
372 >        if($dataitem =~ /^(\S+):(\S+):(\S+):(\S+)#(.{6}):(\S+):(.*)$/) {
373              push @rrdcmd, "DEF:$4=$rrddir/$machine/$2.rrd:$3:AVERAGE";
374              if($1 ne "NONE") {
375 <                push @rrdcmd, "$1:$4#$5:$6";
375 >                push @rrdcmd, "$1:$4#$5:$7";
376 >                if($6 ne "NONE") {
377 >                    # add some nice values to the legend
378 >                    &addlegend(\@rrdcmd, $4);
379 >                }
380              }
381          }
382      }
383      push @rrdcmd, "--title=$title";
384      push @rrdcmd, "--imgformat=PNG";
385      push @rrdcmd, "--lower-limit=0";
386 +    push @rrdcmd, "--vertical-label=$vlabel";
387      # not entirely convinced this is good...
388      push @rrdcmd, "--alt-autoscale-max";
389      # add any further raw commands
# Line 350 | Line 409 | sub makegraph() {
409      &log("created $imgdir/$machine/$type-1y.png\n") unless $err_1y;
410      &error("Error generating 1y graph for $machine/$type: $err_1y\n") if $err_1y;
411      return;
412 + }
413 +
414 + # subroutine to add a legend
415 + # accepts reference to an array and a name
416 + sub addlegend() {
417 +    my($dataref, $name) = @_;
418 +    push @$dataref, "GPRINT:$name:LAST:Current\\: \%8.2lf %s";
419 +    push @$dataref, "GPRINT:$name:AVERAGE:Average\\: \%8.2lf %s";
420 +    push @$dataref, "GPRINT:$name:MAX:Max\\: \%8.2lf %s\\n";
421   }
422  
423   # hacky subroutine to return a colour

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines