Skip to content

Commit a1b0f51

Browse files
committed
fix: updates for postgres 17
- updated checkpoint plugin: added support for new view pg_stat_checkpointer - updated bgwriter plugin: consider updated view pg_stat_bgwriter in postgres 17
1 parent ea9ceb4 commit a1b0f51

File tree

4 files changed

+166
-73
lines changed

4 files changed

+166
-73
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ Supported platforms:
1818
- Windows;
1919

2020
Supported Zabbix server versions: 4.0.44 - 6.4.13
21-
Supported PostgreSQL versions: 12 - 16
21+
22+
Supported PostgreSQL versions: 12 - 17
2223
***
2324

2425
***Table of Contents***

documentation/metrics.md

+38-4
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ Default config:
19971997
</tr>
19981998
<tr>
19991999
<th>Supported Version</th>
2000-
<td>9.5+</td>
2000+
<td>9.5 - 16</td>
20012001
</tr>
20022002
</table>
20032003

@@ -2030,7 +2030,7 @@ Default config:
20302030
</tr>
20312031
<tr>
20322032
<th>Supported Version</th>
2033-
<td>9.5+</td>
2033+
<td>9.5 - 16</td>
20342034
</tr>
20352035
</table>
20362036

@@ -2096,7 +2096,7 @@ Default config:
20962096
</tr>
20972097
<tr>
20982098
<th>Supported Version</th>
2099-
<td>9.5+</td>
2099+
<td>9.5 - 16</td>
21002100
</tr>
21012101
</table>
21022102

@@ -2208,7 +2208,7 @@ Default config:
22082208

22092209
### Items
22102210

2211-
*Checkpoints metrics* use information from `pg_stat_bgwriter`.
2211+
*Checkpoints metrics* use information from `pg_stat_bgwriter`. Starting from Postgres 17 this information is pulled from view `pg_stat_checkpointer`.
22122212

22132213
- **Checkpoints Sync Time**
22142214

@@ -2341,6 +2341,40 @@ Default config:
23412341

23422342
*Requested Checkpoints* maps `checkpoints_req`.
23432343

2344+
2345+
- **Buffers Written During Checkpoints**
2346+
2347+
Zabbix item:
2348+
<table>
2349+
<tr>
2350+
<th>Name</th>
2351+
<td>PostgreSQL bgwriter: Buffers Written During Checkpoints</td>
2352+
</tr>
2353+
<tr>
2354+
<th>Key</th>
2355+
<td>pgsql.checkpoint[buffers_written]</td>
2356+
</tr>
2357+
<tr>
2358+
<th>Type</th>
2359+
<td>Numeric (float)</td>
2360+
</tr>
2361+
<tr>
2362+
<th>Units</th>
2363+
<td></td>
2364+
</tr>
2365+
<tr>
2366+
<th>Delta</th>
2367+
<td>Simple Change</td>
2368+
</tr>
2369+
<tr>
2370+
<th>Supported Version</th>
2371+
<td>17+</td>
2372+
</tr>
2373+
</table>
2374+
2375+
*Buffers Written During Checkpoints* maps `buffers_written`.
2376+
2377+
23442378
### Graphs
23452379

23462380
<table>

mamonsu/plugins/pgsql/bgwriter.py

