Skip to content

Commit

Permalink
fix: updates for postgres 17
Browse files Browse the repository at this point in the history
- updated checkpoint plugin: added support for new view pg_stat_checkpointer
- updated bgwriter plugin: consider updated view pg_stat_bgwriter in postgres 17
  • Loading branch information
mstyushin committed Dec 13, 2024
1 parent ea9ceb4 commit a1b0f51
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 73 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Supported platforms:
- Windows;

Supported Zabbix server versions: 4.0.44 - 6.4.13
Supported PostgreSQL versions: 12 - 16

Supported PostgreSQL versions: 12 - 17
***

***Table of Contents***
Expand Down
42 changes: 38 additions & 4 deletions documentation/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@ Default config:
</tr>
<tr>
<th>Supported Version</th>
<td>9.5+</td>
<td>9.5 - 16</td>
</tr>
</table>

Expand Down Expand Up @@ -2030,7 +2030,7 @@ Default config:
</tr>
<tr>
<th>Supported Version</th>
<td>9.5+</td>
<td>9.5 - 16</td>
</tr>
</table>

Expand Down Expand Up @@ -2096,7 +2096,7 @@ Default config:
</tr>
<tr>
<th>Supported Version</th>
<td>9.5+</td>
<td>9.5 - 16</td>
</tr>
</table>

Expand Down Expand Up @@ -2208,7 +2208,7 @@ Default config:

### Items

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

- **Checkpoints Sync Time**

Expand Down Expand Up @@ -2341,6 +2341,40 @@ Default config:

*Requested Checkpoints* maps `checkpoints_req`.


- **Buffers Written During Checkpoints**

Zabbix item:
<table>
<tr>
<th>Name</th>
<td>PostgreSQL bgwriter: Buffers Written During Checkpoints</td>
</tr>
<tr>
<th>Key</th>
<td>pgsql.checkpoint[buffers_written]</td>
</tr>
<tr>
<th>Type</th>
<td>Numeric (float)</td>
</tr>
<tr>
<th>Units</th>
<td></td>
</tr>
<tr>
<th>Delta</th>
<td>Simple Change</td>
</tr>
<tr>
<th>Supported Version</th>
<td>17+</td>
</tr>
</table>

*Buffers Written During Checkpoints* maps `buffers_written`.


### Graphs

