From d3ac6703c69de146609b94fe23c5ae456b3de644 Mon Sep 17 00:00:00 2001 From: "Peter J. Holzer" Date: Tue, 6 Feb 2024 11:45:21 +0100 Subject: [PATCH] Record postgresql version --- clients/record_postgresql_version | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 clients/record_postgresql_version 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)