Skip to content

Commit faf9dd8

Browse files
committed
feature: added new zabbix cli 'dashboard' feature (only for Zabbix 6.0+)
1 parent e642441 commit faf9dd8

File tree

10 files changed

+1177
-30
lines changed

10 files changed

+1177
-30
lines changed

mamonsu/lib/parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
{prog} zabbix item error <host name>
9393
{prog} zabbix item lastvalue <host name>
9494
{prog} zabbix item lastclock <host name>
95+
{prog} zabbix dashboard upload <template name>
9596
{prog} zabbix version
9697
9798
Options:

mamonsu/plugins/pgsql/bgwriter.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class BgWriter(Plugin):
4747
Plugin.DELTA.simple_change)
4848
]
4949

50+
graph_name_buffers = "PostgreSQL bgwriter buffers"
51+
graph_name_ws = "PostgreSQL bgwriter write/sync"
52+
5053
def run(self, zbx):
5154
columns = [x[0] for x in self.Items]
5255
result = Pooler.query(self.query.format(", ".join(columns)))
@@ -88,24 +91,23 @@ def graphs(self, template, dashboard=False):
8891
"color": item[3][1]
8992
})
9093
result = template.graph({
91-
"name": "PostgreSQL bgwriter buffers",
94+
"name": self.graph_name_buffers,
9295
"items": items_buffers
93-
}) + \
94-
template.graph({
95-
"name": "PostgreSQL bgwriter write/sync",
96-
"items": items_write_sync
97-
})
96+
}) + template.graph({
97+
"name": self.graph_name_ws,
98+
"items": items_write_sync
99+
})
98100
if not dashboard:
99101
return result
100102
else:
101103
return [{
102-
"dashboard": {"name": "PostgreSQL bgwriter buffers",
104+
"dashboard": {"name": self.graph_name_buffers,
103105
"page": ZbxTemplate.dashboard_page_overview["name"],
104106
"size": ZbxTemplate.dashboard_widget_size_medium,
105107
"position": 7}
106108
},
107109
{
108-
"dashboard": {"name": "PostgreSQL bgwriter write/sync",
110+
"dashboard": {"name": self.graph_name_ws,
109111
"page": ZbxTemplate.dashboard_page_overview["name"],
110112
"size": ZbxTemplate.dashboard_widget_size_medium,
111113
"position": 8}

mamonsu/plugins/pgsql/checkpoint.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class Checkpoint(Plugin):
4848
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1)
4949
]
5050

51+
graph_name_count = "PostgreSQL checkpoints count"
52+
graph_name_ws = "PostgreSQL checkpoints write/sync"
53+
5154
def run(self, zbx):
5255
columns = [x[0] for x in self.Items]
5356
result = Pooler.query(self.query.format(", ".join(columns)))
@@ -92,13 +95,12 @@ def graphs(self, template, dashboard=False):
9295
"delay": self.Interval
9396
})
9497
result = template.graph({
95-
"name": "PostgreSQL checkpoints count",
98+
"name": self.graph_name_count,
9699
"items": items_checkpoints
97-
}) + \
98-
template.graph({
99-
"name": "PostgreSQL checkpoints write/sync",
100-
"items": items_checkpoints_write_sync
101-
})
100+
}) + template.graph({
101+
"name": self.graph_name_ws,
102+
"items": items_checkpoints_write_sync
103+
})
102104
if not dashboard:
103105
return result
104106
else:

mamonsu/plugins/pgsql/connections.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Connections(Plugin):
6868
WHERE name = 'max_connections';
6969
"""
7070
key = "pgsql.connections{0}"
71+
graph_name = "PostgreSQL connections"
7172

7273
def run(self, zbx):
7374
if Pooler.is_bootstraped() and Pooler.bootstrap_version_greater("2.3.4"):
@@ -201,7 +202,7 @@ def graphs(self, template, dashboard=False):
201202
})
202203

203204
graph = {
204-
"name": "PostgreSQL connections",
205+
"name": self.graph_name,
205206
"items": items
206207
}
207208

mamonsu/plugins/pgsql/instance.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ class Instance(Plugin):
7676
END;
7777
"""
7878

