fix: add support old zabbix
@@ -4,11 +4,13 @@ from .pool import Pooler
import re
from distutils.version import LooseVersion
import mamonsu.lib.platform as platform
+import posix
class MemoryLeakDiagnostic(Plugin):
DEFAULT_CONFIG = {'enabled': 'False',
- 'private_anon_mem_threshold': '1GB'}
+ 'private_anon_mem_threshold': '1GB',
+ 'interval': '60'}
Interval = 60
query = 'select pid from pg_stat_activity'
@@ -47,7 +49,14 @@ class MemoryLeakDiagnostic(Plugin):
self.diff = ratio * int(private_anon_mem_threshold)
- self.os_release = os.uname().release
+ uname = os.uname()
+ if isinstance(uname, tuple):
+ self.os_release = uname[2]
+ elif isinstance(uname, posix.uname_result):
+ self.os_release = uname.release
+ else:
+ self.os_release = '0'
+
os_release_file = '/etc/os-release'
try:
release_file = open(os_release_file, 'r').readlines()
@@ -92,10 +101,7 @@ class MemoryLeakDiagnostic(Plugin):
diffs.append({'pid': pid, 'RES': RES, 'SHR': SHR, 'diff': self.diff})
if diffs:
for diff in diffs:
- msg_text += 'pid: {pid}, RES {RES} - SHR {SHR} more then {diff}\n'.format(pid=diff.get('pid'),
- RES=diff.get('RES'),
- SHR=diff.get('SHR'),
- diff=diff.get('diff'))
+ msg_text += 'pid: {pid}, RES {RES} - SHR {SHR} more then {diff}\n'.format_map(diff)
else:
for pid in pids:
try:
@@ -126,12 +132,7 @@ class MemoryLeakDiagnostic(Plugin):
if diffs:
for diff in diffs:
msg_text += 'pid: {pid}, RssAnon {RssAnon} more then {diff}, VmRSS {VmRSS}, ' \
- 'RssFile {RssFile}, RssShmem {RssShmem} \n'.format(pid=diff.get('pid'),
- RssAnon=diff.get('RssAnon'),
- diff=diff.get('diff'),
- VmRSS=diff.get('VmRSS'),
- RssFile=diff.get('RssFile'),
- RssShmem=diff.get('RssShmem'))
+ 'RssFile {RssFile}, RssShmem {RssShmem} \n'.format_map(diff)
zbx.send(self.key_count_diff, int(count_diff))
zbx.send(self.key_count_diff_error, msg_text)
