diff options
author | Derek Marcotte <derekmarcotte@users.noreply.github.com> | 2017-12-01 06:58:39 -0500 |
---|---|---|
committer | Ben Kochie <superq@gmail.com> | 2017-12-01 12:58:39 +0100 |
commit | 1527789f760e2ca9f20cee65d375681b44b444a0 (patch) | |
tree | cad3c385adbd4486684dfc6e78f5a2b1ae66bee8 /text_collector_examples | |
parent | 2a8053754728821676e5a072bd0fb4ce051a51cd (diff) | |
download | prometheus_node_collector-1527789f760e2ca9f20cee65d375681b44b444a0.tar.bz2 prometheus_node_collector-1527789f760e2ca9f20cee65d375681b44b444a0.tar.xz prometheus_node_collector-1527789f760e2ca9f20cee65d375681b44b444a0.zip |
Added text collector conversion for ipmitool output. (#746)
* Added text collector conversion for ipmitool output.
* Sort metrics before exporting, add namespace.
* Added HELP string, tidy up a bit.
* Make status a gauge.
Diffstat (limited to 'text_collector_examples')
-rwxr-xr-x | text_collector_examples/ipmitool | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/text_collector_examples/ipmitool b/text_collector_examples/ipmitool new file mode 100755 index 0000000..bb38c91 --- /dev/null +++ b/text_collector_examples/ipmitool | |||
@@ -0,0 +1,89 @@ | |||
1 | #!/usr/bin/awk -nf | ||
2 | |||
3 | # | ||
4 | # Converts output of `ipmitool sensor` to prometheus format. | ||
5 | # | ||
6 | # With GNU awk: | ||
7 | # ipmitool sensor | ./ipmitool > ipmitool.prom | ||
8 | # | ||
9 | # With BSD awk: | ||
10 | # ipmitool sensor | awk -f ./ipmitool > ipmitool.prom | ||
11 | # | ||
12 | |||
13 | function export(values, name) { | ||
14 | if (values["metric_count"] < 1) { | ||
15 | return | ||
16 | } | ||
17 | delete values["metric_count"] | ||
18 | |||
19 | printf("# HELP %s%s %s sensor reading from ipmitool\n", namespace, name, help[name]); | ||
20 | printf("# TYPE %s%s gauge\n", namespace, name); | ||
21 | for (sensor in values) { | ||
22 | printf("%s%s{sensor=\"%s\"} %f\n", namespace, name, sensor, values[sensor]); | ||
23 | } | ||
24 | } | ||
25 | |||
26 | # Fields are Bar separated, with space padding. | ||
27 | BEGIN { | ||
28 | FS = "[ ]*[|][ ]*"; | ||
29 | namespace = "node_ipmi_"; | ||
30 | |||
31 | # Friendly description of the type of sensor for HELP. | ||
32 | help["temperature_celcius"] = "Temperature"; | ||
33 | help["volts"] = "Voltage"; | ||
34 | help["power_watts"] = "Power"; | ||
35 | help["speed_rpm"] = "Fan"; | ||
36 | help["status"] = "Chassis status"; | ||
37 | |||
38 | temperature_celcius["metric_count"] = 0; | ||
39 | volts["metric_count"] = 0; | ||
40 | power_watts["metric_count"] = 0; | ||
41 | speed_rpm["metric_count"] = 0; | ||
42 | status["metric_count"] = 0; | ||
43 | } | ||
44 | |||
45 | # Not a valid line. | ||
46 | { | ||
47 | if (NF < 3) { | ||
48 | next | ||
49 | } | ||
50 | } | ||
51 | |||
52 | # $2 is value field. | ||
53 | $2 ~ /na/ { | ||
54 | next | ||
55 | } | ||
56 | |||
57 | # $3 is type field. | ||
58 | $3 ~ /degrees C/ { | ||
59 | temperature_celcius[$1] = $2; | ||
60 | temperature_celcius["metric_count"]++; | ||
61 | } | ||
62 | |||
63 | $3 ~ /Volts/ { | ||
64 | volts[$1] = $2; | ||
65 | volts["metric_count"]++; | ||
66 | } | ||
67 | |||
68 | $3 ~ /Watts/ { | ||
69 | power_watts[$1] = $2; | ||
70 | power_watts["metric_count"]++; | ||
71 | } | ||
72 | |||
73 | $3 ~ /RPM/ { | ||
74 | speed_rpm[$1] = $2; | ||
75 | speed_rpm["metric_count"]++; | ||
76 | } | ||
77 | |||
78 | $3 ~ /discrete/ { | ||
79 | status[$1] = $2; | ||
80 | status["metric_count"]++; | ||
81 | } | ||
82 | |||
83 | END { | ||
84 | export(temperature_celcius, "temperature_celcius"); | ||
85 | export(volts, "volts"); | ||
86 | export(power_watts, "power_watts"); | ||
87 | export(speed_rpm, "speed_rpm"); | ||
88 | export(status, "status"); | ||
89 | } | ||