Skip to content

Commit d3c5bdd

Browse files
committed
Completed Disk Utilization graph
1 parent 7800681 commit d3c5bdd

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

RRDDiskIO.php

+82-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,44 @@ private function collectForDevice($device)
128128
}
129129
}
130130

131-
// var_dump($collection);
131+
$update = end($collection);
132+
133+
$keys = [];
134+
$values = [];
135+
$mapping = [
136+
'rrqm/s' => 'RRMerge',
137+
'wrqm/s' => 'WRMerge',
138+
'r/s' => 'RReq',
139+
'w/s' => 'WReq',
140+
'rkB/s' => 'RByte',
141+
'wkB/s' => 'WByte',
142+
'avgrq-sz' => 'RSize',
143+
'avgqu-sz' => 'QLength',
144+
'await' => 'WTime',
145+
'r_await' => 'RWTime',
146+
'w_await' => 'WWTime',
147+
'svctm' => 'STime',
148+
'%util' => 'Util'
149+
];
150+
151+
foreach ($mapping as $from => $to){
152+
if (isset($update[$from])) {
153+
array_push($keys, $to);
154+
if (in_array($from,['rkB/s', 'wkB/s'])) {
155+
array_push($values, (float) ($update[$from] * 1024)); // We want these at Bytes not KB
156+
continue;
157+
}
158+
array_push($values, (float) $update[$from]);
159+
}
160+
}
161+
162+
if (!rrd_update($this->rrdFilePath[$device], [
163+
"-t",
164+
implode(':', $keys),
165+
'N:' . implode(':', $values)
166+
])){
167+
$this->fail(rrd_error());
168+
}
132169
}
133170

134171
public function collect()
@@ -143,6 +180,50 @@ public function graph($period = 'day', $graphPath = __DIR__)
143180
if (!file_exists($graphPath)) {
144181
$this->fail("The path [$graphPath] does not exist or is not readable.\n");
145182
}
183+
184+
$colours = [
185+
'#2C3E50',
186+
'#0EAD9A',
187+
'#F8C82D',
188+
'#E84B3A',
189+
'#832D51',
190+
'#74525F',
191+
'#404148',
192+
'#6EC198',
193+
'#27AE60'
194+
];
195+
196+
$config = [
197+
"-s","-1$period",
198+
"-t Disk Utilization in the last $period",
199+
"-z",
200+
"--lazy",
201+
"-h", "150", "-w", "700",
202+
"-l 0",
203+
"-a", "PNG",
204+
"-v Utilization %"
205+
];
206+
207+
foreach ($this->devices as $device) {
208+
array_push($config, "DEF:{$device}Avg={$this->rrdFilePath[$device]}:Util:AVERAGE");
209+
array_push($config, "DEF:{$device}Max={$this->rrdFilePath[$device]}:Util:MAX");
210+
}
211+
212+
foreach ($this->devices as $device) {
213+
$colour = array_pop($colours);
214+
$config = array_merge($config, [
215+
"LINE2:{$device}Avg{$colour}:" . $device . ' Utilization',
216+
"GPRINT:{$device}Avg:LAST: Current\\: %5.2lf%%",
217+
"GPRINT:{$device}Avg:MIN: Min\\: %5.2lf%%",
218+
"GPRINT:{$device}Max:MAX: Max\\: %5.2lf%%",
219+
"GPRINT:{$device}Avg:AVERAGE: Avg\\: %5.2lf%%\\n",
220+
]);
221+
}
222+
223+
if(!rrd_graph($graphPath . '/disk_usage_' . $period . '.png', $config)) {
224+
$this->fail('Error writing connections graph for period '. $period .' ['. rrd_error() .']');
225+
}
226+
146227
}
147228
}
148229

0 commit comments

Comments
 (0)