diff --git a/clients/record_postgresql_version b/clients/record_postgresql_version new file mode 100755 index 0000000..4ad2be5 --- /dev/null +++ b/clients/record_postgresql_version @@ -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)