Compare commits
2 Commits
206be6a8fa
...
1a7003fef2
Author | SHA1 | Date |
---|---|---|
Peter J. Holzer | 1a7003fef2 | |
Peter J. Holzer | 3f21122769 |
|
@ -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)
|
||||
|
10
ltsdb_test
10
ltsdb_test
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue