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 |
52 |
|
$rrdstep $retry_wait |
53 |
|
$verbose $quiet |
54 |
|
}; |
101 |
|
# Read the contents of the base directory |
102 |
|
# and pull out the list of subdirectories (except . and .. :) |
103 |
|
opendir(DIR, $rrddir); |
104 |
< |
my(@rrddirlist) = grep { -d "$rrddir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); |
104 |
> |
my(@rrddirlist) = sort grep { -d "$rrddir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); |
105 |
|
closedir DIR; |
106 |
|
|
107 |
< |
# look through each directoty, as they might |
107 |
> |
# look through each directory, as they might |
108 |
|
# contain rrds for a particular machine |
109 |
|
foreach my $machine (@rrddirlist) { |
110 |
|
# Read the contents of the directory |
135 |
|
if($rrd =~ /^(cpu)\.rrd$/) { |
136 |
|
my(@data); |
137 |
|
my(@rawdata); |
138 |
+ |
push @data, "AREA:$1:swap:swap#FF00FF:OK:swap cpu "; |
139 |
+ |
push @data, "STACK:$1:iowait:iowait#FF0000:OK:iowait cpu"; |
140 |
+ |
push @data, "STACK:$1:kernel:kernel#00FFFF:OK:kernel cpu"; |
141 |
+ |
push @data, "STACK:$1:user:user#0000FF:OK:user cpu "; |
142 |
|
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", "% cpu time", \@data, \@rawdata); |
145 |
|
} |
146 |
+ |
if($rrd =~ /^(uptime)\.rrd$/) { |
147 |
+ |
my(@data); |
148 |
+ |
push @data, "LINE2:$1:uptime:uptime#0000FF:OK:uptime"; |
149 |
+ |
&makegraph($machine, $1, "Uptime for $machine", "uptime in seconds", \@data); |
150 |
+ |
} |
151 |
|
if($rrd =~ /^(mem)\.rrd$/) { |
152 |
|
my(@data); |
153 |
|
my(@rawdata); |
155 |
|
# although we need it to work out peruse... |
156 |
|
push @data, "NONE:$1:free:free#CCCCFF:NONE:free memory"; |
157 |
|
push @data, "NONE:$1:total:total#0000FF:NONE:total 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,*"; |
158 |
> |
push @data, "NONE:$1:cache:cache#0000FF:NONE:cache memory\\n"; |
159 |
> |
# calculate peruse - note that we only use 'free' if it's |
160 |
> |
# less or equal to total (this is to avoid negative percentages :) |
161 |
> |
push @rawdata, "CDEF:peruse=total,free,total,LE,free,0,IF,-,total,/,100,*"; |
162 |
> |
push @rawdata, "CDEF:percacuse=cache,total,LE,cache,0,IF,total,/,100,*"; |
163 |
|
# and add it to the graph |
164 |
|
push @rawdata, "AREA:peruse#CCCCFF:% memory in use"; |
165 |
+ |
&addlegend(\@rawdata, "peruse"); |
166 |
+ |
push @rawdata, "LINE2:percacuse#0000FF:% memory cache "; |
167 |
+ |
&addlegend(\@rawdata, "percacuse"); |
168 |
|
push @rawdata, "--upper-limit=100"; |
169 |
|
push @rawdata, "--base=1024"; |
160 |
– |
# add some nice values to the legend |
161 |
– |
&addlegend(\@rawdata, "peruse"); |
170 |
|
# put the total memory on the graph so we can map percentages to real values |
171 |
|
push @rawdata, "GPRINT:total:LAST:Current total memory\\: \%.2lf %sb\\c"; |
172 |
|
&makegraph($machine, $1, "Memory Usage for $machine", "% memory in use", \@data, \@rawdata); |
180 |
|
} |
181 |
|
if($rrd =~ /^(proc)\.rrd$/) { |
182 |
|
my(@data); |
183 |
< |
push @data, "LINE2:$1:cpu:cpu#00FF00:OK:cpu processes "; |
184 |
< |
push @data, "LINE2:$1:sleeping:sleeping#0000FF:OK:sleeping processes"; |
185 |
< |
push @data, "LINE2:$1:stopped:stopped#00FFFF:OK:stopped processes "; |
183 |
> |
push @data, "AREA:$1:stopped:stopped#00FFFF:OK:stopped processes "; |
184 |
> |
push @data, "STACK:$1:zombie:zombie#FF0000:OK:zombie processes "; |
185 |
> |
push @data, "STACK:$1:cpu:cpu#00FF00:OK:cpu processes "; |
186 |
> |
push @data, "STACK:$1:sleeping:sleeping#0000FF:OK:sleeping processes"; |
187 |
|
push @data, "LINE2:$1:total:total#FF00FF:OK:total processes "; |
179 |
– |
push @data, "LINE2:$1:zombie:zombie#FF0000:OK:zombie processes "; |
188 |
|
&makegraph($machine, $1, "Processes on $machine", "no. of processes", \@data); |
189 |
|
} |
190 |
|
if($rrd =~ /^(swap)\.rrd$/) { |
194 |
|
# although we need it to work out peruse... |
195 |
|
push @data, "NONE:$1:free:free#CCCCFF:NONE:free swap"; |
196 |
|
push @data, "NONE:$1:total:total#0000FF:NONE:total swap\\n"; |
197 |
< |
# calculate peruse - note that we only use 'free' if it's less than total |
198 |
< |
# (this is to avoid negative percentages :) |
199 |
< |
push @rawdata, "CDEF:peruse=total,free,total,LT,free,0,IF,-,total,/,100,*"; |
197 |
> |
# calculate peruse - note that we only use 'free' if it's |
198 |
> |
# less or equal to total (this is to avoid negative percentages :) |
199 |
> |
push @rawdata, "CDEF:peruse=total,free,total,LE,free,0,IF,-,total,/,100,*"; |
200 |
|
# and add it to the graph |
201 |
|
push @rawdata, "AREA:peruse#CCCCFF:% swap in use"; |
202 |
|
push @rawdata, "--upper-limit=100"; |
214 |
|
} |
215 |
|
if($rrd =~ /^(paging)\.rrd$/) { |
216 |
|
my(@data); |
217 |
< |
push @data, "LINE2:$1:pageins:pageins#00FF00:OK:pages paged in "; |
217 |
> |
push @data, "AREA:$1:pageins:pageins#00FF00:OK:pages paged in "; |
218 |
|
push @data, "LINE2:$1:pageouts:pageouts#0000FF:OK:pages paged out"; |
219 |
|
&makegraph($machine, $1, "Paging on $machine", "pages per second", \@data); |
220 |
|
} |
246 |
|
my($nicename) = $2; |
247 |
|
$nicename =~ s/$hex_slash/\//g; |
248 |
|
$nicename =~ s/$hex_underscore/_/g; |
249 |
+ |
$nicename =~ s/$hex_bslash/\\/g; |
250 |
+ |
$nicename =~ s/$hex_space/ /g; |
251 |
+ |
$nicename =~ s/$hex_colon/:/g; |
252 |
|
&makegraph($machine, "$type-$name", "Disk Usage for $machine on $nicename", "% usage", \@data, \@rawdata); |
253 |
|
} |
254 |
|
if($rrd =~ /^(diskio)-(\S+)\.rrd$/) { |
255 |
|
my(@data); |
256 |
|
my(@rawdata); |
257 |
< |
push @data, "LINE2:$1-$2:rbytes:rbytes#00FF00:OK:read bytes "; |
257 |
> |
push @data, "AREA:$1-$2:rbytes:rbytes#00FF00:OK:read bytes "; |
258 |
|
push @data, "LINE2:$1-$2:wbytes:wbytes#0000FF:OK:write bytes"; |
259 |
|
push @rawdata, "--base=1024"; |
260 |
< |
&makegraph($machine, "$1-$2", "Disk IO for $machine on $2", "bytes per second", \@data, \@rawdata); |
260 |
> |
# some name tidting |
261 |
> |
my($type) = $1; |
262 |
> |
my($name) = $2; |
263 |
> |
my($nicename) = $2; |
264 |
> |
$nicename =~ s/$hex_slash/\//g; |
265 |
> |
$nicename =~ s/$hex_underscore/_/g; |
266 |
> |
$nicename =~ s/$hex_bslash/\\/g; |
267 |
> |
$nicename =~ s/$hex_space/ /g; |
268 |
> |
$nicename =~ s/$hex_colon/:/g; |
269 |
> |
&makegraph($machine, "$type-$name", "Disk IO for $machine on $nicename", "bytes per second", \@data, \@rawdata); |
270 |
|
} |
271 |
|
if($rrd =~ /^(net)-(\S+)\.rrd$/) { |
272 |
|
my(@data); |
273 |
|
my(@rawdata); |
274 |
< |
push @data, "LINE2:$1-$2:rx:rx#00FF00:OK:received bytes "; |
274 |
> |
push @data, "AREA:$1-$2:rx:rx#00FF00:OK:received bytes "; |
275 |
|
push @data, "LINE2:$1-$2:tx:tx#0000FF:OK:transfered bytes"; |
276 |
|
push @rawdata, "--base=1024"; |
277 |
< |
&makegraph($machine, "$1-$2", "Network IO for $machine on $2", "bytes per second", \@data, \@rawdata); |
277 |
> |
# some name tidting |
278 |
> |
my($type) = $1; |
279 |
> |
my($name) = $2; |
280 |
> |
my($nicename) = $2; |
281 |
> |
$nicename =~ s/$hex_slash/\//g; |
282 |
> |
$nicename =~ s/$hex_underscore/_/g; |
283 |
> |
$nicename =~ s/$hex_bslash/\\/g; |
284 |
> |
$nicename =~ s/$hex_space/ /g; |
285 |
> |
$nicename =~ s/$hex_colon/:/g; |
286 |
> |
&makegraph($machine, "$type-$name", "Network IO for $machine on $nicename", "bytes per second", \@data, \@rawdata); |
287 |
|
} |
288 |
+ |
if($rrd =~ /^(mailq)-(\S+)\.rrd$/) { |
289 |
+ |
my(@data); |
290 |
+ |
my(@rawdata); |
291 |
+ |
push @data, "LINE2:$1-$2:size:size#0000FF:OK:messages"; |
292 |
+ |
&makegraph($machine, "$1-$2", "Mail Queue ($2) Size for $machine", "messages in queue", \@data, \@rawdata); |
293 |
+ |
} |
294 |
|
# probably a queue with a name like this :) |
295 |
|
if($rrd =~ /^(\d+)_0\.rrd$/) { |
296 |
|
my(@data); |
330 |
|
# Read the contents of the graphs directory |
331 |
|
# and pull out the list of subdirectories (except . and .. :) |
332 |
|
opendir(DIR, $imgdir); |
333 |
< |
my(@imgdirlist) = grep { -d "$imgdir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); |
333 |
> |
my(@imgdirlist) = sort grep { -d "$imgdir/$_" && !/^\.$/ && !/^\.\.$/ } readdir(DIR); |
334 |
|
closedir DIR; |
335 |
|
|
336 |
< |
# look through each directoty, as they might |
336 |
> |
# look through each directory, as they might |
337 |
|
# contain images for a particular machine |
338 |
|
foreach my $machine (@imgdirlist) { |
339 |
|
# Read the contents of the directory |