Skip to content

Commit 7b8c9d5

Browse files
committed
Merge branch 'dev'
2 parents d5c8e98 + 52ab1c8 commit 7b8c9d5

23 files changed

+223
-209
lines changed

.github/workflows/mamonsu-tests-dev.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ jobs:
2727
strategy:
2828
matrix:
2929
docker_os: ['centos:7']
30-
zabbix_version: ['6.0.4']
31-
pg_version: ['10', '11', '12', '13', '14']
30+
zabbix_version: ['6.2.6']
31+
pg_version: ['11', '12', '13', '14']
3232

3333
steps:
3434
- name: Checkout mamonsu repo
@@ -58,15 +58,15 @@ jobs:
5858
run: bash ./github-actions-tests/zbx_install.sh --zbx-version="${{ matrix.zabbix_version }}"
5959
- name: Retrieve Zabbix address
6060
run: |
61-
echo "::set-output name=zabbix_address::$(hostname -I | awk '{print $1}')"
61+
echo "zabbix_address=$(hostname -I | awk '{print $1}')" >> $GITHUB_OUTPUT
6262
id: zabbix_address
6363
- name: Edit Zabbix address in agent.conf
6464
run: sed -i "s/\(address *= *\).*/\1 ${{ steps.zabbix_address.outputs.zabbix_address }}/" ${{ env.MAMONSU_PATH }}/github-actions-tests/sources/agent_3.5.2.conf
6565

6666
- name: Copy test scripts to container
6767
run: docker exec $( echo "${{ matrix.docker_os }}" | sed 's/://' | sed 's/\.//' ) mkdir -p -m 755 /mamonsu/
6868
- run: docker cp . $( echo "${{ matrix.docker_os }}" | sed 's/://' | sed 's/\.//' ):/mamonsu
69-
- name: Install prequisites
69+
- name: Install prerequisites
7070
run: docker exec $( echo "${{ matrix.docker_os }}" | sed 's/://' | sed 's/\.//' ) bash /mamonsu/github-actions-tests/tests.sh --os="${{ matrix.docker_os }}" --pg-version="${{ matrix.pg_version }}"
7171

7272
- name: Build and install mamonsu

.github/workflows/mamonsu-tests-master.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ jobs:
2727
strategy:
2828
matrix:
2929
docker_os: ['ubuntu:20.04', 'centos:7']
30-
zabbix_version: ['4.0.40', '5.0.23', '5.4.12', '6.0.4']
31-
pg_version: ['10', '11', '12', '13', '14']
30+
zabbix_version: ['4.0.44', '4.4.10', '5.0.30', '5.4.12', '6.0.12', '6.2.6']
31+
pg_version: ['11', '12', '13', '14', '15']
3232
exclude:
33-
# excludes PG 9.6 on CentOS 8
34-
- docker_os: 'centos:8'
35-
pg_version: '9.6'
33+
# excludes PG 15 on CentOS
34+
- docker_os: 'centos:7'
35+
pg_version: '15'
3636

3737
steps:
3838
- name: Checkout mamonsu repo
@@ -62,15 +62,15 @@ jobs:
6262
run: bash ./github-actions-tests/zbx_install.sh --zbx-version="${{ matrix.zabbix_version }}"
6363
- name: Retrieve Zabbix address
6464
run: |
65-
echo "::set-output name=zabbix_address::$(hostname -I | awk '{print $1}')"
65+
echo "zabbix_address=$(hostname -I | awk '{print $1}')" >> $GITHUB_OUTPUT
6666
id: zabbix_address
6767
- name: Edit Zabbix address in agent.conf
6868
run: sed -i "s/\(address *= *\).*/\1 ${{ steps.zabbix_address.outputs.zabbix_address }}/" ${{ env.MAMONSU_PATH }}/github-actions-tests/sources/agent_3.5.2.conf
6969

