Record postgresql version
This commit is contained in:
parent
70b68108c7
commit
d3ac6703c6
|
@ -0,0 +1,36 @@
|
||||||
|
#!/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)
|
Loading…
Reference in New Issue