2 |
|
|
3 |
|
# |
4 |
|
# i-scream central monitoring system |
5 |
+ |
# http://www.i-scream.org |
6 |
|
# Copyright (C) 2000-2002 i-scream |
7 |
|
# |
8 |
|
# This program is free software; you can redistribute it and/or |
22 |
|
|
23 |
|
# ----------------------------------------------------------- |
24 |
|
# i-scream graph generation script |
25 |
< |
# http://www.i-scream.org.uk |
25 |
> |
# http://www.i-scream.org |
26 |
|
# |
27 |
|
# Generates graphs from rrd databases for i-scream data. |
28 |
|
# |
35 |
|
# -- allow configurable periods of graphs |
36 |
|
# -- comments, types, etc |
37 |
|
|
38 |
+ |
BEGIN { |
39 |
+ |
push (@INC, "/usr/local/packages/rrdtool/lib/perl5/site_perl/5.8.2/sun4-solaris"); |
40 |
+ |
} |
41 |
+ |
|
42 |
|
my($version) = '$Id$'; |
43 |
|
|
44 |
|
$| = 1; |
105 |
|
# Read the contents of the base directory |
106 |
|
# and pull out the list of subdirectories (except . and .. :) |
107 |
|
opendir(DIR, $rrddir); |
108 |
< |
my(@rrddirlist) = grep { -d "$rrddir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); |
108 |
> |
my(@rrddirlist) = sort grep { -d "$rrddir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); |
109 |
|
closedir DIR; |
110 |
|
|
111 |
< |
# look through each directoty, as they might |
111 |
> |
# look through each directory, as they might |
112 |
|
# contain rrds for a particular machine |
113 |
|
foreach my $machine (@rrddirlist) { |
114 |
|
# Read the contents of the directory |
139 |
|
if($rrd =~ /^(cpu)\.rrd$/) { |
140 |
|
my(@data); |
141 |
|
my(@rawdata); |
142 |
< |
push @data, "LINE2:$1:idle:idle#00FF00:OK:idle cpu "; |
143 |
< |
push @data, "LINE2:$1:user:user#0000FF:OK:user cpu "; |
144 |
< |
push @data, "LINE2:$1:kernel:kernel#00FFFF:OK:kernel cpu"; |
145 |
< |
push @data, "LINE2:$1:swap:swap#FF00FF:OK:swap cpu "; |
146 |
< |
push @data, "LINE2:$1:iowait:iowait#FF0000:OK:iowait cpu"; |
142 |
> |
push @data, "AREA:$1:swap:swap#FF00FF:OK:swap cpu "; |
143 |
> |
push @data, "STACK:$1:iowait:iowait#FF0000:OK:iowait cpu"; |
144 |
> |
push @data, "STACK:$1:kernel:kernel#00FFFF:OK:kernel cpu"; |
145 |
> |
push @data, "STACK:$1:user:user#0000FF:OK:user cpu "; |
146 |
> |
#push @data, "STACK:$1:idle:idle#00FF00:OK:idle cpu "; |
147 |
|
push @rawdata, "--upper-limit=100"; |
148 |
< |
&makegraph($machine, $1, "CPU Usage for $machine", \@data, \@rawdata); |
148 |
> |
&makegraph($machine, $1, "CPU Usage for $machine", "% cpu time", \@data, \@rawdata); |
149 |
|
} |
150 |
|
if($rrd =~ /^(mem)\.rrd$/) { |
151 |
|
my(@data); |
152 |
|
my(@rawdata); |
153 |
< |
# we don't actually want to display free memory, |
154 |
< |
# although we need it to do inuse... |
153 |
> |
# we don't actually want to display free or total memory, |
154 |
> |
# although we need it to work out peruse... |
155 |
|
push @data, "NONE:$1:free:free#CCCCFF:NONE:free memory"; |
156 |
< |
push @data, "LINE2:$1:total:total#0000FF:NONE:total memory\\n"; |
157 |
< |
# calculate inuse |
158 |
< |
push @rawdata, "CDEF:inuse=total,free,-"; |
156 |
> |
push @data, "NONE:$1:total:total#0000FF:NONE:total memory\\n"; |
157 |
> |
push @data, "NONE:$1:cache:cache#0000FF:NONE:cache memory\\n"; |
158 |
> |
# calculate peruse - note that we only use 'free' if it's less than total |
159 |
> |
# (this is to avoid negative percentages :) |
160 |
> |
push @rawdata, "CDEF:peruse=total,free,total,LT,free,0,IF,-,total,/,100,*"; |
161 |
> |
push @rawdata, "CDEF:percacuse=cache,total,LT,cache,0,IF,total,/,100,*"; |
162 |
|
# and add it to the graph |
163 |
< |
push @rawdata, "AREA:inuse#CCCCFF:memory in use"; |
163 |
> |
push @rawdata, "AREA:peruse#CCCCFF:% memory in use"; |
164 |
> |
&addlegend(\@rawdata, "peruse"); |
165 |
> |
push @rawdata, "LINE2:percacuse#0000FF:% memory cache "; |
166 |
> |
&addlegend(\@rawdata, "percacuse"); |
167 |
> |
push @rawdata, "--upper-limit=100"; |
168 |
|
push @rawdata, "--base=1024"; |
169 |
< |
# add some nice values to the legend |
170 |
< |
&addlegend(\@rawdata, "inuse"); |
171 |
< |
&makegraph($machine, $1, "Memory Usage for $machine", \@data, \@rawdata); |
169 |
> |
# put the total memory on the graph so we can map percentages to real values |
170 |
> |
push @rawdata, "GPRINT:total:LAST:Current total memory\\: \%.2lf %sb\\c"; |
171 |
> |
&makegraph($machine, $1, "Memory Usage for $machine", "% memory in use", \@data, \@rawdata); |
172 |
|
} |
173 |
|
if($rrd =~ /^(load)\.rrd$/) { |
174 |
|
my(@data); |
175 |
|
push @data, "LINE2:$1:load1:load1#CCCCFF:OK: 1 min load average"; |
176 |
|
push @data, "LINE2:$1:load5:load5#7777FF:OK: 5 min load average"; |
177 |
|
push @data, "LINE2:$1:load15:load15#0000FF:OK:15 min load average"; |
178 |
< |
&makegraph($machine, $1, "Loads for $machine", \@data); |
178 |
> |
&makegraph($machine, $1, "Loads for $machine", "load average", \@data); |
179 |
|
} |
180 |
|
if($rrd =~ /^(proc)\.rrd$/) { |
181 |
|
my(@data); |
182 |
< |
push @data, "LINE2:$1:cpu:cpu#00FF00:OK:cpu processes "; |
183 |
< |
push @data, "LINE2:$1:sleeping:sleeping#0000FF:OK:sleeping processes"; |
184 |
< |
push @data, "LINE2:$1:stopped:stopped#00FFFF:OK:stopped processes "; |
185 |
< |
push @data, "LINE2:$1:total:total#FF00FF:OK:total processes "; |
186 |
< |
push @data, "LINE2:$1:zombie:zombie#FF0000:OK:zombie processes "; |
187 |
< |
&makegraph($machine, $1, "Processes on $machine", \@data); |
182 |
> |
push @data, "AREA:$1:stopped:stopped#00FFFF:OK:stopped processes "; |
183 |
> |
push @data, "STACK:$1:zombie:zombie#FF0000:OK:zombie processes "; |
184 |
> |
push @data, "STACK:$1:cpu:cpu#00FF00:OK:cpu processes "; |
185 |
> |
push @data, "STACK:$1:sleeping:sleeping#0000FF:OK:sleeping processes"; |
186 |
> |
#push @data, "LINE2:$1:total:total#FF00FF:OK:total processes "; |
187 |
> |
&makegraph($machine, $1, "Processes on $machine", "no. of processes", \@data); |
188 |
|
} |
189 |
|
if($rrd =~ /^(swap)\.rrd$/) { |
190 |
|
my(@data); |
191 |
|
my(@rawdata); |
192 |
< |
# we don't actually want to display free swap, |
193 |
< |
# although we need it to do inuse... |
192 |
> |
# we don't actually want to display free or total swap, |
193 |
> |
# although we need it to work out peruse... |
194 |
|
push @data, "NONE:$1:free:free#CCCCFF:NONE:free swap"; |
195 |
< |
push @data, "LINE2:$1:total:total#0000FF:NONE:total swap\\n"; |
196 |
< |
# calculate inuse |
197 |
< |
push @rawdata, "CDEF:inuse=total,free,-"; |
195 |
> |
push @data, "NONE:$1:total:total#0000FF:NONE:total swap\\n"; |
196 |
> |
# calculate peruse - note that we only use 'free' if it's less than total |
197 |
> |
# (this is to avoid negative percentages :) |
198 |
> |
push @rawdata, "CDEF:peruse=total,free,total,LT,free,0,IF,-,total,/,100,*"; |
199 |
|
# and add it to the graph |
200 |
< |
push @rawdata, "AREA:inuse#CCCCFF:swap in use"; |
200 |
> |
push @rawdata, "AREA:peruse#CCCCFF:% swap in use"; |
201 |
> |
push @rawdata, "--upper-limit=100"; |
202 |
|
push @rawdata, "--base=1024"; |
203 |
|
# add some nice values to the legend |
204 |
< |
&addlegend(\@rawdata, "inuse"); |
205 |
< |
&makegraph($machine, $1, "Swap Usage for $machine", \@data, \@rawdata); |
204 |
> |
&addlegend(\@rawdata, "peruse"); |
205 |
> |
# put the total swap on the graph so we can map percentages to real values |
206 |
> |
push @rawdata, "GPRINT:total:LAST:Current total swap\\: \%.2lf %sb\\c"; |
207 |
> |
&makegraph($machine, $1, "Swap Usage for $machine", "% swap in use", \@data, \@rawdata); |
208 |
|
} |
209 |
|
if($rrd =~ /^(users)\.rrd$/) { |
210 |
|
my(@data); |
211 |
|
push @data, "AREA:$1:count:count#CCCCFF:OK:user count"; |
212 |
< |
&makegraph($machine, $1, "User Count for $machine", \@data); |
212 |
> |
&makegraph($machine, $1, "User Count for $machine", "no. of users", \@data); |
213 |
|
} |
214 |
< |
if($rrd =~ /^(disk)-(\S+).rrd$/) { |
214 |
> |
if($rrd =~ /^(paging)\.rrd$/) { |
215 |
|
my(@data); |
216 |
+ |
push @data, "AREA:$1:pageins:pageins#00FF00:OK:pages paged in "; |
217 |
+ |
push @data, "LINE2:$1:pageouts:pageouts#0000FF:OK:pages paged out"; |
218 |
+ |
&makegraph($machine, $1, "Paging on $machine", "pages per second", \@data); |
219 |
+ |
} |
220 |
+ |
if($rrd =~ /^(disk)-(\S+)\.rrd$/) { |
221 |
+ |
my(@data); |
222 |
|
my(@rawdata); |
223 |
< |
push @data, "LINE2:$1-$2:kbytes:kbytes#0000FF:NONE:total size\\n"; |
224 |
< |
push @data, "AREA:$1-$2:used:used#CCCCFF:OK:used space"; |
223 |
> |
# we need this lot for our calculations, but we'll never show them |
224 |
> |
push @data, "NONE:$1-$2:total:total#0000FF:NONE:total size\\n"; |
225 |
> |
push @data, "NONE:$1-$2:used:used#CCCCFF:NONE:used space"; |
226 |
> |
push @data, "NONE:$1-$2:totalinodes:totalinodes#000000:NONE:total inodes"; |
227 |
> |
push @data, "NONE:$1-$2:freeinodes:freeinodes#000000:NONE:free inodes"; |
228 |
> |
# calculate peruse, add it to the graph, and add a legend |
229 |
> |
push @rawdata, "CDEF:peruse=used,total,/,100,*"; |
230 |
> |
push @rawdata, "AREA:peruse#CCCCFF:% disk used "; |
231 |
> |
&addlegend(\@rawdata, "peruse"); |
232 |
> |
# put the total space on the graph so we can map percentages to real values |
233 |
> |
push @rawdata, "GPRINT:total:LAST:Current total space\\: \%.2lf %sb\\c"; |
234 |
> |
# calculate perinodeuse, add it to the graph, and add a legend |
235 |
> |
push @rawdata, "CDEF:perinodeuse=totalinodes,freeinodes,totalinodes,LT,freeinodes,0,IF,-,totalinodes,/,100,*"; |
236 |
> |
push @rawdata, "LINE2:perinodeuse#FF4444:% inodes used"; |
237 |
> |
push @rawdata, "--upper-limit=100"; |
238 |
|
push @rawdata, "--base=1024"; |
239 |
+ |
&addlegend(\@rawdata, "perinodeuse"); |
240 |
+ |
# put the total inodes on the graph so we can map percentages to real values |
241 |
+ |
push @rawdata, "GPRINT:totalinodes:LAST:Current total inodes\\: \%.2lf %s\\c"; |
242 |
+ |
# some name tidting |
243 |
|
my($type) = $1; |
244 |
|
my($name) = $2; |
245 |
|
my($nicename) = $2; |
246 |
|
$nicename =~ s/$hex_slash/\//g; |
247 |
|
$nicename =~ s/$hex_underscore/_/g; |
248 |
< |
&makegraph($machine, "$type-$name", "Disk Usage for $machine on $nicename", \@data, \@rawdata); |
248 |
> |
&makegraph($machine, "$type-$name", "Disk Usage for $machine on $nicename", "% usage", \@data, \@rawdata); |
249 |
|
} |
250 |
+ |
if($rrd =~ /^(diskio)-(\S+)\.rrd$/) { |
251 |
+ |
my(@data); |
252 |
+ |
my(@rawdata); |
253 |
+ |
push @data, "AREA:$1-$2:rbytes:rbytes#00FF00:OK:read bytes "; |
254 |
+ |
push @data, "LINE2:$1-$2:wbytes:wbytes#0000FF:OK:write bytes"; |
255 |
+ |
push @rawdata, "--base=1024"; |
256 |
+ |
&makegraph($machine, "$1-$2", "Disk IO for $machine on $2", "bytes per second", \@data, \@rawdata); |
257 |
+ |
} |
258 |
+ |
if($rrd =~ /^(net)-(\S+)\.rrd$/) { |
259 |
+ |
my(@data); |
260 |
+ |
my(@rawdata); |
261 |
+ |
push @data, "AREA:$1-$2:rx:rx#00FF00:OK:received bytes "; |
262 |
+ |
push @data, "LINE2:$1-$2:tx:tx#0000FF:OK:transfered bytes"; |
263 |
+ |
push @rawdata, "--base=1024"; |
264 |
+ |
&makegraph($machine, "$1-$2", "Network IO for $machine on $2", "bytes per second", \@data, \@rawdata); |
265 |
+ |
} |
266 |
+ |
if($rrd =~ /^(mailq)-(\S+)\.rrd$/) { |
267 |
+ |
my(@data); |
268 |
+ |
my(@rawdata); |
269 |
+ |
push @data, "LINE2:$1-$2:size:size#0000FF:OK:messages"; |
270 |
+ |
&makegraph($machine, "$1-$2", "Mail Queue ($2) Size for $machine", "messages in queue", \@data, \@rawdata); |
271 |
+ |
} |
272 |
|
# probably a queue with a name like this :) |
273 |
|
if($rrd =~ /^(\d+)_0\.rrd$/) { |
274 |
|
my(@data); |
287 |
|
chomp $comment if defined $comment; |
288 |
|
} |
289 |
|
$comment = "unknown queue" if not defined $comment; |
290 |
< |
&makegraph($machine, $baserrd, $comment, \@data, \@rawdata); |
290 |
> |
&makegraph($machine, $baserrd, $comment, "", \@data, \@rawdata); |
291 |
|
} |
292 |
|
} |
293 |
|
# have a last check, maybe we can remove the directory now? |
308 |
|
# Read the contents of the graphs directory |
309 |
|
# and pull out the list of subdirectories (except . and .. :) |
310 |
|
opendir(DIR, $imgdir); |
311 |
< |
my(@imgdirlist) = grep { -d "$imgdir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); |
311 |
> |
my(@imgdirlist) = sort grep { -d "$imgdir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); |
312 |
|
closedir DIR; |
313 |
|
|
314 |
|
# look through each directoty, as they might |
356 |
|
# (eg. cpu) |
357 |
|
# $title = the title for the graph |
358 |
|
# (eg. kernow CPU usage) |
359 |
+ |
# $vlabel = the vertical label to apply to the left side of the graph |
360 |
+ |
# (eg. kb/s) |
361 |
|
# $dataref = a reference to an array containing information for the graph |
362 |
|
# elements of format: "gtype:rrdname:dsname:name#colour:legend:comment with spaces" |
363 |
|
# (if gtype is "NONE" only a DEF of 'name' will be defined, no line will be plotted) |
367 |
|
# |
368 |
|
|
369 |
|
sub makegraph() { |
370 |
< |
my($machine, $type, $title, $dataref, $rawcmdref) = @_; |
370 |
> |
my($machine, $type, $title, $vlabel, $dataref, $rawcmdref) = @_; |
371 |
|
# pass in these arrays by reference |
372 |
|
my(@data) = @$dataref if defined $dataref; |
373 |
|
my(@rawcmd) = @$rawcmdref if defined $rawcmdref; |
396 |
|
push @rrdcmd, "--title=$title"; |
397 |
|
push @rrdcmd, "--imgformat=PNG"; |
398 |
|
push @rrdcmd, "--lower-limit=0"; |
399 |
+ |
push @rrdcmd, "--vertical-label=$vlabel"; |
400 |
|
# not entirely convinced this is good... |
401 |
|
push @rrdcmd, "--alt-autoscale-max"; |
402 |
|
# add any further raw commands |
431 |
|
push @$dataref, "GPRINT:$name:LAST:Current\\: \%8.2lf %s"; |
432 |
|
push @$dataref, "GPRINT:$name:AVERAGE:Average\\: \%8.2lf %s"; |
433 |
|
push @$dataref, "GPRINT:$name:MAX:Max\\: \%8.2lf %s\\n"; |
370 |
– |
#push @$dataref, "GPRINT:$name:MIN:Min\\: \%8.2lf %s\\n"; |
434 |
|
} |
435 |
|
|
436 |
|
# hacky subroutine to return a colour |