7070
- name: Copy test scripts to container
7171
run: docker exec $( echo "${{ matrix.docker_os }}" | sed 's/://' | sed 's/\.//' ) mkdir -p -m 755 /mamonsu/
7272
- run: docker cp . $( echo "${{ matrix.docker_os }}" | sed 's/://' | sed 's/\.//' ):/mamonsu
73-
- name: Install prequisites
73+
- name: Install prerequisites
7474
run: docker exec $( echo "${{ matrix.docker_os }}" | sed 's/://' | sed 's/\.//' ) bash /mamonsu/github-actions-tests/tests.sh --os="${{ matrix.docker_os }}" --pg-version="${{ matrix.pg_version }}"
7575

7676
- name: Build and install mamonsu

github-actions-tests/sources/metrics-linux-14.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,13 @@ pgsql.tuples[inserted]
8787
pgsql.tuples[returned]
8888
pgsql.tuples[updated]
8989
pgsql.uptime[]
90-
pgsql.wal.buffers_full
90+
pgsql.wal.buffers_full[]
9191
pgsql.wal.count[]
9292
pgsql.wal.fpi.count[]
9393
pgsql.wal.records.count[]
94-
pgsql.wal.sync_time
94+
pgsql.wal.sync_time[]
9595
pgsql.wal.write[]
96-
pgsql.wal.write_time
96+
pgsql.wal.write_time[]
9797
system.cpu[idle]
9898
system.cpu[iowait]
9999
system.cpu[irq]

github-actions-tests/tools/zabbix_cli.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ mamonsu zabbix $OPTIONS host delete ${HOST_ID} | grep "hostids.*${HOST_ID}" || e
9999

100100
# test 'mamonsu hostgroup'
101101
echo && echo "------> mamonsu zabbix hostgroup list"
102-
mamonsu zabbix $OPTIONS hostgroup list | grep Templates || exit 11
102+
mamonsu zabbix $OPTIONS hostgroup list | grep Linux || exit 11
103103
echo && echo "------> mamonsu zabbix hostgroup show"
104104
mamonsu zabbix $OPTIONS hostgroup show "Linux servers" | grep Linux || exit 11
105105
echo && echo "------> mamonsu zabbix hostgroup id"

mamonsu/lib/config.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,19 @@ def __init__(self, cfg_file=None, plugin_directories=None):
8181
sys.stderr.write('Config file is empty: {0}\n'.format(cfg_file))
8282
sys.exit(1)
8383
if cfg_file is not None:
84-
if platform.LINUX:
85-
config_status = int(repr(oct(os.stat(cfg_file).st_mode))[:-1][-3:])
86-
config_owner = pwd.getpwuid(os.stat(cfg_file).st_uid).pw_name
87-
if not (config_status == 600 and config_owner == "mamonsu"):
88-
logging.info(
89-
"Shut down because of incorrect config file {0} permissions. It must be r/w for mamonsu user only (600).".format(
90-
cfg_file))
91-
sys.stderr.write(
92-
"Please, check your config file {0} permissions. It must be r/w for mamonsu user only (600).\n".format(
93-
cfg_file))
94-
sys.exit(1)
84+
# TODO: instead of hardcoded "mamonsu" user get real mamonsu owner user
85+
# and check if config file belongs to this user
86+
# if platform.LINUX:
87+
# config_status = int(repr(oct(os.stat(cfg_file).st_mode))[:-1][-3:])
88+
# config_owner = pwd.getpwuid(os.stat(cfg_file).st_uid).pw_name
89+
# if not (config_status == 600 and config_owner == "mamonsu"):
90+
# logging.info(
91+
# "Shut down because of incorrect config file {0} permissions. It must be r/w for mamonsu user only (600).".format(
92+
# cfg_file))
93+
# sys.stderr.write(
94+
# "Please, check your config file {0} permissions. It must be r/w for mamonsu user only (600).\n".format(
95+
# cfg_file))
96+
# sys.exit(1)
9597
self.config.read_file(open(cfg_file))
9698

9799
plugins = self.fetch('plugins', 'directory', str)

mamonsu/lib/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Plugin(object):
2424
AgentPluginType = 'all'
2525

2626
# PG version
27-
VersionPG = '10'
27+
VersionPG = '14'
2828

2929
# Macros for run as agent type or as mamonsu
3030
Macros = {"mamonsu": "", "agent": "{$PG_CONNINFO},{$PG_PATH}"}

