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 |
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", "% 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", "megabytes", \@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); |
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 "; |
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", "megabytes", \@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", "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", "kilobytes", \@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); |
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 |
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"; |
373 |
– |
#push @$dataref, "GPRINT:$name:MIN:Min\\: \%8.2lf %s\\n"; |
434 |
|
} |
435 |
|
|
436 |
|
# hacky subroutine to return a colour |