+58-34
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,68 @@ class BgWriter(Plugin):
1212
SELECT {0}
1313
FROM pg_catalog.pg_stat_bgwriter;
1414
"""
15-
Items = [
16-
# key, zbx_key, description,
17-
# ('graph name', color, side), units, delta
18-
19-
("buffers_checkpoint", "bgwriter[buffers_checkpoint]",
20-
"Buffers Written During Checkpoints",
21-
("PostgreSQL bgwriter", "006AAE", 1),
22-
Plugin.DELTA.simple_change),
23-
24-
("buffers_clean", "bgwriter[buffers_clean]",
25-
"Buffers Written",
26-
("PostgreSQL bgwriter", "00CC00", 1),
27-
Plugin.DELTA.simple_change),
28-
29-
("maxwritten_clean", "bgwriter[maxwritten_clean]",
30-
"Number of bgwriter Stopped by Max Write Count",
31-
("PostgreSQL bgwriter", "FF5656", 0),
32-
Plugin.DELTA.simple_change),
33-
34-
("buffers_backend", "bgwriter[buffers_backend]",
35-
"Buffers Written Directly by a Backend",
36-
("PostgreSQL bgwriter", "9C8A4E", 1),
37-
Plugin.DELTA.simple_change),
38-
39-
("buffers_backend_fsync", "bgwriter[buffers_backend_fsync]",
40-
"Times a Backend Execute Its Own Fsync",
41-
("PostgreSQL bgwriter", "00CC00", 0),
42-
Plugin.DELTA.simple_change),
43-
44-
("buffers_alloc", "bgwriter[buffers_alloc]",
45-
"Buffers Allocated",
46-
("PostgreSQL bgwriter", "FF5656", 1),
47-
Plugin.DELTA.simple_change)
48-
]
4915

5016
graph_name_buffers = "PostgreSQL bgwriter: Buffers"
5117
graph_name_ws = "PostgreSQL bgwriter: Write/Sync"
5218

19+
def __init__(self, config):
20+
super(BgWriter, self).__init__(config)
21+
if Pooler.server_version_less("17"):
22+
self.Items = [
23+
# key, zbx_key, description,
24+
# ('graph name', color, side), units, delta
25+
26+
("buffers_checkpoint", "bgwriter[buffers_checkpoint]",
27+
"Buffers Written During Checkpoints",
28+
("PostgreSQL bgwriter", "006AAE", 1),
29+
Plugin.DELTA.simple_change),
30+
31+
("buffers_clean", "bgwriter[buffers_clean]",
32+
"Buffers Written",
33+
("PostgreSQL bgwriter", "00CC00", 1),
34+
Plugin.DELTA.simple_change),
35+
36+
("maxwritten_clean", "bgwriter[maxwritten_clean]",
37+
"Number of bgwriter Stopped by Max Write Count",
38+
("PostgreSQL bgwriter", "FF5656", 0),
39+
Plugin.DELTA.simple_change),
40+
41+
("buffers_backend", "bgwriter[buffers_backend]",
42+
"Buffers Written Directly by a Backend",
43+
("PostgreSQL bgwriter", "9C8A4E", 1),
44+
Plugin.DELTA.simple_change),
45+
46+
("buffers_backend_fsync", "bgwriter[buffers_backend_fsync]",
47+
"Times a Backend Execute Its Own Fsync",
48+
("PostgreSQL bgwriter", "00CC00", 0),
49+
Plugin.DELTA.simple_change),
50+
51+
("buffers_alloc", "bgwriter[buffers_alloc]",
52+
"Buffers Allocated",
53+
("PostgreSQL bgwriter", "FF5656", 1),
54+
Plugin.DELTA.simple_change)
55+
]
56+
else:
57+
self.Items = [
58+
# key, zbx_key, description,
59+
# ('graph name', color, side), units, delta
60+
61+
("buffers_clean", "bgwriter[buffers_clean]",
62+
"Buffers Written",
63+
("PostgreSQL bgwriter", "00CC00", 1),
64+
Plugin.DELTA.simple_change),
65+
66+
("maxwritten_clean", "bgwriter[maxwritten_clean]",
67+
"Number of bgwriter Stopped by Max Write Count",
68+
("PostgreSQL bgwriter", "FF5656", 0),
69+
Plugin.DELTA.simple_change),
70+
71+
("buffers_alloc", "bgwriter[buffers_alloc]",
72+
"Buffers Allocated",
73+
("PostgreSQL bgwriter", "FF5656", 1),
74+
Plugin.DELTA.simple_change)
75+
]
76+
5377
def run(self, zbx):
5478
columns = [x[0] for x in self.Items]
5579
result = Pooler.query(self.query.format(", ".join(columns)))

mamonsu/plugins/pgsql/checkpoint.py

+68-34
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,83 @@ class Checkpoint(Plugin):
99
AgentPluginType = "pg"
1010
Interval = 60 * 5
1111

12-
query = """
13-
SELECT {0}
14-
FROM pg_catalog.pg_stat_bgwriter;
15-
""" # for mamonsu and agent
16-
query_interval = """
17-
SELECT {0}*3600
18-
FROM pg_catalog.pg_stat_bgwriter;
19-
""" # for mamonsu and agent checkpoints in hour
2012
key = "pgsql.checkpoint{0}"
2113

2214
# key: (macro, value)
2315
plugin_macros = {
2416
"max_checkpoint_by_wal_in_hour": [("macro", "{$MAX_CHECKPOINT_BY_WAL_IN_HOUR}"), ("value", 12)]
2517
}
2618

27-
Items = [
28-
# key, zbx_key, description,
29-
# ('graph name', color, side), units, delta, factor
30-
31-
("checkpoints_timed", "count_timed",
32-
"by Timeout (in hour)",
33-
("PostgreSQL Checkpoints: Count (in hour)", "00CC00", 0),
34-
Plugin.UNITS.none, Plugin.DELTA.speed_per_second, 60 * 60),
35-
36-
("checkpoints_req", "count_wal",
37-
"by WAL (in hour)",
38-
("PostgreSQL Checkpoints: Count (in hour)", "FF5656", 0),
39-
Plugin.UNITS.none, Plugin.DELTA.speed_per_second, 60 * 60),
40-
41-
("checkpoint_write_time", "write_time",
42-
"Write Time",
43-
("PostgreSQL Checkpoints: Write/Sync", "00CC00", 1),
44-
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1),
45-
46-
("checkpoint_sync_time", "checkpoint_sync_time",
47-
"Sync Time",
48-
("PostgreSQL Checkpoints: Write/Sync", "FF5656", 1),
49-
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1)
50-
]
51-
5219
graph_name_count = "PostgreSQL Checkpoints: Count (in hour)"
5320
graph_name_ws = "PostgreSQL Checkpoints: Write/Sync"
5421

22+
def __init__(self, config):
23+
super(Checkpoint, self).__init__(config)
24+
if Pooler.server_version_less("17"):
25+
self.query = """
26+
SELECT {0}
27+
FROM pg_catalog.pg_stat_bgwriter;
28+
""" # for mamonsu and agent
29+
self.query_interval = """
30+
SELECT {0}*3600
31+
FROM pg_catalog.pg_stat_bgwriter;
32+
""" # for mamonsu and agent checkpoints in hour
33+
self.Items = [
34+
# key, zbx_key, description,
35+
# ('graph name', color, side), units, delta, factor
36+
("checkpoints_timed", "count_timed",
37+
"by Timeout (in hour)",
38+
("PostgreSQL Checkpoints: Count (in hour)", "00CC00", 0),
39+
Plugin.UNITS.none, Plugin.DELTA.speed_per_second, 60 * 60),
40+
41+
("checkpoints_req", "count_wal",
42+
"by WAL (in hour)",
43+
("PostgreSQL Checkpoints: Count (in hour)", "FF5656", 0),
44+
Plugin.UNITS.none, Plugin.DELTA.speed_per_second, 60 * 60),
45+
46+
("checkpoint_write_time", "write_time",
47+
"Write Time",
48+
("PostgreSQL Checkpoints: Write/Sync", "00CC00", 1),
49+
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1),
50+
51+
("checkpoint_sync_time", "checkpoint_sync_time",
52+
"Sync Time",
53+
("PostgreSQL Checkpoints: Write/Sync", "FF5656", 1),
54+
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1)
55+
]
56+
else:
57+
self.query = """
58+
SELECT {0}
59+
FROM pg_catalog.pg_stat_checkpointer;
60+
""" # for mamonsu and agent
61+
self.query_interval = """
62+
SELECT {0}*3600
63+
FROM pg_catalog.pg_stat_checkpointer;
64+
""" # for mamonsu and agent checkpoints in hour
65+
self.Items = [
66+
# key, zbx_key, description,
67+
# ('graph name', color, side), units, delta, factor
68+
("num_timed", "count_timed",
69+
"by Timeout (in hour)",
70+
("PostgreSQL Checkpoints: Count (in hour)", "00CC00", 0),
71+
Plugin.UNITS.none, Plugin.DELTA.speed_per_second, 60 * 60),
72+
73+
("num_requested", "count_wal",
74+
"by WAL (in hour)",
75+
("PostgreSQL Checkpoints: Count (in hour)", "FF5656", 0),
76+
Plugin.UNITS.none, Plugin.DELTA.speed_per_second, 60 * 60),
77+
78+
("write_time", "write_time",
79+
"Write Time",
80+
("PostgreSQL Checkpoints: Write/Sync", "00CC00", 1),
81+
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1),
82+
83+
("sync_time", "checkpoint_sync_time",
84+
"Sync Time",
85+
("PostgreSQL Checkpoints: Write/Sync", "FF5656", 1),
86+
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1)
87+
]
88+
5589
def run(self, zbx):
5690
columns = [x[0] for x in self.Items]
5791
result = Pooler.query(self.query.format(", ".join(columns)))
@@ -146,5 +180,5 @@ def keys_and_queries(self, template_zabbix):
146180
else:
147181
result.append(
148182
"{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + item[1]),
149-
self.query_interval.format(item[0])))
183+
self.query_interval.format(item[0])))
150184
return template_zabbix.key_and_query(result)

0 commit comments

Comments
 (0)