mamonsu/lib/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def is_any_equal(array):
224224
# extract pg version from input
225225
def define_pg_version(version_args):
226226
if len(version_args) < 4:
227-
if version_args == "14" or version_args == "11" or version_args == "12" or version_args == "13" or version_args == "10" \
227+
if version_args == "15" or version_args == "14" or version_args == "11" or version_args == "12" or version_args == "13" or version_args == "10" \
228228
or version_args == "9.6" or version_args == "9.5":
229229
version_number = version_args[0].split('.')
230230
for num in version_number:

mamonsu/lib/zbx_template.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import re
3+
34
import mamonsu.lib.platform as platform
45
from mamonsu.lib.const import Template
56
from mamonsu.lib.plugin import Plugin
@@ -174,9 +175,9 @@ def xml(self, plg_type, plugins=None):
174175
template_data = {'template': self.Template, 'application': self.Application}
175176
template_data['items'] = self._get_all('items', plugins)
176177
template_data['discovery_rules'] = self._get_all('discovery_rules', plugins)
177-
if Plugin.Type == 'agent':
178-
template_data['macros'] = self.agent_macro()
179178
template_data['macros'] = self._get_all('macros', plugins)
179+
if Plugin.Type == 'agent':
180+
template_data['macros'] += self.agent_macro()
180181
template_data['screens'] = self.screen(plugins)
181182
template_data['triggers'] = self._get_all('triggers', plugins)
182183
template_data['graphs'] = self._get_all('graphs', plugins)
@@ -301,9 +302,9 @@ def screen(self, plugins=None, xml_key='screen'):
301302

302303
def agent_macro(self, xml_key='macro'):
303304
result = ''
304-
value = {'value': '-qAt -p 5433 -U postgres ', 'macro': "{$PG_CONNINFO}"}
305+
value = {'value': '-qAt -p 5432 -U postgres ', 'macro': "{$PG_CONNINFO}"}
305306
result += '<{1}>{0}</{1}>'.format(self._format_args(self.macro_defaults, value), xml_key)
306-
value = {'value': '/opt/pgpro/std-10/bin/psql', 'macro': "{$PG_PATH}"}
307+
value = {'value': '/usr/bin/psql', 'macro': "{$PG_PATH}"}
307308
result += '<{1}>{0}</{1}>'.format(self._format_args(self.macro_defaults, value), xml_key)
308309
return result
309310

mamonsu/plugins/pgsql/archive_command.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22

