2 |
|
|
3 |
|
# |
4 |
|
# i-scream central monitoring system |
5 |
< |
# http://www.i-scream.org.uk |
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 |
|
# |
45 |
|
|
46 |
|
# define variables that will be read from the config |
47 |
|
# nb. keep this insync with the config file! |
48 |
< |
use vars qw{ |
49 |
< |
$imgdir $rrddir |
48 |
> |
use vars qw{ |
49 |
> |
$imgdir $rrddir |
50 |
|
$maxrrdage $maximgage $deleterrds $deleteimgs |
51 |
< |
$hex_slash $hex_underscore |
51 |
> |
$hex_slash $hex_underscore $hex_space $hex_colon $hex_bslash $hex_rbracket |
52 |
> |
$hex_lbracket $hex_plus $hex_hash |
53 |
|
$rrdstep $retry_wait |
54 |
|
$verbose $quiet |
55 |
|
}; |
102 |
|
# Read the contents of the base directory |
103 |
|
# and pull out the list of subdirectories (except . and .. :) |
104 |
|
opendir(DIR, $rrddir); |
105 |
< |
my(@rrddirlist) = grep { -d "$rrddir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); |
105 |
> |
my(@rrddirlist) = sort grep { -d "$rrddir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); |
106 |
|
closedir DIR; |
107 |
|
|
108 |
< |
# look through each directoty, as they might |
108 |
> |
# look through each directory, as they might |
109 |
|
# contain rrds for a particular machine |
110 |
|
foreach my $machine (@rrddirlist) { |
111 |
|
# Read the contents of the directory |
136 |
|
if($rrd =~ /^(cpu)\.rrd$/) { |
137 |
|
my(@data); |
138 |
|
my(@rawdata); |
139 |
+ |
push @data, "AREA:$1:swap:swap#FF00FF:OK:swap cpu "; |
140 |
+ |
push @data, "STACK:$1:iowait:iowait#FF0000:OK:iowait cpu"; |
141 |
+ |
push @data, "STACK:$1:kernel:kernel#00FFFF:OK:kernel cpu"; |
142 |
+ |
push @data, "STACK:$1:user:user#0000FF:OK:user cpu "; |
143 |
|
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"; |
144 |
|
push @rawdata, "--upper-limit=100"; |
145 |
|
&makegraph($machine, $1, "CPU Usage for $machine", "% cpu time", \@data, \@rawdata); |
146 |
|
} |
147 |
+ |
if($rrd =~ /^(uptime)\.rrd$/) { |
148 |
+ |
my(@data); |
149 |
+ |
push @data, "LINE2:$1:uptime:uptime#0000FF:OK:uptime"; |
150 |
+ |
&makegraph($machine, $1, "Uptime for $machine", "uptime in seconds", \@data); |
151 |
+ |
} |
152 |
|
if($rrd =~ /^(mem)\.rrd$/) { |
153 |
|
my(@data); |
154 |
|
my(@rawdata); |
156 |
|
# although we need it to work out peruse... |
157 |
|
push @data, "NONE:$1:free:free#CCCCFF:NONE:free memory"; |
158 |
|
push @data, "NONE:$1:total:total#0000FF:NONE:total memory\\n"; |
159 |
< |
# calculate peruse - note that we only use 'free' if it's less than total |
160 |
< |
# (this is to avoid negative percentages :) |
161 |
< |
push @rawdata, "CDEF:peruse=total,free,total,LT,free,0,IF,-,total,/,100,*"; |
159 |
> |
push @data, "NONE:$1:cache:cache#0000FF:NONE:cache memory\\n"; |
160 |
> |
# calculate peruse - note that we only use 'free' if it's |
161 |
> |
# less or equal to total (this is to avoid negative percentages :) |
162 |
> |
push @rawdata, "CDEF:peruse=total,free,total,LE,free,0,IF,-,total,/,100,*"; |
163 |
> |
push @rawdata, "CDEF:percacuse=cache,total,LE,cache,0,IF,total,/,100,*"; |
164 |
|
# and add it to the graph |
165 |
|
push @rawdata, "AREA:peruse#CCCCFF:% memory in use"; |
158 |
– |
push @rawdata, "--upper-limit=100"; |
159 |
– |
# add some nice values to the legend |
166 |
|
&addlegend(\@rawdata, "peruse"); |
167 |
+ |
push @rawdata, "LINE2:percacuse#0000FF:% memory cache "; |
168 |
+ |
&addlegend(\@rawdata, "percacuse"); |
169 |
+ |
push @rawdata, "--upper-limit=100"; |
170 |
+ |
push @rawdata, "--base=1024"; |
171 |
|
# put the total memory on the graph so we can map percentages to real values |
172 |
< |
push @rawdata, "GPRINT:total:LAST:Current total memory\\: \%.2lf %sMb\\c"; |
172 |
> |
push @rawdata, "GPRINT:total:LAST:Current total memory\\: \%.2lf %sb\\c"; |
173 |
|
&makegraph($machine, $1, "Memory Usage for $machine", "% memory in use", \@data, \@rawdata); |
174 |
|
} |
175 |
|
if($rrd =~ /^(load)\.rrd$/) { |
181 |
|
} |
182 |
|
if($rrd =~ /^(proc)\.rrd$/) { |
183 |
|
my(@data); |
184 |
< |
push @data, "LINE2:$1:cpu:cpu#00FF00:OK:cpu processes "; |
185 |
< |
push @data, "LINE2:$1:sleeping:sleeping#0000FF:OK:sleeping processes"; |
186 |
< |
push @data, "LINE2:$1:stopped:stopped#00FFFF:OK:stopped processes "; |
184 |
> |
push @data, "AREA:$1:stopped:stopped#00FFFF:OK:stopped processes "; |
185 |
> |
push @data, "STACK:$1:zombie:zombie#FF0000:OK:zombie processes "; |
186 |
> |
push @data, "STACK:$1:cpu:cpu#00FF00:OK:cpu processes "; |
187 |
> |
push @data, "STACK:$1:sleeping:sleeping#0000FF:OK:sleeping processes"; |
188 |
|
push @data, "LINE2:$1:total:total#FF00FF:OK:total processes "; |
178 |
– |
push @data, "LINE2:$1:zombie:zombie#FF0000:OK:zombie processes "; |
189 |
|
&makegraph($machine, $1, "Processes on $machine", "no. of processes", \@data); |
190 |
|
} |
191 |
|
if($rrd =~ /^(swap)\.rrd$/) { |
195 |
|
# although we need it to work out peruse... |
196 |
|
push @data, "NONE:$1:free:free#CCCCFF:NONE:free swap"; |
197 |
|
push @data, "NONE:$1:total:total#0000FF:NONE:total swap\\n"; |
198 |
< |
# calculate peruse - note that we only use 'free' if it's less than total |
199 |
< |
# (this is to avoid negative percentages :) |
200 |
< |
push @rawdata, "CDEF:peruse=total,free,total,LT,free,0,IF,-,total,/,100,*"; |
198 |
> |
# calculate peruse - note that we only use 'free' if it's |
199 |
> |
# less or equal to total (this is to avoid negative percentages :) |
200 |
> |
push @rawdata, "CDEF:peruse=total,free,total,LE,free,0,IF,-,total,/,100,*"; |
201 |
|
# and add it to the graph |
202 |
|
push @rawdata, "AREA:peruse#CCCCFF:% swap in use"; |
203 |
|
push @rawdata, "--upper-limit=100"; |
204 |
+ |
push @rawdata, "--base=1024"; |
205 |
|
# add some nice values to the legend |
206 |
|
&addlegend(\@rawdata, "peruse"); |
207 |
|
# put the total swap on the graph so we can map percentages to real values |
208 |
< |
push @rawdata, "GPRINT:total:LAST:Current total swap\\: \%.2lf %sMb\\c"; |
208 |
> |
push @rawdata, "GPRINT:total:LAST:Current total swap\\: \%.2lf %sb\\c"; |
209 |
|
&makegraph($machine, $1, "Swap Usage for $machine", "% swap in use", \@data, \@rawdata); |
210 |
|
} |
211 |
|
if($rrd =~ /^(users)\.rrd$/) { |
215 |
|
} |
216 |
|
if($rrd =~ /^(paging)\.rrd$/) { |
217 |
|
my(@data); |
218 |
< |
push @data, "LINE2:$1:swapins:swapins#00FF00:OK:swap pages in "; |
219 |
< |
push @data, "LINE2:$1:swapouts:swapouts#0000FF:OK:swap pages out"; |
218 |
> |
push @data, "AREA:$1:pageins:pageins#00FF00:OK:pages paged in "; |
219 |
> |
push @data, "LINE2:$1:pageouts:pageouts#0000FF:OK:pages paged out"; |
220 |
|
&makegraph($machine, $1, "Paging on $machine", "pages per second", \@data); |
221 |
|
} |
222 |
< |
if($rrd =~ /^(disk)-(\S+).rrd$/) { |
222 |
> |
if($rrd =~ /^(disk)-(\S+)\.rrd$/) { |
223 |
|
my(@data); |
224 |
|
my(@rawdata); |
225 |
|
# we need this lot for our calculations, but we'll never show them |
226 |
< |
push @data, "NONE:$1-$2:kbytes:kbytes#0000FF:NONE:total size\\n"; |
226 |
> |
push @data, "NONE:$1-$2:total:total#0000FF:NONE:total size\\n"; |
227 |
|
push @data, "NONE:$1-$2:used:used#CCCCFF:NONE:used space"; |
228 |
|
push @data, "NONE:$1-$2:totalinodes:totalinodes#000000:NONE:total inodes"; |
229 |
|
push @data, "NONE:$1-$2:freeinodes:freeinodes#000000:NONE:free inodes"; |
230 |
|
# calculate peruse, add it to the graph, and add a legend |
231 |
< |
push @rawdata, "CDEF:peruse=used,kbytes,/,100,*"; |
231 |
> |
push @rawdata, "CDEF:peruse=used,total,/,100,*"; |
232 |
|
push @rawdata, "AREA:peruse#CCCCFF:% disk used "; |
233 |
|
&addlegend(\@rawdata, "peruse"); |
234 |
|
# put the total space on the graph so we can map percentages to real values |
235 |
< |
push @rawdata, "GPRINT:kbytes:LAST:Current total space\\: \%.2lf %sKb\\c"; |
235 |
> |
push @rawdata, "GPRINT:total:LAST:Current total space\\: \%.2lf %sb\\c"; |
236 |
|
# calculate perinodeuse, add it to the graph, and add a legend |
237 |
|
push @rawdata, "CDEF:perinodeuse=totalinodes,freeinodes,totalinodes,LT,freeinodes,0,IF,-,totalinodes,/,100,*"; |
238 |
|
push @rawdata, "LINE2:perinodeuse#FF4444:% inodes used"; |
239 |
|
push @rawdata, "--upper-limit=100"; |
240 |
+ |
push @rawdata, "--base=1024"; |
241 |
|
&addlegend(\@rawdata, "perinodeuse"); |
242 |
|
# put the total inodes on the graph so we can map percentages to real values |
243 |
|
push @rawdata, "GPRINT:totalinodes:LAST:Current total inodes\\: \%.2lf %s\\c"; |
247 |
|
my($nicename) = $2; |
248 |
|
$nicename =~ s/$hex_slash/\//g; |
249 |
|
$nicename =~ s/$hex_underscore/_/g; |
250 |
+ |
$nicename =~ s/$hex_bslash/\\/g; |
251 |
+ |
$nicename =~ s/$hex_space/ /g; |
252 |
+ |
$nicename =~ s/$hex_colon/:/g; |
253 |
|
&makegraph($machine, "$type-$name", "Disk Usage for $machine on $nicename", "% usage", \@data, \@rawdata); |
254 |
|
} |
255 |
+ |
if($rrd =~ /^(diskio)-(\S+)\.rrd$/) { |
256 |
+ |
my(@data); |
257 |
+ |
my(@rawdata); |
258 |
+ |
push @data, "AREA:$1-$2:rbytes:rbytes#00FF00:OK:read bytes "; |
259 |
+ |
push @data, "LINE2:$1-$2:wbytes:wbytes#0000FF:OK:write bytes"; |
260 |
+ |
push @rawdata, "--base=1024"; |
261 |
+ |
# some name tidying |
262 |
+ |
my($type) = $1; |
263 |
+ |
my($name) = $2; |
264 |
+ |
my($nicename) = $2; |
265 |
+ |
$nicename =~ s/$hex_slash/\//g; |
266 |
+ |
$nicename =~ s/$hex_underscore/_/g; |
267 |
+ |
$nicename =~ s/$hex_bslash/\\/g; |
268 |
+ |
$nicename =~ s/$hex_space/ /g; |
269 |
+ |
$nicename =~ s/$hex_colon/:/g; |
270 |
+ |
&makegraph($machine, "$type-$name", "Disk IO for $machine on $nicename", "bytes per second", \@data, \@rawdata); |
271 |
+ |
} |
272 |
+ |
if($rrd =~ /^(net)-(\S+)\.rrd$/) { |
273 |
+ |
my(@data); |
274 |
+ |
my(@rawdata); |
275 |
+ |
push @data, "AREA:$1-$2:rx:rx#00FF00:OK:received bytes "; |
276 |
+ |
push @data, "LINE2:$1-$2:tx:tx#0000FF:OK:transfered bytes"; |
277 |
+ |
push @rawdata, "--base=1024"; |
278 |
+ |
# some name tidying |
279 |
+ |
my($type) = $1; |
280 |
+ |
my($name) = $2; |
281 |
+ |
my($nicename) = $2; |
282 |
+ |
$nicename =~ s/$hex_slash/\//g; |
283 |
+ |
$nicename =~ s/$hex_underscore/_/g; |
284 |
+ |
$nicename =~ s/$hex_bslash/\\/g; |
285 |
+ |
$nicename =~ s/$hex_space/ /g; |
286 |
+ |
$nicename =~ s/$hex_colon/:/g; |
287 |
+ |
$nicename =~ s/$hex_lbracket/(/g; |
288 |
+ |
$nicename =~ s/$hex_rbracket/)/g; |
289 |
+ |
$nicename =~ s/$hex_plus/+/g; |
290 |
+ |
$nicename =~ s/$hex_hash/#/g; |
291 |
+ |
&makegraph($machine, "$type-$name", "Network IO for $machine on $nicename", "bytes per second", \@data, \@rawdata); |
292 |
+ |
} |
293 |
+ |
if($rrd =~ /^(mailq)-(\S+)\.rrd$/) { |
294 |
+ |
my(@data); |
295 |
+ |
my(@rawdata); |
296 |
+ |
push @data, "LINE2:$1-$2:size:size#0000FF:OK:messages"; |
297 |
+ |
&makegraph($machine, "$1-$2", "Mail Queue ($2) Size for $machine", "messages in queue", \@data, \@rawdata); |
298 |
+ |
} |
299 |
|
# probably a queue with a name like this :) |
300 |
|
if($rrd =~ /^(\d+)_0\.rrd$/) { |
301 |
|
my(@data); |
335 |
|
# Read the contents of the graphs directory |
336 |
|
# and pull out the list of subdirectories (except . and .. :) |
337 |
|
opendir(DIR, $imgdir); |
338 |
< |
my(@imgdirlist) = grep { -d "$imgdir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); |
338 |
> |
my(@imgdirlist) = sort grep { -d "$imgdir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); |
339 |
|
closedir DIR; |
340 |
|
|
341 |
< |
# look through each directoty, as they might |
341 |
> |
# look through each directory, as they might |
342 |
|
# contain images for a particular machine |
343 |
|
foreach my $machine (@imgdirlist) { |
344 |
|
# Read the contents of the directory |
458 |
|
push @$dataref, "GPRINT:$name:LAST:Current\\: \%8.2lf %s"; |
459 |
|
push @$dataref, "GPRINT:$name:AVERAGE:Average\\: \%8.2lf %s"; |
460 |
|
push @$dataref, "GPRINT:$name:MAX:Max\\: \%8.2lf %s\\n"; |
402 |
– |
#push @$dataref, "GPRINT:$name:MIN:Min\\: \%8.2lf %s\\n"; |
461 |
|
} |
462 |
|
|
463 |
|
# hacky subroutine to return a colour |