From 1527789f760e2ca9f20cee65d375681b44b444a0 Mon Sep 17 00:00:00 2001 From: Derek Marcotte Date: Fri, 1 Dec 2017 06:58:39 -0500 Subject: [PATCH] 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. --- text_collector_examples/ipmitool | 89 ++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 text_collector_examples/ipmitool diff --git a/text_collector_examples/ipmitool b/text_collector_examples/ipmitool new file mode 100755 index 00000000..bb38c910 --- /dev/null +++ b/text_collector_examples/ipmitool @@ -0,0 +1,89 @@ +#!/usr/bin/awk -nf + +# +# Converts output of `ipmitool sensor` to prometheus format. +# +# With GNU awk: +# ipmitool sensor | ./ipmitool > ipmitool.prom +# +# With BSD awk: +# ipmitool sensor | awk -f ./ipmitool > ipmitool.prom +# + +function export(values, name) { + if (values["metric_count"] < 1) { + return + } + delete values["metric_count"] + + printf("# HELP %s%s %s sensor reading from ipmitool\n", namespace, name, help[name]); + printf("# TYPE %s%s gauge\n", namespace, name); + for (sensor in values) { + printf("%s%s{sensor=\"%s\"} %f\n", namespace, name, sensor, values[sensor]); + } +} + +# Fields are Bar separated, with space padding. +BEGIN { + FS = "[ ]*[|][ ]*"; + namespace = "node_ipmi_"; + + # Friendly description of the type of sensor for HELP. + help["temperature_celcius"] = "Temperature"; + help["volts"] = "Voltage"; + help["power_watts"] = "Power"; + help["speed_rpm"] = "Fan"; + help["status"] = "Chassis status"; + + temperature_celcius["metric_count"] = 0; + volts["metric_count"] = 0; + power_watts["metric_count"] = 0; + speed_rpm["metric_count"] = 0; + status["metric_count"] = 0; +} + +# Not a valid line. +{ + if (NF < 3) { + next + } +} + +# $2 is value field. +$2 ~ /na/ { + next +} + +# $3 is type field. +$3 ~ /degrees C/ { + temperature_celcius[$1] = $2; + temperature_celcius["metric_count"]++; +} + +$3 ~ /Volts/ { + volts[$1] = $2; + volts["metric_count"]++; +} + +$3 ~ /Watts/ { + power_watts[$1] = $2; + power_watts["metric_count"]++; +} + +$3 ~ /RPM/ { + speed_rpm[$1] = $2; + speed_rpm["metric_count"]++; +} + +$3 ~ /discrete/ { + status[$1] = $2; + status["metric_count"]++; +} + +END { + export(temperature_celcius, "temperature_celcius"); + export(volts, "volts"); + export(power_watts, "power_watts"); + export(speed_rpm, "speed_rpm"); + export(status, "status"); +}