Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mstyushin committed Apr 18, 2024
2 parents 0656479 + 5e1d955 commit 31a5981
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 105 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/mamonsu-tests-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
- docker_os: 'centos:8'
pg_version: '16'
zabbix_version: '6.4.13'
- docker_os: 'ubuntu:24.04'
pg_version: '16'
zabbix_version: '6.4.13'
exclude:
- docker_os: 'centos:8'
pg_version: '12'
Expand Down Expand Up @@ -77,7 +80,7 @@ jobs:
echo "zabbix_address=$(hostname -I | awk '{print $1}')" >> $GITHUB_OUTPUT
id: zabbix_address
- name: Edit Zabbix address in agent.conf
run: sed -i "s/\(address *= *\).*/\1 ${{ steps.zabbix_address.outputs.zabbix_address }}/" ${{ env.MAMONSU_PATH }}/github-actions-tests/sources/agent_3.5.7.conf
run: sed -i "s/\(address *= *\).*/\1 ${{ steps.zabbix_address.outputs.zabbix_address }}/" ${{ env.MAMONSU_PATH }}/github-actions-tests/sources/agent_3.5.8.conf

- name: Copy test scripts to container
run: docker exec $( echo "${{ matrix.docker_os }}" | sed 's/://' | sed 's/\.//' ) mkdir -p -m 755 /mamonsu/
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/mamonsu-tests-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
- docker_os: 'ubuntu:20.04'
pg_version: '15'
zabbix_version: '6.4.13'
- docker_os: 'ubuntu:24.04'
pg_version: '16'
zabbix_version: '6.4.13'
exclude:
# excludes PG 15, 16 on CentOS
- docker_os: 'centos:7'
Expand Down Expand Up @@ -88,7 +91,7 @@ jobs:
echo "zabbix_address=$(hostname -I | awk '{print $1}')" >> $GITHUB_OUTPUT
id: zabbix_address
- name: Edit Zabbix address in agent.conf
run: sed -i "s/\(address *= *\).*/\1 ${{ steps.zabbix_address.outputs.zabbix_address }}/" ${{ env.MAMONSU_PATH }}/github-actions-tests/sources/agent_3.5.7.conf
run: sed -i "s/\(address *= *\).*/\1 ${{ steps.zabbix_address.outputs.zabbix_address }}/" ${{ env.MAMONSU_PATH }}/github-actions-tests/sources/agent_3.5.8.conf

- name: Copy test scripts to container
run: docker exec $( echo "${{ matrix.docker_os }}" | sed 's/://' | sed 's/\.//' ) mkdir -p -m 755 /mamonsu/
Expand Down
4 changes: 2 additions & 2 deletions github-actions-tests/mamonsu_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if [ "${OS%:*}" = "centos" ]; then
python3 setup.py build && python3 setup.py install
make rpm
sudo rpm -i ./mamonsu*.rpm
cat /mamonsu/github-actions-tests/sources/agent_3.5.7.conf > /etc/mamonsu/agent.conf
cat /mamonsu/github-actions-tests/sources/agent_3.5.8.conf > /etc/mamonsu/agent.conf
systemctl daemon-reload
systemctl restart mamonsu
sleep 5
Expand All @@ -64,7 +64,7 @@ elif [ "${OS%:*}" = "ubuntu" ]; then
python3 setup.py build && python3 setup.py install
make deb
sudo dpkg -i ./mamonsu*.deb
cat /mamonsu/github-actions-tests/sources/agent_3.5.7.conf > /etc/mamonsu/agent.conf
cat /mamonsu/github-actions-tests/sources/agent_3.5.8.conf > /etc/mamonsu/agent.conf
service mamonsu restart
sleep 5
echo && echo && echo "mamonsu version:"
Expand Down
2 changes: 1 addition & 1 deletion mamonsu/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__author__ = 'Dmitry Vasilyev'
__author_email__ = '[email protected]'
__description__ = 'Monitoring agent for PostgreSQL'
__version__ = '3.5.7'
__version__ = '3.5.8'
__licence__ = 'BSD'

__url__ = 'https://github.com/postgrespro/mamonsu'
Expand Down
13 changes: 9 additions & 4 deletions mamonsu/plugins/pgsql/driver/pg8000/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections import defaultdict, deque
from datetime import datetime as Datetime
from decimal import Decimal
from distutils.version import LooseVersion
from pkg_resources import packaging
from hashlib import md5
from itertools import count, islice
from struct import Struct
Expand Down Expand Up @@ -1416,11 +1416,16 @@ def handle_PARAMETER_STATUS(self, data, ps):
pass