<table>
Expand Down
92 changes: 58 additions & 34 deletions mamonsu/plugins/pgsql/bgwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,68 @@ class BgWriter(Plugin):
SELECT {0}
FROM pg_catalog.pg_stat_bgwriter;
"""
Items = [
# key, zbx_key, description,
# ('graph name', color, side), units, delta

("buffers_checkpoint", "bgwriter[buffers_checkpoint]",
"Buffers Written During Checkpoints",
("PostgreSQL bgwriter", "006AAE", 1),
Plugin.DELTA.simple_change),

("buffers_clean", "bgwriter[buffers_clean]",
"Buffers Written",
("PostgreSQL bgwriter", "00CC00", 1),
Plugin.DELTA.simple_change),

("maxwritten_clean", "bgwriter[maxwritten_clean]",
"Number of bgwriter Stopped by Max Write Count",
("PostgreSQL bgwriter", "FF5656", 0),
Plugin.DELTA.simple_change),

("buffers_backend", "bgwriter[buffers_backend]",
"Buffers Written Directly by a Backend",
("PostgreSQL bgwriter", "9C8A4E", 1),
Plugin.DELTA.simple_change),

("buffers_backend_fsync", "bgwriter[buffers_backend_fsync]",
"Times a Backend Execute Its Own Fsync",
("PostgreSQL bgwriter", "00CC00", 0),
Plugin.DELTA.simple_change),

("buffers_alloc", "bgwriter[buffers_alloc]",
"Buffers Allocated",
("PostgreSQL bgwriter", "FF5656", 1),
Plugin.DELTA.simple_change)
]

graph_name_buffers = "PostgreSQL bgwriter: Buffers"
graph_name_ws = "PostgreSQL bgwriter: Write/Sync"

def __init__(self, config):
super(BgWriter, self).__init__(config)
if Pooler.server_version_less("17"):
self.Items = [
# key, zbx_key, description,
# ('graph name', color, side), units, delta

("buffers_checkpoint", "bgwriter[buffers_checkpoint]",
"Buffers Written During Checkpoints",
("PostgreSQL bgwriter", "006AAE", 1),
Plugin.DELTA.simple_change),

("buffers_clean", "bgwriter[buffers_clean]",
"Buffers Written",
("PostgreSQL bgwriter", "00CC00", 1),
Plugin.DELTA.simple_change),

("maxwritten_clean", "bgwriter[maxwritten_clean]",
"Number of bgwriter Stopped by Max Write Count",
("PostgreSQL bgwriter", "FF5656", 0),
Plugin.DELTA.simple_change),

("buffers_backend", "bgwriter[buffers_backend]",
"Buffers Written Directly by a Backend",
("PostgreSQL bgwriter", "9C8A4E", 1),
Plugin.DELTA.simple_change),

("buffers_backend_fsync", "bgwriter[buffers_backend_fsync]",
"Times a Backend Execute Its Own Fsync",
("PostgreSQL bgwriter", "00CC00", 0),
Plugin.DELTA.simple_change),

("buffers_alloc", "bgwriter[buffers_alloc]",
"Buffers Allocated",
("PostgreSQL bgwriter", "FF5656", 1),
Plugin.DELTA.simple_change)
]
else:
self.Items = [
# key, zbx_key, description,
# ('graph name', color, side), units, delta

("buffers_clean", "bgwriter[buffers_clean]",
"Buffers Written",
("PostgreSQL bgwriter", "00CC00", 1),
Plugin.DELTA.simple_change),

("maxwritten_clean", "bgwriter[maxwritten_clean]",
"Number of bgwriter Stopped by Max Write Count",
("PostgreSQL bgwriter", "FF5656", 0),
Plugin.DELTA.simple_change),

("buffers_alloc", "bgwriter[buffers_alloc]",
"Buffers Allocated",
("PostgreSQL bgwriter", "FF5656", 1),
Plugin.DELTA.simple_change)
]

def run(self, zbx):
columns = [x[0] for x in self.Items]
result = Pooler.query(self.query.format(", ".join(columns)))
Expand Down
102 changes: 68 additions & 34 deletions mamonsu/plugins/pgsql/checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,83 @@ class Checkpoint(Plugin):
AgentPluginType = "pg"
Interval = 60 * 5

query = """
SELECT {0}
FROM pg_catalog.pg_stat_bgwriter;
""" # for mamonsu and agent
query_interval = """
SELECT {0}*3600
FROM pg_catalog.pg_stat_bgwriter;
""" # for mamonsu and agent checkpoints in hour
key = "pgsql.checkpoint{0}"

# key: (macro, value)
plugin_macros = {
"max_checkpoint_by_wal_in_hour": [("macro", "{$MAX_CHECKPOINT_BY_WAL_IN_HOUR}"), ("value", 12)]
}

Items = [
# key, zbx_key, description,
# ('graph name', color, side), units, delta, factor

("checkpoints_timed", "count_timed",
"by Timeout (in hour)",
("PostgreSQL Checkpoints: Count (in hour)", "00CC00", 0),
Plugin.UNITS.none, Plugin.DELTA.speed_per_second, 60 * 60),

("checkpoints_req", "count_wal",
"by WAL (in hour)",
("PostgreSQL Checkpoints: Count (in hour)", "FF5656", 0),
Plugin.UNITS.none, Plugin.DELTA.speed_per_second, 60 * 60),

("checkpoint_write_time", "write_time",
"Write Time",
("PostgreSQL Checkpoints: Write/Sync", "00CC00", 1),
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1),

("checkpoint_sync_time", "checkpoint_sync_time",
"Sync Time",
("PostgreSQL Checkpoints: Write/Sync", "FF5656", 1),
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1)
]

graph_name_count = "PostgreSQL Checkpoints: Count (in hour)"
graph_name_ws = "PostgreSQL Checkpoints: Write/Sync"

def __init__(self, config):
super(Checkpoint, self).__init__(config)
if Pooler.server_version_less("17"):
self.query = """
SELECT {0}
FROM pg_catalog.pg_stat_bgwriter;
""" # for mamonsu and agent
self.query_interval = """
SELECT {0}*3600
FROM pg_catalog.pg_stat_bgwriter;
""" # for mamonsu and agent checkpoints in hour
self.Items = [
# key, zbx_key, description,
# ('graph name', color, side), units, delta, factor
("checkpoints_timed", "count_timed",
"by Timeout (in hour)",
("PostgreSQL Checkpoints: Count (in hour)", "00CC00", 0),
Plugin.UNITS.none, Plugin.DELTA.speed_per_second, 60 * 60),

("checkpoints_req", "count_wal",
"by WAL (in hour)",
("PostgreSQL Checkpoints: Count (in hour)", "FF5656", 0),
Plugin.UNITS.none, Plugin.DELTA.speed_per_second, 60 * 60),

("checkpoint_write_time", "write_time",
"Write Time",
("PostgreSQL Checkpoints: Write/Sync", "00CC00", 1),
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1),

("checkpoint_sync_time", "checkpoint_sync_time",
"Sync Time",
("PostgreSQL Checkpoints: Write/Sync", "FF5656", 1),
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1)
]
else:
self.query = """
SELECT {0}
FROM pg_catalog.pg_stat_checkpointer;
""" # for mamonsu and agent
self.query_interval = """
SELECT {0}*3600
FROM pg_catalog.pg_stat_checkpointer;
""" # for mamonsu and agent checkpoints in hour
self.Items = [
# key, zbx_key, description,
# ('graph name', color, side), units, delta, factor
("num_timed", "count_timed",
"by Timeout (in hour)",
("PostgreSQL Checkpoints: Count (in hour)", "00CC00", 0),
Plugin.UNITS.none, Plugin.DELTA.speed_per_second, 60 * 60),

("num_requested", "count_wal",
"by WAL (in hour)",
("PostgreSQL Checkpoints: Count (in hour)", "FF5656", 0),
Plugin.UNITS.none, Plugin.DELTA.speed_per_second, 60 * 60),

("write_time", "write_time",
"Write Time",
("PostgreSQL Checkpoints: Write/Sync", "00CC00", 1),
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1),

("sync_time", "checkpoint_sync_time",
"Sync Time",
("PostgreSQL Checkpoints: Write/Sync", "FF5656", 1),
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1)
]

def run(self, zbx):
columns = [x[0] for x in self.Items]
result = Pooler.query(self.query.format(", ".join(columns)))
Expand Down Expand Up @@ -146,5 +180,5 @@ def keys_and_queries(self, template_zabbix):
else:
result.append(
"{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + item[1]),
self.query_interval.format(item[0])))
self.query_interval.format(item[0])))
return template_zabbix.key_and_query(result)

0 comments on commit a1b0f51

Please sign in to comment.