79+
graphs_name = {
80+
"rate": "PostgreSQL instance: rate",
81+
"events": "PostgreSQL instance: events",
82+
"temp": "PostgreSQL instance: temp files",
83+
"tuples": "PostgreSQL instance: tuples"}
84+
7985
def run(self, zbx):
8086
all_items = self.Items
8187
if Pooler.server_version_greater("12.0"):
@@ -144,13 +150,8 @@ def items(self, template, dashboard=False):
144150
}]
145151

146152
def graphs(self, template, dashboard=False):
147-
graphs_name = [
148-
"PostgreSQL instance: rate",
149-
"PostgreSQL instance: events",
150-
"PostgreSQL instance: temp files",
151-
"PostgreSQL instance: tuples"]
152153
result = ""
153-
for name in graphs_name:
154+
for name in self.graphs_name.values():
154155
items = []
155156
for num, item in enumerate(self.Items + self.Items_pg_12):
156157
if item[3][0] == name:

mamonsu/plugins/pgsql/pg_buffercache.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class PgBufferCache(Plugin):
2828
("dirty", "PostgreSQL: shared buffer dirty size", "00CC00")
2929
]
3030

31+
graph_name = "PostgreSQL: shared buffer"
32+
3133
def run(self, zbx):
3234
if not self.extension_installed("pg_buffercache"):
3335
return
@@ -57,11 +59,11 @@ def graphs(self, template, dashboard=False):
5759
"color": item[2]})
5860
if not dashboard:
5961
return template.graph({
60-
"name": "PostgreSQL: shared buffer",
62+
"name": self.graph_name,
6163
"items": items})
6264
else:
6365
return [{
64-
"dashboard": {"name": "PostgreSQL: shared buffer",
66+
"dashboard": {"name": self.graph_name,
6567
"page": ZbxTemplate.dashboard_page_overview["name"],
6668
"size": ZbxTemplate.dashboard_widget_size_medium,
6769
"position": 2}

mamonsu/plugins/pgsql/pg_locks.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class PgLocks(Plugin):
4747
"00CCCC")
4848
]
4949

50+
graph_name = "PostgreSQL locks sampling"
51+
5052
def run(self, zbx):
5153
result = Pooler.query(self.query)
5254
for item in self.Items:
@@ -81,7 +83,8 @@ def items(self, template, dashboard=False):
8183
return lock_graphs
8284

8385
def graphs(self, template, dashboard=False):
84-
name, items = "PostgreSQL locks sampling", []
86+
name = self.graph_name
87+
items = []
8588
for item in self.Items:
8689
items.append({
8790
"key": self.right_type(self.key, item[0]),

mamonsu/plugins/pgsql/pg_stat_statement.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class PgStatStatement(Plugin):
7575
("PostgreSQL statements info: last statistics reset", "0000CC", 0))
7676
]
7777

78+
all_graphs = [
79+
("PostgreSQL statements: bytes", None),
80+
("PostgreSQL statements: spend time", 1),
81+
("PostgreSQL statements: wal statistics", None)]
82+
7883
def run(self, zbx):
7984
if not self.extension_installed("pg_stat_statements"):
8085
return
@@ -124,12 +129,8 @@ def items(self, template, dashboard=False):
124129
return []
125130

126131
def graphs(self, template, dashboard=False):
127-
all_graphs = [
128-
("PostgreSQL statements: bytes", None),
129-
("PostgreSQL statements: spend time", 1),
130-
("PostgreSQL statements: wal statistics", None)]
131132
result = ""
132-
for graph_item in all_graphs:
133+
for graph_item in self.all_graphs:
133134
items = []
134135
for item in self.Items + self.Items_pg_13:
135136
if item[5][0] == graph_item[0]:

0 commit comments

Comments
 (0)