Compare commits

...

2 Commits

Author SHA1 Message Date
Peter J. Holzer 1a7003fef2 Record raw smart vendor attributes 2023-08-19 13:13:09 +02:00
Peter J. Holzer 3f21122769 Use random time stamps
Don't remember what I wanted to test there ...
2023-08-18 21:14:15 +02:00
2 changed files with 66 additions and 4 deletions

60
clients/record_smart Executable file
View File

@ -0,0 +1,60 @@
#!/usr/bin/python3
import argparse
import re
import subprocess
import time
import ltsdb_record
ap = argparse.ArgumentParser()
ap.add_argument("device")
args = ap.parse_args()
p = subprocess.run(["/usr/sbin/smartctl", "-A", args.device],
stdout=subprocess.PIPE, universal_newlines=True)
report0 = []
state = 0
for ln in p.stdout.splitlines():
if state == 0 and ln.startswith("ID# ATTRIBUTE_NAME"):
state = 1
elif state == 1 and ln == "":
state = 2
elif state == 1:
(id, attribute_name, flag, value, worst, thresh, type, updated, when_failed, raw_value) = ln.split()
if "_Ct" in attribute_name or "_Count" in attribute_name or "_Cnt" in attribute_name:
unit = "count"
elif "_Hours" in attribute_name:
unit = "hours"
elif "Total_LBAs_Written" in attribute_name:
unit = "blocks"
elif "Temperature_Cel" in attribute_name:
unit = "°C"
else:
unit = "unknown"
report0.append(
{
"measure": "smart_" + attribute_name.lower(),
"unit": unit,
"value": int(raw_value),
})
now = time.time()
report = [
{
"description": {
"hostname": ltsdb_record.node,
"device": args.device,
"measure": r["measure"],
"unit": r["unit"],
},
"data": [
[now, r["value"]]
]
}
for r in report0
]
success = ltsdb_record.record_observations(report)
exit(1 - success)

View File

@ -1,20 +1,22 @@
#!/usr/bin/python3
import time
import random
from ltsdb_json import LTS
ts1 = LTS({"hostname": "rorschach.hjp.at", "measure": "uptime"})
ts1.add(1661026122, 4)
ts1.add(time.time(), 4 + random.random())
ts1.save()
ts1 = LTS({"hostname": "rorschach.hjp.at", "website": "i12e.hjp.at", "measure": "rtt"})
ts1.add(1661026122, 0.06)
ts1.add(time.time(), 0.06)
ts1.save()
ts1 = LTS({"hostname": "rorschach.hjp.at", "measure": "uptime"})
ts1.add(1661026361, 5)
ts1.add(time.time() + 240, 5 + random.random())
ts1.save()
ts1 = LTS({"hostname": "charly.wsr.ac.at", "website": "www.wifo.ac.at", "measure": "rtt"})
ts1.add(1661026122, 0.347)
ts1.add(time.time(), 0.347)
ts1.save()