-
Notifications
You must be signed in to change notification settings - Fork 189
/
ipmitool
executable file
·105 lines (89 loc) · 2.02 KB
/
ipmitool
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/awk -f
#
# 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_celsius"] = "Temperature";
help["volts"] = "Voltage";
help["amps"] = "Current";
help["power_watts"] = "Power";
help["speed_rpm"] = "Fan";
help["percent"] = "Device";
help["status"] = "Chassis status";
temperature_celsius["metric_count"] = 0;
volts["metric_count"] = 0;
amps["metric_count"] = 0;
power_watts["metric_count"] = 0;
speed_rpm["metric_count"] = 0;
percent["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_celsius[$1] = $2;
temperature_celsius["metric_count"]++;
}
$3 ~ /Volts/ {
volts[$1] = $2;
volts["metric_count"]++;
}
$3 ~ /Amps/ {
amps[$1] = $2;
amps["metric_count"]++;
}
$3 ~ /Watts/ {
power_watts[$1] = $2;
power_watts["metric_count"]++;
}
$3 ~ /RPM/ {
speed_rpm[$1] = $2;
speed_rpm["metric_count"]++;
}
$3 ~ /percent/ {
percent[$1] = $2;
percent["metric_count"]++;
}
$3 ~ /discrete/ {
status[$1] = sprintf("%d", substr($2,3,2));
status["metric_count"]++;
}
END {
export(temperature_celsius, "temperature_celsius");
export(volts, "volts");
export(amps, "amps");
export(power_watts, "power_watts");
export(speed_rpm, "speed_rpm");
export(percent, "percent");
export(status, "status");
}