11 |
|
#------------------------------------------------------------ |
12 |
|
|
13 |
|
## TODO |
14 |
+ |
# allow specification of lower/upper graph bounds |
15 |
+ |
# -- then replace mem/swap/disk "total" line ;) |
16 |
|
# possibly make more configurable? |
17 |
|
# -- allow configurable periods of graphs |
18 |
|
# -- comments, types, etc |
53 |
|
chomp $rrd; |
54 |
|
if($rrd =~ /^(cpu)\.rrd$/) { |
55 |
|
my(@data); |
56 |
< |
push @data, "LINE2:$1:idle#00FF00:idle cpu"; |
57 |
< |
push @data, "LINE2:$1:user#0000FF:user cpu"; |
58 |
< |
push @data, "LINE2:$1:kernel#00FFFF:kernel cpu"; |
59 |
< |
push @data, "LINE2:$1:swap#FF00FF:swap cpu"; |
60 |
< |
push @data, "LINE2:$1:iowait#FF0000:iowait cpu"; |
56 |
> |
push @data, "LINE2:$1:idle:idle#00FF00:idle cpu"; |
57 |
> |
push @data, "LINE2:$1:user:user#0000FF:user cpu"; |
58 |
> |
push @data, "LINE2:$1:kernel:kernel#00FFFF:kernel cpu"; |
59 |
> |
push @data, "LINE2:$1:swap:swap#FF00FF:swap cpu"; |
60 |
> |
push @data, "LINE2:$1:iowait:iowait#FF0000:iowait cpu"; |
61 |
|
&makegraph($machine, $1, "CPU Usage for $machine", \@data); |
62 |
|
} |
63 |
|
if($rrd =~ /^(mem)\.rrd$/) { |
64 |
|
my(@data); |
65 |
< |
push @data, "LINE2:$1:free#00FF00:free memory"; |
66 |
< |
push @data, "LINE2:$1:total#0000FF:total memory"; |
65 |
> |
push @data, "LINE2:$1:free:free#00FF00:free memory"; |
66 |
> |
push @data, "LINE2:$1:total:total#0000FF:total memory"; |
67 |
|
&makegraph($machine, $1, "Memory Usage for $machine", \@data); |
68 |
|
} |
69 |
|
if($rrd =~ /^(load)\.rrd$/) { |
70 |
|
my(@data); |
71 |
< |
push @data, "LINE2:$1:load1#00FF00:1 minute load average"; |
72 |
< |
push @data, "LINE2:$1:load5#0000FF:5 minute load average"; |
73 |
< |
push @data, "LINE2:$1:load15#FF0000:15 minute load average"; |
71 |
> |
push @data, "LINE2:$1:load1:load1#00FF00:1 minute load average"; |
72 |
> |
push @data, "LINE2:$1:load5:load5#0000FF:5 minute load average"; |
73 |
> |
push @data, "LINE2:$1:load15:load15#FF0000:15 minute load average"; |
74 |
|
&makegraph($machine, $1, "Loads for $machine", \@data); |
75 |
|
} |
76 |
|
if($rrd =~ /^(proc)\.rrd$/) { |
77 |
|
my(@data); |
78 |
< |
push @data, "LINE2:$1:cpu#00FF00:cpu processes"; |
79 |
< |
push @data, "LINE2:$1:sleeping#0000FF:sleeping processes"; |
80 |
< |
push @data, "LINE2:$1:stopped#00FFFF:stopped processes"; |
81 |
< |
push @data, "LINE2:$1:total#FF00FF:total processes"; |
82 |
< |
push @data, "LINE2:$1:zombie#FF0000:zombie processes"; |
78 |
> |
push @data, "LINE2:$1:cpu:cpu#00FF00:cpu processes"; |
79 |
> |
push @data, "LINE2:$1:sleeping:sleeping#0000FF:sleeping processes"; |
80 |
> |
push @data, "LINE2:$1:stopped:stopped#00FFFF:stopped processes"; |
81 |
> |
push @data, "LINE2:$1:total:total#FF00FF:total processes"; |
82 |
> |
push @data, "LINE2:$1:zombie:zombie#FF0000:zombie processes"; |
83 |
|
&makegraph($machine, $1, "Processes on $machine", \@data); |
84 |
|
} |
85 |
|
if($rrd =~ /^(swap)\.rrd$/) { |
86 |
|
my(@data); |
87 |
< |
push @data, "LINE2:$1:free#00FF00:free swap"; |
88 |
< |
push @data, "LINE2:$1:total#0000FF:total swap"; |
87 |
> |
push @data, "LINE2:$1:free:free#00FF00:free swap"; |
88 |
> |
push @data, "LINE2:$1:total:total#0000FF:total swap"; |
89 |
|
&makegraph($machine, $1, "Swap Usage for $machine", \@data); |
90 |
|
} |
91 |
|
if($rrd =~ /^(users)\.rrd$/) { |
92 |
|
my(@data); |
93 |
< |
push @data, "LINE2:$1:count#00FF00:user count"; |
93 |
> |
push @data, "LINE2:$1:count:count#00FF00:user count"; |
94 |
|
&makegraph($machine, $1, "User Count for $machine", \@data); |
95 |
|
} |
96 |
|
if($rrd =~ /^(disk)-(\S+).rrd$/) { |
97 |
|
my(@data); |
98 |
< |
push @data, "LINE2:$1-$2:kbytes#0000FF:total size"; |
99 |
< |
push @data, "LINE2:$1-$2:used#00FF00:used"; |
98 |
> |
push @data, "LINE2:$1-$2:kbytes:kbytes#0000FF:total size"; |
99 |
> |
push @data, "LINE2:$1-$2:used:used#00FF00:used"; |
100 |
|
my($type) = $1; |
101 |
|
my($name) = $2; |
102 |
|
my($nicename) = $2; |
111 |
|
my($baserrd) = $1; |
112 |
|
my($i) = 0; |
113 |
|
while( -f "$rrddir/$machine/$baserrd\_$i.rrd" ) { |
114 |
< |
push @data, "LINE2:$baserrd\_$i:size" . &get_colour($i) . ":queue$i size "; |
114 |
> |
push @data, "LINE2:$baserrd\_$i:size:size$i" . &get_colour($i) . ":queue$i size "; |
115 |
|
++$i; |
116 |
|
} |
117 |
< |
push @data, "LINE2:$baserrd\_0:total#FF0000:packets/sec - currently"; |
118 |
< |
push @rawdata, "GPRINT:total:LAST:\"%lf %spackets/sec\""; |
117 |
> |
push @data, "LINE2:$baserrd\_0:total:total#FF0000:packets/sec - currently"; |
118 |
> |
push @rawdata, "GPRINT:total:LAST:%lf %spackets/sec"; |
119 |
|
my($comment); |
120 |
|
if(-f "$rrddir/$machine/$baserrd.def") { |
121 |
|
open(DEF, "$rrddir/$machine/$baserrd.def"); |
138 |
|
# $title = the title for the graph |
139 |
|
# (eg. kernow CPU usage) |
140 |
|
# $dataref = a reference to an array containing information for the graph |
141 |
< |
# elements of format: "gtype:rrdname:name#colour:comment with spaces" |
141 |
> |
# elements of format: "gtype:rrdname:dsname:name#colour:comment with spaces" |
142 |
|
# $rawcmdref = a reference to an array containing raw rrd commands |
143 |
|
# elements a single command each, no spaces |
144 |
|
# |
145 |
+ |
|
146 |
|
sub makegraph() { |
147 |
|
my($machine, $type, $title, $dataref, $rawcmdref) = @_; |
148 |
|
# pass in these arrays by reference |
155 |
|
} |
156 |
|
my(@rrdcmd); |
157 |
|
foreach my $dataitem (@data) { |
158 |
< |
# dataitem should be: "gtype:rrdname:name#colour:comment with spaces" |
159 |
< |
if($dataitem =~ /^(\S+):(\S+):(\S+)#(.{6}):(.*)$/) { |
160 |
< |
push @rrdcmd, "DEF:$3=$rrddir/$machine/$2.rrd:$3:MAX"; |
161 |
< |
push @rrdcmd, "$1:$3#$4:$5"; |
158 |
> |
# dataitem should be: "gtype:rrdname:dsname:name#colour:comment with spaces" |
159 |
> |
if($dataitem =~ /^(\S+):(\S+):(\S+):(\S+)#(.{6}):(.*)$/) { |
160 |
> |
push @rrdcmd, "DEF:$4=$rrddir/$machine/$2.rrd:$3:MAX"; |
161 |
> |
push @rrdcmd, "$1:$4#$5:$6"; |
162 |
|
} |
163 |
|
} |
164 |
|
push @rrdcmd, "--title=$title"; |
168 |
|
push @rrdcmd, @rawcmd; |
169 |
|
RRDs::graph ("$imgdir/$machine/$type-3h.png", "--start=-10800", @rrdcmd); |
170 |
|
my($err_3h) = RRDs::error; |
171 |
< |
print STDERR "Error generating 3h graph for $machine\_$type: $err_3h\n" if $err_3h; |
171 |
> |
print STDERR "Error generating 3h graph for $machine/$type: $err_3h\n" if $err_3h; |
172 |
|
RRDs::graph ("$imgdir/$machine/$type-1d.png", "--start=-86400", @rrdcmd); |
173 |
|
my($err_1d) = RRDs::error; |
174 |
< |
print STDERR "Error generating 1d graph for $machine\_$type: $err_1d\n" if $err_1d; |
174 |
> |
print STDERR "Error generating 1d graph for $machine/$type: $err_1d\n" if $err_1d; |
175 |
|
RRDs::graph ("$imgdir/$machine/$type-1w.png", "--start=-604800", @rrdcmd); |
176 |
|
my($err_1w) = RRDs::error; |
177 |
< |
print STDERR "Error generating 1w graph for $machine\_$type: $err_1w\n" if $err_1w; |
177 |
> |
print STDERR "Error generating 1w graph for $machine/$type: $err_1w\n" if $err_1w; |
178 |
|
RRDs::graph ("$imgdir/$machine/$type-1m.png", "--start=-2678400", @rrdcmd); |
179 |
|
my($err_1m) = RRDs::error; |
180 |
< |
print STDERR "Error generating 1m graph for $machine\_$type: $err_1m\n" if $err_1m; |
180 |
> |
print STDERR "Error generating 1m graph for $machine/$type: $err_1m\n" if $err_1m; |
181 |
|
return; |
182 |
|
} |
183 |
|
|