33
from mamonsu.plugins.pgsql.plugin import PgsqlPlugin as Plugin
4-
from distutils.version import LooseVersion
54
from .pool import Pooler
65
from mamonsu.lib.zbx_template import ZbxTemplate
76
import re
@@ -46,7 +45,7 @@ class ArchiveCommand(Plugin):
4645
('x' || substring(pg_{1}_name(pg_current_{0}()) from 17 for 8))::bit(32)::int END AS current_wal_mod
4746
FROM pg_settings, pg_stat_archiver
4847
WHERE pg_settings.name = 'wal_segment_size')
49-
greatest(coalesce(((segment_parts_count - last_wal_mod) + ((current_wal_div - last_wal_div - 1) * segment_parts_count) + current_wal_mod - 1) * segment_size, 0), 0)::bigint AS size_files
48+
SELECT greatest(coalesce(((segment_parts_count - last_wal_mod) + ((current_wal_div - last_wal_div - 1) * segment_parts_count) + current_wal_mod - 1) * segment_size, 0), 0)::bigint AS size_files
5049
FROM values;
5150
"""
5251

@@ -59,10 +58,12 @@ class ArchiveCommand(Plugin):
5958
key = "pgsql.archive_command{0}"
6059
Items = [
6160
# key, desc, color, side, graph, delta, units
62-
("count_files_to_archive", "Files in archive_status Need to Archive Count", "006AAE", 0, 1, Plugin.DELTA.as_is, Plugin.UNITS.none),
61+
("count_files_to_archive", "Files in archive_status Need to Archive Count", "006AAE", 0, 1, Plugin.DELTA.as_is,
62+
Plugin.UNITS.none),
6363
("size_files_to_archive", "Files Need to Archive Size", "793F5D", 0, 0, Plugin.DELTA.as_is, Plugin.UNITS.bytes),
6464
("archived_files", "Archived Files Count", "00CC00", 0, 1, Plugin.DELTA.simple_change, Plugin.UNITS.none),
65-
("failed_trying_to_archive", "Attempts to Archive Files Count", "FF5656", 0, 1, Plugin.DELTA.simple_change, Plugin.UNITS.none),
65+
("failed_trying_to_archive", "Attempts to Archive Files Count", "FF5656", 0, 1, Plugin.DELTA.simple_change,
66+
Plugin.UNITS.none),
6667
]
6768
old_archived_count = None
6869
old_failed_count = None
@@ -192,25 +193,27 @@ def triggers(self, template, dashboard=False):
192193
return template.trigger({
193194
"name": "PostgreSQL Archiver: count files need to archive on {HOSTNAME} more than 2",
194195
"expression": "{#TEMPLATE:" + self.right_type(self.key,
195-
self.Items[0][0]) + ".last()}&gt;" + self.plugin_macros["archive_queue_files"][0][1]
196+
self.Items[0][0]) + ".last()}&gt;" +
197+
self.plugin_macros["archive_queue_files"][0][1]
196198
})
197199

198200
def keys_and_queries(self, template_zabbix):
199201
result = []
200-
if LooseVersion(self.VersionPG) >= LooseVersion("10"):
202+
if Pooler.server_version_greater("10"):
201203
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + self.Items[0][0]),
202-
self.query_agent_count_files.format("wal_lsn", "walfile")))
204+
self.query_agent_count_files.format("wal_lsn",
205+
"walfile")))
203206
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + self.Items[1][0]),
204-
self.query_agent_size_files.format("wal_lsn", "walfile")))
207+
self.query_agent_size_files.format("wal_lsn", "walfile")))
205208
else:
206209
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + self.Items[0][0]),
207-
self.query_agent_count_files.format("xlog_location",
208-
"xlogfile")))
210+
self.query_agent_count_files.format("xlog_location",
211+
"xlogfile")))
209212
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + self.Items[1][0]),
210-
self.query_agent_size_files.format("xlog_location",
211-
"xlogfile")))
213+
self.query_agent_size_files.format("xlog_location",
214+
"xlogfile")))
212215
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + self.Items[2][0]),
213-
self.query_agent_archived_count))
216+
self.query_agent_archived_count))
214217
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + self.Items[3][0]),
215-
self.query_agent_failed_count))
218+
self.query_agent_failed_count))
216219
return template_zabbix.key_and_query(result)

mamonsu/plugins/pgsql/autovacuum.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# -*- coding: utf-8 -*-
2-
from distutils.version import LooseVersion
32
from mamonsu.plugins.pgsql.plugin import PgsqlPlugin as Plugin
43
from .pool import Pooler
54
from mamonsu.lib.zbx_template import ZbxTemplate
65

6+
77
class Autovacuum(Plugin):
8-
98
AgentPluginType = "pg"
109
# TODO: unify keys and remove its direct mentioning in zbx.send() functions
1110
key_count = "pgsql.autovacuum.count{0}"
@@ -21,7 +20,8 @@ class Autovacuum(Plugin):
2120
def run(self, zbx):
2221
if Pooler.server_version_greater("10.0"):
2322
result_count = Pooler.run_sql_type("count_autovacuum", args=["backend_type = 'autovacuum worker'"])
24-
result_utilization = Pooler.run_sql_type("autovacuum_utilization", args=["backend_type = 'autovacuum worker'"])
23+
result_utilization = Pooler.run_sql_type("autovacuum_utilization",
24+
args=["backend_type = 'autovacuum worker'"])
2525
else:
2626
result_count = Pooler.run_sql_type("count_autovacuum", args=[
2727
"query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()"])
@@ -51,7 +51,7 @@ def items(self, template, dashboard=False):
5151
"value_type": Plugin.VALUE_TYPE.numeric_float,
5252
"units": Plugin.UNITS.percent,
5353
"type": Plugin.TYPE.CALCULATED,
54-
"params": "avg(pgsql.autovacuum.utilization[], 5m)",
54+
"params": "avg(//{item}, 5m)".format(item=self.right_type(self.key_utilization)),
5555
"delay": self.plugin_config("interval")
5656
}))
5757
result += (template.item({
@@ -60,7 +60,7 @@ def items(self, template, dashboard=False):
6060
"value_type": Plugin.VALUE_TYPE.numeric_float,
6161
"units": Plugin.UNITS.percent,
6262
"type": Plugin.TYPE.CALCULATED,
63-
"params": "avg(pgsql.autovacuum.utilization[], 15m)",
63+
"params": "avg(//{item}, 15m)".format(item=self.right_type(self.key_utilization)),
6464
"delay": self.plugin_config("interval")
6565
}))
6666
result += (template.item({
@@ -69,13 +69,13 @@ def items(self, template, dashboard=False):
6969
"value_type": Plugin.VALUE_TYPE.numeric_float,
7070
"units": Plugin.UNITS.percent,
7171
"type": Plugin.TYPE.CALCULATED,
72-
"params": "avg(pgsql.autovacuum.utilization[], 30m)",
72+
"params": "avg(//{item}, 30m)".format(item=self.right_type(self.key_utilization)),
7373
"delay": self.plugin_config("interval")
7474
}))
7575
return result
7676
else:
7777
return []
78-
78+
7979
def graphs(self, template, dashboard=False):
8080
result = template.graph({
8181
"name": "PostgreSQL Autovacuum: Count of Autovacuum Workers",
@@ -97,16 +97,20 @@ def graphs(self, template, dashboard=False):
9797

9898
def keys_and_queries(self, template_zabbix):
9999
result = []
100-
if LooseVersion(self.VersionPG) >= LooseVersion("10"):
101-
result.append("{0},$2 $1 -c \"{1}\"".format(self.key_count.format("[*]"),
102-
Pooler.SQL["count_autovacuum"][0].format("backend_type = 'autovacuum worker'")))
100+
if Pooler.server_version_greater("10"):
101+
# TODO: define another metric key because it duplicates native zabbix agents keys
102+
# result.append("{0},$2 $1 -c \"{1}\"".format(self.key_count.format("[*]"),
103+
# Pooler.SQL["count_autovacuum"][0].format(
104+
# "backend_type = 'autovacuum worker'")))
103105
result.append("{0},$2 $1 -c \"{1}\"".format(self.key_utilization.format("[*]"),
104-
Pooler.SQL["autovacuum_utilization"][0].format(
105-
"backend_type = 'autovacuum worker'")))
106+
Pooler.SQL["autovacuum_utilization"][0].format(
107+
"backend_type = 'autovacuum worker'")))
106108
else:
107-
result.append("{0},$2 $1 -c \"{1}\"".format(self.key_count.format("[*]"),
108-
Pooler.SQL["count_autovacuum"][0].format("query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()")))
109+
# TODO: define another metric key because it duplicates native zabbix agents keys
110+
# result.append("{0},$2 $1 -c \"{1}\"".format(self.key_count.format("[*]"),
111+
# Pooler.SQL["count_autovacuum"][0].format(
112+
# "query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()")))
109113
result.append("{0},$2 $1 -c \"{1}\"".format(self.key_utilization.format("[*]"),
110-
Pooler.SQL["autovacuum_utilization"][0].format(
111-
"query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()")))
114+
Pooler.SQL["autovacuum_utilization"][0].format(
115+
"query LIKE '%%autovacuum%%' AND state <> 'idle' AND pid <> pg_catalog.pg_backend_pid()")))
112116
return template_zabbix.key_and_query(result)

mamonsu/plugins/pgsql/bgwriter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,6 @@ def keys_and_queries(self, template_zabbix):
119119
result = []
120120
for item in self.Items:
121121
# delete from key '[' and ']' in Item for zabbix agent
122-
result.append("{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + item[0]), self.query.format(item[0])))
122+
result.append(
123+
"{0}[*],$2 $1 -c \"{1}\"".format(self.key.format("." + item[0]), self.query.format(item[0])))
123124
return template_zabbix.key_and_query(result)

0 commit comments

Comments
 (0)