Record meminfo

This commit is contained in:
Peter J. Holzer 2023-01-07 13:45:03 +01:00 committed by Peter J. Holzer
parent ed3f7872e9
commit 52a5f60389
1 changed files with 40 additions and 0 deletions

40
clients/record_meminfo Normal file
View File

@ -0,0 +1,40 @@
#!/usr/bin/python3
import time
import re
import ltsdb_record
now = time.time()
report0 = []
with open("/proc/meminfo") as mfh:
for ln in mfh:
m = re.match(r"^(?P<measure>.*?): *(?P<value>[0-9]*)( (?P<unit>.*))?", ln)
measure = m.group("measure")
value = int(m.group("value"))
unit = m.group("unit")
if unit is None and "Pages" in measure:
unit = "pages"
if unit == "kB":
value *= 1024
unit = "bytes"
report0.append({ "measure": "meminfo." + measure, "unit": unit, "value": value })
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)