elif key == b"server_version":
self._server_version = LooseVersion(value.decode('ascii'))
if self._server_version < LooseVersion('8.2.0'):
# LooseVersion() from distutils was able to handle non-relevant strings
# in version (like "16.2 (Ubuntu 16.2-1.pgdg20.04+1)")
# since distutils became deprecated we need this hack hoping that
# postgres package maintainers won't come up with something more exotic
string_version = value.decode('ascii').split(' ')[0]
self._server_version = packaging.version.parse(string_version)
if self._server_version < packaging.version.parse('8.2.0'):
self._commands_with_count = (
b"INSERT", b"DELETE", b"UPDATE", b"MOVE")
elif self._server_version < LooseVersion('9.0.0'):
elif self._server_version < packaging.version.parse('9.0.0'):
self._commands_with_count = (
b"INSERT", b"DELETE", b"UPDATE", b"MOVE", b"FETCH",
b"COPY")
Expand Down
42 changes: 22 additions & 20 deletions mamonsu/plugins/pgsql/driver/pool.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from distutils.version import LooseVersion
from pkg_resources import packaging
from .connection import Connection, ConnectionInfo


Expand Down Expand Up @@ -124,27 +124,29 @@ def server_version(self, db=None):
db = self._normalize_db(db)
if db in self._cache["server_version"]["storage"]:
return self._cache["server_version"]["storage"][db]

version_string = self.query("show server_version", db)[0][0]
result = bytes(
self.query("show server_version", db)[0][0], "utf-8")
version_string.split(" ")[0], "utf-8")
self._cache["server_version"]["storage"][db] = "{0}".format(
result.decode("ascii"))
return self._cache["server_version"]["storage"][db]

def server_version_greater(self, version, db=None):
db = self._normalize_db(db)
return self.server_version(db) >= LooseVersion(version)
return packaging.version.parse(self.server_version(db)) >= packaging.version.parse(version)

def server_version_less(self, version, db=None):
db = self._normalize_db(db)
return self.server_version(db) <= LooseVersion(version)
return packaging.version.parse(self.server_version(db)) <= packaging.version.parse(version)

def bootstrap_version_greater(self, version):
return str(
self._cache["bootstrap"]["version"]) >= LooseVersion(version)
return packaging.version.parse(
str(self._cache["bootstrap"]["version"])) >= packaging.version.parse(version)

def bootstrap_version_less(self, version):
return str(
self._cache["bootstrap"]["version"]) <= LooseVersion(version)
return packaging.version.parse(
str(self._cache["bootstrap"]["version"])) <= packaging.version.parse(version)

def in_recovery(self, db=None):
db = self._normalize_db(db)
Expand All @@ -166,16 +168,16 @@ def is_bootstraped(self, db=None):
self._cache["bootstrap"]["counter"] = 0
# TODO: изменить на нормальное название, 'config' слишком общее
sql = """
SELECT count(*)
FROM pg_catalog.pg_class
SELECT count(*)
FROM pg_catalog.pg_class
WHERE relname = 'config';
"""
result = int(self.query(sql, db)[0][0])
self._cache["bootstrap"]["storage"][db] = (result == 1)
if self._cache["bootstrap"]["storage"][db]:
self._connections[db].log.info("Found mamonsu bootstrap")
sql = """
SELECT max(version)
SELECT max(version)
FROM mamonsu.config;
"""
self._cache["bootstrap"]["version"] = self.query(sql, db)[0][0]
Expand Down Expand Up @@ -227,8 +229,8 @@ def is_pgpro_ee(self, db=None):
def extension_installed(self, ext, db=None):
db = self._normalize_db(db)
result = self.query("""
SELECT count(*)
FROM pg_catalog.pg_extension
SELECT count(*)
FROM pg_catalog.pg_extension
WHERE lower(extname) = lower('{0}');
""".format(ext), db)
return (int(result[0][0])) == 1
Expand All @@ -239,9 +241,9 @@ def extension_schema(self, extension, db=None):
return self._cache["extension_schema"][extension][db]
try:
self._cache["extension_schema"][extension][db] = self.query("""
SELECT n.nspname
FROM pg_extension e
JOIN pg_namespace n ON e.extnamespace = n.oid
SELECT n.nspname
FROM pg_extension e
JOIN pg_namespace n ON e.extnamespace = n.oid
WHERE e.extname = '{0}'
""".format(extension), db)[0][0]
return self._cache["extension_schema"][extension][db]
Expand All @@ -250,7 +252,7 @@ def extension_schema(self, extension, db=None):

