Skip to content

Commit 4ef9e0d

Browse files
committed
Merge branch 'master' of https://github.com/postgrespro/mamonsu
2 parents 2e9ebe5 + 6274eeb commit 4ef9e0d

File tree

12 files changed

+92
-36
lines changed

12 files changed

+92
-36
lines changed

Makefile.pkg

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ build/all: build/pkg_debian build/pkg_ubuntu build/pkg_centos
4848
build/pkg_debian: build/pkg_debian_7 build/pkg_debian_8 build/pkg_debian_9
4949
@echo Debian: done
5050

51-
build/pkg_ubuntu: build/pkg_ubuntu_14_04 build/pkg_ubuntu_16_04 build/pkg_ubuntu_17_10
51+
build/pkg_ubuntu: build/pkg_ubuntu_14_04 build/pkg_ubuntu_16_04 build/pkg_ubuntu_17_10 build/pkg_ubuntu_18_04
5252
@echo Ubuntu: done
5353

5454
build/pkg_centos: build/pkg_centos_6 build/pkg_centos_7
@@ -95,6 +95,10 @@ build/pkg_ubuntu_17_10:
9595
$(call build_deb,ubuntu,artful)
9696
touch build/pkg_ubuntu_17_10
9797

98+
build/pkg_ubuntu_18_04:
99+
$(call build_deb,ubuntu,bionic)
100+
touch build/pkg_ubuntu_18_04
101+
98102
build/pkg_centos_6:
99103
$(call build_rpm,centos,6)
100104
touch build/pkg_centos_6

mamonsu/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__author__ = 'Dmitry Vasilyev'
22
__author_email__ = '[email protected]'
33
__description__ = 'Monitoring agent for PostgreSQL'
4-
__version__ = '2.3.3'
4+
__version__ = '2.3.4'
55
__licence__ = 'BSD'
66

77
__url__ = 'https://github.com/postgrespro/mamonsu'

