summaryrefslogtreecommitdiffstats
path: root/utils/prometheus-node-exporter-ucode/files/extra/watchdog.uc
blob: 0c3e6db4f5f574ded0a6286dcc53183297222c4a (plain)
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
// based loosely on https://github.com/prometheus/node_exporter/blob/master/collector/watchdog.go

const SC_WATCHDOG_PATH = "/sys/class/watchdog/";

const metrics = {
	bootstatus: gauge("node_watchdog_bootstatus",
		"Value of /sys/class/watchdog/<watchdog>/bootstatus"),
	fw_version: gauge("node_watchdog_fw_version",
		"Value of /sys/class/watchdog/<watchdog>/fw_version"),
	nowayout: gauge("node_watchdog_nowayout",
		"Value of /sys/class/watchdog/<watchdog>/nowayout"),
	timeleft: gauge("node_watchdog_timeleft_seconds",
		"Value of /sys/class/watchdog/<watchdog>/timeleft"),
	timeout: gauge("node_watchdog_timeout_seconds",
		"Value of /sys/class/watchdog/<watchdog>/timeout"),
	pretimeout: gauge("node_watchdog_pretimeout_seconds",
		"Value of /sys/class/watchdog/<watchdog>/pretimeout"),
	access_cs0: gauge("node_watchdog_access_cs0",
		"Value of /sys/class/watchdog/<watchdog>/access_cs0"),
};

const info_gauge = gauge("node_watchdog_info",
	"Info of /sys/class/watchdog/<watchdog>");
const avail_gauge = gauge("node_watchdog_available",
	"Info of /sys/class/watchdog/<watchdog>/pretimeout_available_governors");


const wd_paths = [];

for (let wd_path in fs.lsdir(SC_WATCHDOG_PATH, "watchdog*")) {
	push(wd_paths, wd_path);
}

// watchdog metrics
for (let m in metrics) {
	for (let wd_path in wd_paths)
		if(fs.access(`${SC_WATCHDOG_PATH}/${wd_path}/${m}`))
			metrics[m]({ name: `${wd_path}` }, oneline(`${SC_WATCHDOG_PATH}/${wd_path}/${m}`));
}

// watchdog summary info properties
for (let wd_path in wd_paths) {
	const path = `${SC_WATCHDOG_PATH}/${wd_path}`;
	const opts = oneline(`${path}/options`);
	const iden = oneline(`${path}/identity`);
	const stat = oneline(`${path}/state`);
	const stus = oneline(`${path}/status`);
	const prtg = oneline(`${path}/pretimeout_governor`);

	const labels = { name: wd_path };

	if (opts) labels.options = opts;
	if (iden) labels.identity = iden;
	if (stat) labels.state = stat;
	if (stus) labels.status = stus;
	if (prtg) labels.pretimeout_governor = prtg;

	info_gauge(labels, 1);
}

for (let wd_path in wd_paths) {
	if (!fs.access(`${SC_WATCHDOG_PATH}/${wd_path}/pretimeout_available_governors`))
		continue;

	const pa = split(oneline(`${SC_WATCHDOG_PATH}/${wd_path}/pretimeout_available_governors`), ' ');
	for (let gov in pa) {
		if (!gov) continue;
		avail_gauge({ available: gov, device: `${wd_path}` }, 1)
	}
}