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 |
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); |
135 |
|
if($rrd =~ /^(cpu)\.rrd$/) { |
136 |
|
my(@data); |
137 |
|
my(@rawdata); |
138 |
< |
push @data, "LINE2:$1:idle:idle#00FF00:OK:idle cpu"; |
139 |
< |
push @data, "LINE2:$1:user:user#0000FF:OK:user 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"; |
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... |
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, "LINE2:$1:total:total#0000FF:NONE:total memory"; |
153 |
< |
# calculate inuse |
154 |
< |
push @rawdata, "CDEF:inuse=total,free,-"; |
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\\l"; |
158 |
< |
push @rawdata, "--base=1024"; |
157 |
> |
push @rawdata, "AREA:peruse#CCCCFF:% memory in use"; |
158 |
> |
push @rawdata, "--upper-limit=100"; |
159 |
|
# add some nice values to the legend |
160 |
< |
&addlegend(\@rawdata, "inuse"); |
161 |
< |
&makegraph($machine, $1, "Memory Usage for $machine", \@data, \@rawdata); |
160 |
> |
&addlegend(\@rawdata, "peruse"); |
161 |
> |
# put the total memory on the graph so we can map percentages to real values |
162 |
> |
push @rawdata, "GPRINT:total:LAST:Current total memory\\: \%.2lf %sMb\\c"; |
163 |
> |
&makegraph($machine, $1, "Memory Usage for $machine", "% memory in use", \@data, \@rawdata); |
164 |
|
} |
165 |
|
if($rrd =~ /^(load)\.rrd$/) { |
166 |
|
my(@data); |
167 |
< |
push @data, "LINE2:$1:load1:load1#CCCCFF:OK:1 minute load average"; |
168 |
< |
push @data, "LINE2:$1:load5:load5#7777FF:OK:5 minute load average"; |
169 |
< |
push @data, "LINE2:$1:load15:load15#0000FF:OK:15 minute load average"; |
170 |
< |
&makegraph($machine, $1, "Loads for $machine", \@data); |
167 |
> |
push @data, "LINE2:$1:load1:load1#CCCCFF:OK: 1 min load average"; |
168 |
> |
push @data, "LINE2:$1:load5:load5#7777FF:OK: 5 min load average"; |
169 |
> |
push @data, "LINE2:$1:load15:load15#0000FF:OK:15 min load average"; |
170 |
> |
&makegraph($machine, $1, "Loads for $machine", "load average", \@data); |
171 |
|
} |
172 |
|
if($rrd =~ /^(proc)\.rrd$/) { |
173 |
|
my(@data); |
174 |
< |
push @data, "LINE2:$1:cpu:cpu#00FF00:OK:cpu processes"; |
174 |
> |
push @data, "LINE2:$1:cpu:cpu#00FF00:OK:cpu processes "; |
175 |
|
push @data, "LINE2:$1:sleeping:sleeping#0000FF:OK:sleeping processes"; |
176 |
< |
push @data, "LINE2:$1:stopped:stopped#00FFFF:OK:stopped processes"; |
177 |
< |
push @data, "LINE2:$1:total:total#FF00FF:OK:total processes"; |
178 |
< |
push @data, "LINE2:$1:zombie:zombie#FF0000:OK:zombie processes"; |
179 |
< |
&makegraph($machine, $1, "Processes on $machine", \@data); |
176 |
> |
push @data, "LINE2:$1:stopped:stopped#00FFFF:OK:stopped processes "; |
177 |
> |
push @data, "LINE2:$1:total:total#FF00FF:OK:total processes "; |
178 |
> |
push @data, "LINE2:$1:zombie:zombie#FF0000:OK:zombie processes "; |
179 |
> |
&makegraph($machine, $1, "Processes on $machine", "no. of processes", \@data); |
180 |
|
} |
181 |
|
if($rrd =~ /^(swap)\.rrd$/) { |
182 |
|
my(@data); |
183 |
|
my(@rawdata); |
184 |
< |
# we don't actually want to display free swap, |
185 |
< |
# although we need it to do inuse... |
184 |
> |
# we don't actually want to display free or total swap, |
185 |
> |
# although we need it to work out peruse... |
186 |
|
push @data, "NONE:$1:free:free#CCCCFF:NONE:free swap"; |
187 |
< |
push @data, "LINE2:$1:total:total#0000FF:NONE:total swap"; |
188 |
< |
# calculate inuse |
189 |
< |
push @rawdata, "CDEF:inuse=total,free,-"; |
187 |
> |
push @data, "NONE:$1:total:total#0000FF:NONE:total swap\\n"; |
188 |
> |
# calculate peruse - note that we only use 'free' if it's less than total |
189 |
> |
# (this is to avoid negative percentages :) |
190 |
> |
push @rawdata, "CDEF:peruse=total,free,total,LT,free,0,IF,-,total,/,100,*"; |
191 |
|
# and add it to the graph |
192 |
< |
push @rawdata, "AREA:inuse#CCCCFF:swap in use\\l"; |
193 |
< |
push @rawdata, "--base=1024"; |
192 |
> |
push @rawdata, "AREA:peruse#CCCCFF:% swap in use"; |
193 |
> |
push @rawdata, "--upper-limit=100"; |
194 |
|
# add some nice values to the legend |
195 |
< |
&addlegend(\@rawdata, "inuse"); |
196 |
< |
&makegraph($machine, $1, "Swap Usage for $machine", \@data, \@rawdata); |
195 |
> |
&addlegend(\@rawdata, "peruse"); |
196 |
> |
# put the total swap on the graph so we can map percentages to real values |
197 |
> |
push @rawdata, "GPRINT:total:LAST:Current total swap\\: \%.2lf %sMb\\c"; |
198 |
> |
&makegraph($machine, $1, "Swap Usage for $machine", "% swap in use", \@data, \@rawdata); |
199 |
|
} |
200 |
|
if($rrd =~ /^(users)\.rrd$/) { |
201 |
|
my(@data); |
202 |
|
push @data, "AREA:$1:count:count#CCCCFF:OK:user count"; |
203 |
< |
&makegraph($machine, $1, "User Count for $machine", \@data); |
203 |
> |
&makegraph($machine, $1, "User Count for $machine", "no. of users", \@data); |
204 |
|
} |
205 |
+ |
if($rrd =~ /^(paging)\.rrd$/) { |
206 |
+ |
my(@data); |
207 |
+ |
push @data, "LINE2:$1:swapins:swapins#00FF00:OK:swap pages in "; |
208 |
+ |
push @data, "LINE2:$1:swapouts:swapouts#0000FF:OK:swap pages out"; |
209 |
+ |
&makegraph($machine, $1, "Paging on $machine", "pages per second", \@data); |
210 |
+ |
} |
211 |
|
if($rrd =~ /^(disk)-(\S+).rrd$/) { |
212 |
|
my(@data); |
213 |
|
my(@rawdata); |
214 |
< |
push @data, "LINE2:$1-$2:kbytes:kbytes#0000FF:NONE:total size"; |
215 |
< |
push @data, "AREA:$1-$2:used:used#CCCCFF:OK:used"; |
216 |
< |
push @rawdata, "--base=1024"; |
214 |
> |
# we need this lot for our calculations, but we'll never show them |
215 |
> |
push @data, "NONE:$1-$2:kbytes:kbytes#0000FF:NONE:total size\\n"; |
216 |
> |
push @data, "NONE:$1-$2:used:used#CCCCFF:NONE:used space"; |
217 |
> |
push @data, "NONE:$1-$2:totalinodes:totalinodes#000000:NONE:total inodes"; |
218 |
> |
push @data, "NONE:$1-$2:freeinodes:freeinodes#000000:NONE:free inodes"; |
219 |
> |
# calculate peruse, add it to the graph, and add a legend |
220 |
> |
push @rawdata, "CDEF:peruse=used,kbytes,/,100,*"; |
221 |
> |
push @rawdata, "AREA:peruse#CCCCFF:% disk used "; |
222 |
> |
&addlegend(\@rawdata, "peruse"); |
223 |
> |
# put the total space on the graph so we can map percentages to real values |
224 |
> |
push @rawdata, "GPRINT:kbytes:LAST:Current total space\\: \%.2lf %sKb\\c"; |
225 |
> |
# calculate perinodeuse, add it to the graph, and add a legend |
226 |
> |
push @rawdata, "CDEF:perinodeuse=totalinodes,freeinodes,totalinodes,LT,freeinodes,0,IF,-,totalinodes,/,100,*"; |
227 |
> |
push @rawdata, "LINE2:perinodeuse#FF4444:% inodes used"; |
228 |
> |
push @rawdata, "--upper-limit=100"; |
229 |
> |
&addlegend(\@rawdata, "perinodeuse"); |
230 |
> |
# put the total inodes on the graph so we can map percentages to real values |
231 |
> |
push @rawdata, "GPRINT:totalinodes:LAST:Current total inodes\\: \%.2lf %s\\c"; |
232 |
> |
# some name tidting |
233 |
|
my($type) = $1; |
234 |
|
my($name) = $2; |
235 |
|
my($nicename) = $2; |
236 |
|
$nicename =~ s/$hex_slash/\//g; |
237 |
|
$nicename =~ s/$hex_underscore/_/g; |
238 |
< |
&makegraph($machine, "$type-$name", "Disk Usage for $machine on $nicename", \@data, \@rawdata); |
238 |
> |
&makegraph($machine, "$type-$name", "Disk Usage for $machine on $nicename", "% usage", \@data, \@rawdata); |
239 |
|
} |
240 |
|
# probably a queue with a name like this :) |
241 |
|
if($rrd =~ /^(\d+)_0\.rrd$/) { |
247 |
|
push @data, "LINE2:$baserrd\_$i:size:size$i" . &get_colour($i) . ":OK:queue$i size "; |
248 |
|
++$i; |
249 |
|
} |
250 |
< |
push @data, "LINE2:$baserrd\_0:total:total#FF0000:OK:packets/sec"; |
250 |
> |
push @data, "LINE2:$baserrd\_0:total:total#FF0000:OK:packets/sec "; |
251 |
|
my($comment); |
252 |
|
if(-f "$rrddir/$machine/$baserrd.def") { |
253 |
|
open(DEF, "$rrddir/$machine/$baserrd.def"); |
255 |
|
chomp $comment if defined $comment; |
256 |
|
} |
257 |
|
$comment = "unknown queue" if not defined $comment; |
258 |
< |
&makegraph($machine, $baserrd, $comment, \@data, \@rawdata); |
258 |
> |
&makegraph($machine, $baserrd, $comment, "", \@data, \@rawdata); |
259 |
|
} |
260 |
|
} |
261 |
|
# have a last check, maybe we can remove the directory now? |
324 |
|
# (eg. cpu) |
325 |
|
# $title = the title for the graph |
326 |
|
# (eg. kernow CPU usage) |
327 |
+ |
# $vlabel = the vertical label to apply to the left side of the graph |
328 |
+ |
# (eg. kb/s) |
329 |
|
# $dataref = a reference to an array containing information for the graph |
330 |
|
# elements of format: "gtype:rrdname:dsname:name#colour:legend:comment with spaces" |
331 |
|
# (if gtype is "NONE" only a DEF of 'name' will be defined, no line will be plotted) |
335 |
|
# |
336 |
|
|
337 |
|
sub makegraph() { |
338 |
< |
my($machine, $type, $title, $dataref, $rawcmdref) = @_; |
338 |
> |
my($machine, $type, $title, $vlabel, $dataref, $rawcmdref) = @_; |
339 |
|
# pass in these arrays by reference |
340 |
|
my(@data) = @$dataref if defined $dataref; |
341 |
|
my(@rawcmd) = @$rawcmdref if defined $rawcmdref; |
353 |
|
if($dataitem =~ /^(\S+):(\S+):(\S+):(\S+)#(.{6}):(\S+):(.*)$/) { |
354 |
|
push @rrdcmd, "DEF:$4=$rrddir/$machine/$2.rrd:$3:AVERAGE"; |
355 |
|
if($1 ne "NONE") { |
356 |
< |
push @rrdcmd, "$1:$4#$5:$7\\s"; |
356 |
> |
push @rrdcmd, "$1:$4#$5:$7"; |
357 |
|
if($6 ne "NONE") { |
358 |
|
# add some nice values to the legend |
359 |
|
&addlegend(\@rrdcmd, $4); |
364 |
|
push @rrdcmd, "--title=$title"; |
365 |
|
push @rrdcmd, "--imgformat=PNG"; |
366 |
|
push @rrdcmd, "--lower-limit=0"; |
367 |
+ |
push @rrdcmd, "--vertical-label=$vlabel"; |
368 |
|
# not entirely convinced this is good... |
369 |
|
push @rrdcmd, "--alt-autoscale-max"; |
370 |
|
# add any further raw commands |
396 |
|
# accepts reference to an array and a name |
397 |
|
sub addlegend() { |
398 |
|
my($dataref, $name) = @_; |
399 |
< |
push @$dataref, "GPRINT:$name:LAST:latest=\%lf\\r"; |
400 |
< |
push @$dataref, "GPRINT:$name:AVERAGE:average=\%lf"; |
401 |
< |
push @$dataref, "GPRINT:$name:MAX:max=\%lf"; |
402 |
< |
push @$dataref, "GPRINT:$name:MIN:min=\%lf\\r"; |
399 |
> |
push @$dataref, "GPRINT:$name:LAST:Current\\: \%8.2lf %s"; |
400 |
> |
push @$dataref, "GPRINT:$name:AVERAGE:Average\\: \%8.2lf %s"; |
401 |
> |
push @$dataref, "GPRINT:$name:MAX:Max\\: \%8.2lf %s\\n"; |
402 |
> |
#push @$dataref, "GPRINT:$name:MIN:Min\\: \%8.2lf %s\\n"; |
403 |
|
} |
404 |
|
|
405 |
|
# hacky subroutine to return a colour |