postgres.chart.py: Support new WAL directory name.
In versions <= 10 the WAL directory was called 'pg_xlog', and from 10 onwards has been renamed to 'pg_wal'. Raised in #2865
Facetoe committed
Oct 24, 2017 at 13:25 UTC
21c947a8917b21828ab1da7cebca1ba5098beb60
1 file changed
+16
-3
python.d/postgres.chart.py
+16
-3
@@ -62,7 +62,7 @@ SELECT
62
CAST(COALESCE(SUM(CAST(archive_file ~ $r$\.ready$$r$ as INT)), 0) AS INT) AS ready_count,
63
CAST(COALESCE(SUM(CAST(archive_file ~ $r$\.done$$r$ AS INT)), 0) AS INT) AS done_count
64
FROM
65
- pg_catalog.pg_ls_dir('pg_xlog/archive_status') AS archive_files (archive_file);
65
+ pg_catalog.pg_ls_dir('{}/archive_status') AS archive_files (archive_file);
66
""",
67
BACKENDS="""
68
SELECT
@@ -125,7 +125,11 @@ AND NOT datname ~* '^template\d+';
125
""",
126
IF_SUPERUSER="""
127
SELECT current_setting('is_superuser') = 'on' AS is_superuser;
128
- """)
128
+ """,
129
+ DETECT_SERVER_VERSION="""
130
+SHOW server_version_num;
131
+ """
132
+)
133
134
135
QUERY_STATS = {
@@ -229,6 +233,7 @@ class Service(SimpleService):
233
self.database_poll = configuration.pop('database_poll', None)
234
self.configuration = configuration
235
self.connection = False
236
+ self.server_version = None
237
self.data = dict()
238
self.locks_zeroed = dict()
239
self.databases = list()
@@ -264,6 +269,7 @@ class Service(SimpleService):
269
cursor = self.connection.cursor()
270
self.databases = discover_databases_(cursor, QUERIES['FIND_DATABASES'])
271
is_superuser = check_if_superuser_(cursor, QUERIES['IF_SUPERUSER'])
272
+ self.server_version = detect_server_version(cursor, QUERIES['DETECT_SERVER_VERSION'])
273
cursor.close()
274
275
if (self.database_poll and isinstance(self.database_poll, str)):
@@ -284,7 +290,11 @@ class Service(SimpleService):
290
self.queries[QUERIES['TABLE_STATS']] = METRICS['TABLE_STATS']
291
if is_superuser:
292
self.queries[QUERIES['BGWRITER']] = METRICS['BGWRITER']
287
- self.queries[QUERIES['ARCHIVE']] = METRICS['ARCHIVE']
293
+ if self.server_version >= 100000:
294
+ wal_dir_name = 'pg_wal'
295
+ else:
296
+ wal_dir_name = 'pg_xlog'
297
+ self.queries[QUERIES['ARCHIVE'].format(wal_dir_name)] = METRICS['ARCHIVE']
298
299
def create_dynamic_charts_(self):
300
@@ -340,6 +350,9 @@ def check_if_superuser_(cursor, query):
350
cursor.execute(query)
351
return cursor.fetchone()[0]
352
353
+def detect_server_version(cursor, query):
354
+ cursor.execute(query)
355
+ return int(cursor.fetchone()[0])
356
357
def populate_lock_types(databases):
358
result = dict()