From 125dd443c1abf5f17a2f30bdbdf10294eb419563 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Sat, 14 Jan 2023 19:20:57 +0100 Subject: [PATCH] Record reboot overdue time --- clients/record_reboot_overdue | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 clients/record_reboot_overdue diff --git a/clients/record_reboot_overdue b/clients/record_reboot_overdue new file mode 100755 index 0000000..e828984 --- /dev/null +++ b/clients/record_reboot_overdue @@ -0,0 +1,43 @@ +#!/usr/bin/python3 + +import time +import glob +import os.path + +import ltsdb_record + +now = time.time() +with open("/proc/uptime") as fh: + ln = fh.readline() + uptime = float(ln.split()[0]) +last_reboot = now - uptime + +last_mtime = 0 +for p in glob.glob("/boot/**/*", recursive=True): + mtime = os.path.getmtime(p) + if mtime > last_mtime: + last_mtime = mtime + +if last_mtime > last_reboot: + overdue = now - last_mtime +else: + overdue = 0 + +report0 = [] +report0.append({ "measure": "reboot_overdue", "unit": "s", "value": overdue}) +report = [ + { + "description": { + "hostname": ltsdb_record.node, + "measure": r["measure"], + "unit": r["unit"] + }, + "data": [ + [now, r["value"]] + ] + } + for r in report0 +] + +success = ltsdb_record.record_observations(report) +exit(1 - success)