mamonsu/plugins/pgsql/cfs.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Cfs(Plugin):
2020
pg_catalog.pg_class as c
2121
left join pg_catalog.pg_namespace n on n.oid = c.relnamespace
2222
where c.reltablespace in (select oid from pg_catalog.pg_tablespace where spcoptions::text ~ 'compression')
23-
and c.relkind IN ('r','v','m','S','f','')
23+
and c.relkind IN ('r','v','m','S','f','p','')
2424
and cfs_compression_ratio(c.oid::regclass) <> 'NaN'
2525
2626
union all
@@ -33,7 +33,7 @@ class Cfs(Plugin):
3333
pg_catalog.pg_class as c
3434
left join pg_catalog.pg_namespace n on n.oid = c.relnamespace
3535
where c.reltablespace in (select oid from pg_catalog.pg_tablespace where spcoptions::text ~ 'compression')
36-
and c.relkind = 'i' and n.nspname <> 'pg_toast'
36+
and c.relkind = 'i'
3737
and cfs_compression_ratio(c.oid::regclass) <> 'NaN';
3838
"""
3939

@@ -52,6 +52,7 @@ def run(self, zbx):
5252
if self.plugin_config('force_enable') == 'False':
5353
self.disable_and_exit_if_not_pgpro_ee()
5454

55+
# tick every 100 seconds
5556
if self.ratioCounter == self.ratioInterval:
5657
relations, compressed_size, non_compressed_size = [], 0, 0
5758
for db in Pooler.databases():
@@ -62,7 +63,15 @@ def run(self, zbx):
6263
non_compressed_size += row[2] * row[1]
6364
zbx.send('pgsql.cfs.compress_ratio[{0}]'.format(relation_name), row[1])
6465
zbx.send('pgsql.cfs.discovery_compressed_relations[]', zbx.json({'data': relations}))
65-
zbx.send('pgsql.cfs.activity[total_compress_ratio]', non_compressed_size / compressed_size)
66+
if compressed_size > 0:
67+
zbx.send(
68+
'pgsql.cfs.activity[total_compress_ratio]',
69+
non_compressed_size / compressed_size)
70+
else:
71+
zbx.send(
72+
'pgsql.cfs.activity[total_compress_ratio]',
73+
0.0)
74+
6675
del(relations, compressed_size, non_compressed_size)
6776
self.ratioCounter = 0
6877
self.ratioCounter += 1

mamonsu/plugins/pgsql/connections.py

+26-6
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ class Connections(Plugin):
1616

1717
def run(self, zbx):
1818

19-
result = Pooler.query('select state, count(*) \
20-
from pg_catalog.pg_stat_activity group by state')
19+
if Pooler.is_bootstraped() and Pooler.bootstrap_version_greater('2.3.4'):
20+
result = Pooler.query(
21+
'select state, count(*) '
22+
'from mamonsu_get_connections_states() group by state')
23+
else:
24+
result = Pooler.query(
25+
'select state, count(*) '
26+
'from pg_catalog.pg_stat_activity group by state')
2127
for item in self.Items:
2228
state, key, val = item[0], item[1], 0
2329
for row in result:
@@ -28,13 +34,27 @@ def run(self, zbx):
2834
break
2935
zbx.send('pgsql.connections[{0}]'.format(key), float(val))
3036

31-
result = Pooler.query('select count(*) \
32-
from pg_catalog.pg_stat_activity')
37+
if Pooler.is_bootstraped() and Pooler.bootstrap_version_greater('2.3.4'):
38+
result = Pooler.query(
39+
'select count(*) '
40+
'from mamonsu_get_connections_states()')
41+
else:
42+
result = Pooler.query(
43+
'select count(*) '
44+
'from pg_catalog.pg_stat_activity')
45+
3346
zbx.send('pgsql.connections[total]', int(result[0][0]))
3447

3548
if Pooler.server_version_less('9.5.0'):
36-
result = Pooler.query('select count(*) \
37-
from pg_catalog.pg_stat_activity where waiting')
49+
if Pooler.is_bootstraped() and Pooler.bootstrap_version_greater('2.3.4'):
50+
result = Pooler.query(
51+
'select count(*) '
52+
'from mamonsu.mamonsu_get_connections_states() '
53+
'where waiting')
54+
else:
55+
result = Pooler.query(
56+
'select count(*) '
57+
'from pg_catalog.pg_stat_activity where waiting')
3858
zbx.send('pgsql.connections[waiting]', int(result[0][0]))
3959

4060
def items(self, template):

mamonsu/plugins/pgsql/driver/pool.py

+21-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
class Pool(object):
77

8-
ExcludeDBs = ['template0', 'template1', 'postgres']
8+
ExcludeDBs = ['template0', 'template1']
99

1010
SQL = {
1111
# query type: ( 'if_not_installed', 'if_installed' )
@@ -76,21 +76,21 @@ def server_version(self, db=None):
7676
result.decode('ascii'))
7777
return self._cache['server_version']['storage'][db]
7878

79-
def server_version_greater(self, version, db=None, bootstrap=False):
80-
if not bootstrap:
81-
db = self._normalize_db(db)
82-
return self.server_version(db) >= LooseVersion(version)
83-
else:
84-
return str(
85-
self._cache['bootstrap']['version']) >= LooseVersion(version)
79+
def server_version_greater(self, version, db=None):
80+
db = self._normalize_db(db)
81+
return self.server_version(db) >= LooseVersion(version)
8682

87-
def server_version_less(self, version, db=None, bootstrap=False):
88-
if not bootstrap:
89-
db = self._normalize_db(db)
90-
return self.server_version(db) <= LooseVersion(version)
91-
else:
92-
print(self._cache['bootstrap']['version'])
93-
return self._cache['bootstrap']['version'] <= LooseVersion(version)
83+
def server_version_less(self, version, db=None):
84+
db = self._normalize_db(db)
85+
return self.server_version(db) <= LooseVersion(version)
86+
87+
def bootstrap_version_greater(self, version):
88+
return str(
89+
self._cache['bootstrap']['version']) >= LooseVersion(version)
90+
91+
def bootstrap_version_less(self, version):
92+
return str(
93+
self._cache['bootstrap']['version']) <= LooseVersion(version)
9494

9595
def in_recovery(self, db=None):
9696
db = self._normalize_db(db)
@@ -159,13 +159,15 @@ def is_pgpro_ee(self, db=None):
159159

160160
def extension_installed(self, ext, db=None):
161161
db = self._normalize_db(db)
162-
result = self.query('select count(*) from pg_catalog.pg_extension\
163-
where extname = \'{0}\''.format(ext), db)
162+
result = self.query(
163+
'select count(*) from pg_catalog.pg_extension '
164+
'where extname = \'{0}\''.format(ext), db)
164165
return (int(result[0][0])) == 1
165166

166167
def databases(self):
167-
result, databases = self.query('select datname from \
168-
pg_catalog.pg_database'), []
168+
result, databases = self.query(
169+
'select datname from '
170+
'pg_catalog.pg_database'), []
169171
for row in result:
170172
if row[0] not in self.ExcludeDBs:
171173
databases.append(row[0])

mamonsu/plugins/pgsql/oldest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Oldest(Plugin):
3232
}
3333

3434
def run(self, zbx):
35-
if Pooler.is_bootstraped() and Pooler.server_version_greater('2.3.2', bootstrap=True):
35+
if Pooler.is_bootstraped() and Pooler.bootstrap_version_greater('2.3.2'):
3636
xid = Pooler.query(self.OldestXidSql_bootstrap)[0][0]
3737
query = Pooler.query(self.OldestQuerySql_bootstrap)[0][0]
3838
else:

mamonsu/tools/bootstrap/sql.py

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@
5050
and pid <> pg_catalog.pg_backend_pid()
5151
$$ LANGUAGE SQL SECURITY DEFINER;
5252
53+
CREATE OR REPLACE FUNCTION public.mamonsu_get_connections_states()
54+
RETURNS TABLE(state text) AS $$
55+
SELECT
56+
state
57+
FROM pg_catalog.pg_stat_activity
58+
$$ LANGUAGE SQL SECURITY DEFINER;
59+
5360
CREATE or REPLACE FUNCTION public.mamonsu_get_oldest_xid()
5461
RETURNS BIGINT AS $$
5562
SELECT

mamonsu/tools/bootstrap/start.py

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ def try_configure_connect_to_pg(self):
9090
"Can't connect as user postgres,"
9191
" may be database settings wrong?\n")
9292
return False
93+
else:
94+
return True
95+
9396
else:
9497
sys.stderr.write(
9598
"Can't connect with host=auto,"

mamonsu/tools/report/pgsql.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,10 @@ def _collect_connections(self):
308308

309309
def _collect_biggest(self):
310310
result, sizes, sorted_result = {}, {}, OrderedDict({})
311-
for info_dbs in Pooler.query('select datname \
312-
from pg_catalog.pg_database where datistemplate = false'):
311+
for info_dbs in Pooler.query(
312+
'select datname '
313+
'from pg_catalog.pg_database where datistemplate = false'
314+
):
313315
try:
314316
for info in Pooler.query(self.BigTableInfo[0], info_dbs[0]):
315317
table_name = '{0}.{1}'.format(info_dbs[0], info[0])

packaging/debian/changelog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
mamonsu (2.3.4-1) stable; urgency=low
2+
3+
* Connections states fix, cfs compression ratio fix
4+
5+
-- PostgresPro DBA <[email protected]> Thu, 15 Feb 2018 11:00:00 +0300
6+
17
mamonsu (2.3.3-1) stable; urgency=low
28

39
* PostgreSQL 10 support

packaging/rpm/SPECS/mamonsu.spec

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name: mamonsu
2-
Version: 2.3.3
2+
Version: 2.3.4
33
Release: 1%{?dist}
44
Summary: Monitoring agent for PostgreSQL
55
Group: Applications/Internet
@@ -70,7 +70,10 @@ chown mamonsu.mamonsu /var/log/mamonsu
7070
/sbin/chkconfig --del mamonsu
7171

7272
%changelog
73-
* Fri Jan 19 2018 Grigory Smolkin <[email protected]> - 2.3.3-1
73+
* Thu Feb 15 2018 Grigory Smolkin <[email protected]> - 2.3.4-1
74+
- Connections states fix, cfs compression ratio fix
75+
76+
* Tue Dec 12 2017 Grigory Smolkin <[email protected]> - 2.3.3-1
7477
- PostgreSQL 10 support
7578

7679
* Tue Dec 12 2017 Grigory Smolkin <[email protected]> - 2.3.2-1

packaging/win/mamonsu.def.nsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
!define NAME Mamonsu
2-
!define VERSION 2.3.3
2+
!define VERSION 2.3.4
33
!define MAMONSU_REG_PATH "Software\PostgresPro\Mamonsu"
44
!define MAMONSU_REG_UNINSTALLER_PATH "Software\Microsoft\Windows\CurrentVersion\Uninstall"
55
!define EDB_REG "SOFTWARE\Postgresql"

0 commit comments

Comments
 (0)