41 lines
904 B
Plaintext
41 lines
904 B
Plaintext
|
#!/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)
|
||
|
|