This repository has been archived by the owner on May 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 126
/
device-metrics.php
80 lines (66 loc) · 2.45 KB
/
device-metrics.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
// adopted from http://nousefor.net/79/2012/04/php/ganglia-iostat-disk-metrics/
// {{ ansible_managed }}
exec('iostat -d -x -k 10 2', $out);
$out = array_slice($out, ceil(count($out) / 2));
$header = array();
$data = array();
foreach ($out as $line) {
$line = preg_replace('/\s+/', ' ', $line);
$cols = explode(" ", $line);
if ($cols[0] == "Device:") {
$header = $cols;
} elseif (count($header) > 0 && count($cols) > 1) {
$data[] = $cols;
}
}
$titles = array();
$titles['rrqm_s'] = 'Merged Reads';
$titles['wrqm_s'] = 'Merged Writes';
$titles['r_s'] = 'Completed Reads';
$titles['w_s'] = 'Completed Writes';
$titles['rkB_s'] = 'Data Read';
$titles['wkB_s'] = 'Data Written';
$titles['avgrq-sz'] = 'Average Req Size';
$titles['avgqu-sz'] = 'Average Req Queue Length';
$titles['await'] = 'Await';
$titles['r_await'] = 'Average Read Await';
$titles['w_await'] = 'Average Write Await';
$titles['util'] = 'CPU Time';
$units = array();
$units['rrqm_s'] = 'queued reqs/sec';
$units['wrqm_s'] = 'queued reqs/sec';
$units['r_s'] = 'reqs/sec';
$units['w_s'] = 'reqs/sec';
$units['rkB_s'] = 'kB/sec';
$units['wkB_s'] = 'kB/sec';
$units['avgrq-sz'] = 'sectors';
$units['avgqu-sz'] = 'sectors';
$units['await'] = 'ms';
$units['r_await'] = 'ms';
$units['w_await'] = 'ms';
$units['util'] = '%';
for ($col = 0; $col < count($header); $col++) {
$header[$col] = str_replace("/", "_", $header[$col]);
$header[$col] = str_replace("%", "", $header[$col]);
}
for ($row = 0; $row < count($data); $row++) {
$namePrefix = "dev_" . $data[$row][0] . "-";
$titlePrefix = "dev/" . $data[$row][0] . " ";
for ($col = 1; $col < count($header); $col++) {
if ($header[$col] == 'svctm')
continue;
if ($header[$col] == '')
continue;
if (!isset($data[$row][$col]))
continue;
$name = $namePrefix . $header[$col];
$title = $titlePrefix . $titles[$header[$col]];
$value = $data[$row][$col];
$unit = $units[$header[$col]];
exec('gmetric -c /etc/ganglia/gmond.conf --name="' . $name . '" --title="' . $title . '" --value="' . $value . '" --type="float" --units="' . $unit . '" -g disk');
}
exec('/usr/sbin/hddtemp -q -n /dev/' . $data[$row][0], $temperature);
exec('gmetric -c /etc/ganglia/gmond.conf --name="' . $namePrefix . 'temp" --title="' . $titlePrefix . 'Temperature" --value="' . $temperature[0] . '" --type="int8" --units="degrees C" -g disk');
}
?>