ltsdb/clients/record_postgresql_version

37 lines
886 B
Plaintext
Raw Permalink Normal View History

2024-02-06 11:45:21 +01:00
#!/usr/bin/python3
import re
import subprocess
import time
import ltsdb_record
p = subprocess.run(["psql", "-c", "select version()", "-A", "-t", "-X", "-q",],
stdout=subprocess.PIPE, universal_newlines=True)
# This works only for PostgreSQL 10.x and above. I don't expect to encounter
# older versions any more.
m = re.match(r"^PostgreSQL (\d+).(\d+) ", p.stdout)
if m:
version = int(m.group(1)) + int(m.group(2)) / 100
report0 = []
report0.append({ "measure": "postgresql_version", "unit": "version", "value":
version})
now = time.time()
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)