def databases(self):
result, databases = self.query("""
SELECT datname
SELECT datname
FROM pg_catalog.pg_database;
"""), []
for row in result:
Expand Down Expand Up @@ -309,13 +311,13 @@ def get_sys_param(self, param, db=None):
db = self._normalize_db(db)
if self.is_bootstraped() and self.bootstrap_version_greater("2.3.4"):
result = self.query("""
SELECT *
SELECT *
FROM mamonsu.get_sys_param('{0}');
""".format(param))[0][0]
else:
result = self.query("""
SELECT setting
FROM pg_catalog.pg_settings
SELECT setting
FROM pg_catalog.pg_settings
WHERE name = '{0}';
""".format(param), db)[0][0]
return result
4 changes: 2 additions & 2 deletions mamonsu/plugins/pgsql/memory_leak_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
from .pool import Pooler
import re
from distutils.version import LooseVersion
from pkg_resources import packaging
import mamonsu.lib.platform as platform
import posix

Expand Down Expand Up @@ -91,7 +91,7 @@ def run(self, zbx):
for row in Pooler.query(query=self.query):
pids.append(row[0])

if (LooseVersion(self.os_release) < LooseVersion("4.5")
if (packaging.version.parse(self.os_release) < packaging.version.parse("4.5")
and not (self.os_name == "centos" and self.os_version == "7")) \
or (not self.os_name and not self.os_version):
for pid in pids:
Expand Down
4 changes: 2 additions & 2 deletions mamonsu/plugins/pgsql/replication.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

from mamonsu.plugins.pgsql.plugin import PgsqlPlugin as Plugin
from distutils.version import LooseVersion
from pkg_resources import packaging
from .pool import Pooler
from mamonsu.lib.zbx_template import ZbxTemplate

Expand Down Expand Up @@ -201,7 +201,7 @@ def discovery_rules(self, template, dashboard=False):

def keys_and_queries(self, template_zabbix):
result = []
if LooseVersion(self.VersionPG) < LooseVersion("10"):
if packaging.version.parse(self.VersionPG) < packaging.version.parse("10"):
result.append("{0},$2 $1 -c \"{1}\"".format("pgsql.replication_lag.sec[*]",
self.query_agent_replication_lag.format(
self.plugin_config("interval"), "xlog_receive_location",
Expand Down
4 changes: 2 additions & 2 deletions mamonsu/plugins/system/linux/disk_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DiskStats(Plugin):
# Track only physical devices without logical partitions
OnlyPhysicalDevices = True

re_stat = re.compile("^(?:\s+\d+){2}\s+([\w\d]+) (.*)$")
re_stat = re.compile(r"^(?:\s+\d+){2}\s+([\w\d]+) (.*)$")

# rd_ios rd_merges rd_sectors rd_ticks
# wr_ios wr_merges wr_sectors wr_ticks
Expand All @@ -43,7 +43,7 @@ def run(self, zbx):
if m is None:
continue
dev, val = m.group(1), m.group(2)
if self.OnlyPhysicalDevices and re.search("\d+$", dev): # get drive name without digits at the end
if self.OnlyPhysicalDevices and re.search(r"\d+$", dev): # get drive name without digits at the end
continue
val = [int(x) for x in val.split()]
read_op, read_sc, write_op, write_sc, ticks = val[0], val[2], val[4], val[6], val[9]
Expand Down
6 changes: 3 additions & 3 deletions mamonsu/plugins/system/linux/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
class Memory(Plugin):
AgentPluginType = "sys"

query_agent = "cat /proc/meminfo | awk '/^{0}\:/ "
query_agent_used = "MemTotal=$(cat /proc/meminfo | awk '/MemTotal\:/ { print $2 }'); " \
"SUM=$(cat /proc/meminfo | awk '/(MemFree|Buffers|(Swap)?Cached|Slab|PageTables)\:/ " \
query_agent = r"cat /proc/meminfo | awk '/^{0}\:/ "
query_agent_used = r"MemTotal=$(cat /proc/meminfo | awk '/MemTotal\:/ { print $2 }'); " \
r"SUM=$(cat /proc/meminfo | awk '/(MemFree|Buffers|(Swap)?Cached|Slab|PageTables)\:/ " \
"{ SUM += $2 } END {print SUM}'); echo $((($MemTotal-$SUM)*1024))"
query_agent_swap = "expr `grep -Ei 'Swap(Total|Free)' /proc/meminfo | awk '{print $2 * 1024}' | paste -s -d '-' " \
"| sed -E 's/-/ - /g'` "
Expand Down
2 changes: 1 addition & 1 deletion mamonsu/plugins/system/linux/proc_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ProcStat(Plugin):
# alert fork-rate
ForkRate = 500
# /proc/stat all cpu line
re_stat = re.compile("cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)")
re_stat = re.compile(r"cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)")

ProcessItems = [
# key, zbx_key, name, delta, color, side
Expand Down
Loading

0 comments on commit 31a5981

Please sign in to comment.