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
|
// modelled after: https://github.com/prometheus/node_exporter/blob/master/collector/thermal_zone_linux.go
// See also: https://docs.kernel.org/driver-api/thermal/sysfs-api.html
// thermal collector
const thermal_devs = [];
for (let idx = 0; ; idx++) {
const devPath = `/sys/class/thermal/thermal_zone${idx}`;
const typ = oneline(devPath + "/type");
if (!typ) break;
const policy = oneline(devPath + "/policy");
if (!policy) break;
const temp = oneline(devPath + "/temp");
if (!temp) break;
push(thermal_devs, {
idx,
typ,
policy,
temp,
mode: oneline(devPath + "/mode"),
passive: oneline(devPath + "/passive"),
});
}
if (length(thermal_devs) > 0) {
const temp_metric = gauge("node_thermal_zone_temp", "Zone temperature in Celsius");
for (let d in thermal_devs) {
const labels = { zone: `${d.idx}`, type: d.typ, policy: d.policy };
if (d.mode) labels.mode = d.mode;
if (d.passive) labels.passive = d.passive;
temp_metric(labels, d.temp / 1000.00);
}
}
// cooling collector
const cooling_devs = [];
for (let idx = 0; ; idx++) {
const devPath = `/sys/class/thermal/cooling_device${idx}`;
const typ = oneline(devPath + "/type");
if (!typ) break;
push(cooling_devs, {
idx,
typ,
cur: oneline(devPath + "/cur_state"),
max: oneline(devPath + "/max_state"),
});
}
if (length(cooling_devs) > 0) {
const cur_throttle = gauge("node_cooling_device_cur_state", "Current throttle state of the cooling device");
for (let d in cooling_devs) {
const labels = { name: `${d.idx}`, type: d.typ };
cur_throttle(labels, d.cur);
}
const max_throttle = gauge("node_cooling_device_max_state", "Maximum throttle state of the cooling device");
for (let d in cooling_devs) {
const labels = { name: `${d.idx}`, type: d.typ };
max_throttle(labels, d.max);
}
}
|