8000 Merge branch 'dev' · postgrespro/mamonsu@bdfe6e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit bdfe6e1

Browse files
committed
Merge branch 'dev'
2 parents 499a3bc + c83c973 commit bdfe6e1

File tree

9 files changed

+93
-25
lines changed

9 files changed

+93
-25
lines changed

github-actions-tests/mamonsu_build.sh

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,8 @@ if [ "${OS%:*}" = "centos" ]; then
4040
rm -rf /etc/mamonsu; rm -rf /usr/bin/mamonsu; rm -rf /usr/local/bin/mamonsu; rm -rf /usr/lib/python3/dist-packages/mamonsu; rm -rf /usr/share/doc/mamonsu; rm -rf /usr/share/mamonsu; rm -rf /var/log/mamonsu; rm -rf /var/lib/mamonsu; rm -rf /run/mamonsu
4141
python3 setup.py build && python3 setup.py install
4242
make rpm
43-
sudo mkdir -p /var/log/mamonsu
44-
sudo touch /var/log/mamonsu/mamonsu.log
45-
chmod -R 777 /var/log/mamonsu/
46-
sudo mkdir -p /etc/mamonsu
47-
sudo touch /etc/mamonsu/agent.conf
43+
sudo rpm -i ./mamonsu*.rpm
4844
cat /mamonsu/github-actions-tests/sources/agent_3.4.0.conf > /etc/mamonsu/agent.conf
49-
chmod -R 777 /etc/mamonsu/
50-
sudo yum -y install ./mamonsu*.rpm
5145
systemctl daemon-reload
5246
systemctl restart mamonsu
5347
sleep 5
@@ -69,14 +63,8 @@ elif [ "${OS%:*}" = "ubuntu" ]; then
6963
rm -rf /etc/mamonsu; rm -rf /usr/bin/mamonsu; rm -rf /usr/local/bin/mamonsu; rm -rf /usr/lib/python3/dist-packages/mamonsu; rm -rf /usr/share/doc/mamonsu; rm -rf /usr/share/mamonsu; rm -rf /var/log/mamonsu; rm -rf /var/lib/mamonsu; rm -rf /run/mamonsu
7064
python3 setup.py build && python3 setup.py install
7165
make deb
72-
sudo mkdir -p /var/log/mamonsu
73-
sudo touch /var/log/mamonsu/mamonsu.log
74-
chmod -R 777 /var/log/mamonsu/
75-
sudo mkdir -p /etc/mamonsu
76-
sudo touch /etc/mamonsu/agent.conf
66+
sudo dpkg -i ./mamonsu*.deb
7767
cat /mamonsu/github-actions-tests/sources/agent_3.4.0.conf > /etc/mamonsu/agent.conf
78-
chmod -R 777 /etc/mamonsu/
79-
sudo apt-get -y install ./mamonsu*.deb
8068
service mamonsu restart
8169
sleep 5
8270
echo && echo && echo "Mamonsu version:"

mamonsu/lib/config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
import pwd
23
import socket
34
import os
45
import logging
@@ -79,6 +80,17 @@ def __init__(self, cfg_file=None, plugin_directories=None):
7980
sys.stderr.write('Config file is empty: {0}\n'.format(cfg_file))
8081
sys.exit(1)
8182
if cfg_file is not None:
83+
if platform.LINUX:
84+
config_status = int(repr(oct(os.stat(cfg_file).st_mode))[:-1][-3:])
85+
config_owner = pwd.getpwuid(os.stat(cfg_file).st_uid).pw_name
86+
if not (config_status == 600 and config_owner == "mamonsu"):
87+
logging.info(
88+
"Shut down because of incorrect config file {0} permissions. It must be r/w for mamonsu user only (600).".format(
89+
cfg_file))
90+
sys.stderr.write(
91+
"Please, check your config file {0} permissions. It must be r/w for mamonsu user only (600).\n".format(
92+
cfg_file))
93+
sys.exit(1)
8294
self.config.read_file(open(cfg_file))
8395

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

mamonsu/plugins/pgsql/checkpoint.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ class Checkpoint(Plugin):
2929

3030
("checkpoints_timed", "count_timed",
3131
"by Timeout (in hour)",
32-
("PostgreSQL: checkpoint", "00CC00", 0),
32+
("PostgreSQL Checkpoints: Count (in hour)", "00CC00", 0),
3333
Plugin.UNITS.none, Plugin.DELTA.speed_per_second, 60 * 60),
3434

3535
("checkpoints_req", "count_wal",
3636
"by WAL (in hour)",
37-
("PostgreSQL: Checkpoint", "FF5656", 0),
37+
("PostgreSQL Checkpoints: Count (in hour)", "FF5656", 0),
3838
Plugin.UNITS.none, Plugin.DELTA.speed_per_second, 60 * 60),
3939

4040
("checkpoint_write_time", "write_time",
4141
"Write Time",
42-
("PostgreSQL: Checkpoints", "00CC00", 1),
42+
("PostgreSQL Checkpoints: Write/Sync", "00CC00", 1),
4343
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1),
4444

4545
("checkpoint_sync_time", "checkpoint_sync_time",
4646
"Sync Time",
47-
("PostgreSQL: checkpoints", "FF5656", 1),
47+
("PostgreSQL Checkpoints: Write/Sync", "FF5656", 1),
4848
Plugin.UNITS.ms, Plugin.DELTA.speed_per_second, 1)
4949
]
5050

mamonsu/plugins/system/linux/memory.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class Memory(Plugin):
3636
("vmalloc_used", "VmallocUsed", "VMallocUsed - vmaloc() Allocated by Kernel", "CF6518", 1)
3737
]
3838

39+
graph_name_detailed = "System: Server Memory Detailed Overview"
40+
graph_name_free_used = "System: Server Free/Used Memory Overview"
41+
3942
def run(self, zbx):
4043

4144
meminfo, result = {}, {}
@@ -93,13 +96,13 @@ def graphs(self, template, dashboard=False):
9396
})
9497
graphs = [
9598
{
96-
"name": "System: Server Memory Detailed Overview",
99+
"name": self.graph_name_detailed,
97100
"height": 400,
98101
"type": 1,
99102
"items": all_items
100103
},
101104
{
102-
"name": "System: Server Free/Used Memory Overview",
105+
"name": self.graph_name_free_used,
103106
"height": 400,
104107
"type": 1,
105108
"items": free_used_items

mamonsu/tools/report/pgsql.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,31 @@ class PostgresInfo(object):
162162
'%-dead', '%-heap-hit', '%-idx-hit')
163163
)
164164

165+
query_current_locks = ("""
166+
SELECT blocked_locks.pid AS blocked_pid,
167+
blocking_activity.datname as database,
168+
blocked_activity.usename AS blocked_user,
169+
blocking_locks.pid AS blocking_pid,
170+
blocking_activity.usename AS blocking_user,
171+
blocked_activity.query AS blocked_statement,
172+
coalesce((blocked_activity.state_change - now()), interval '0') AS duration
173+
FROM pg_catalog.pg_locks blocked_locks
174+
JOIN pg_catalog.pg_stat_activity blocked_activity ON blocked_activity.pid = blocked_locks.pid
175+
JOIN pg_catalog.pg_locks blocking_locks ON blocking_locks.locktype = blocked_locks.locktype
176+
AND blocking_locks.database IS NOT DISTINCT FROM blocked_locks.database
177+
AND blocking_locks.relation IS NOT DISTINCT FROM blocked_locks.relation
178+
AND blocking_locks.page IS NOT DISTINCT FROM blocked_locks.page
179+
AND blocking_locks.tuple IS NOT DISTINCT FROM blocked_locks.tuple
180+
AND blocking_locks.virtualxid IS NOT DISTINCT FROM blocked_locks.virtualxid
181+
AND blocking_locks.transactionid IS NOT DISTINCT FROM blocked_locks.transactionid
182+
AND blocking_locks.classid IS NOT DISTINCT FROM blocked_locks.classid
183+
AND blocking_locks.objid IS NOT DISTINCT FROM blocked_locks.objid
184+
AND blocking_locks.objsubid IS NOT DISTINCT FROM blocked_locks.objsubid
185+
AND blocking_locks.pid != blocked_locks.pid
186+
JOIN pg_catalog.pg_stat_activity blocking_activity ON blocking_activity.pid = blocking_locks.pid
187+
WHERE NOT blocked_locks.granted;
188+
""", ("blocked pid", "database", "blocked user", "blocking pid", "blocking user", "blocked statement", "duration"))
189+
165190
def __init__(self, args):
166191
self.args = args
167192
logging.info('Test connection...')
@@ -180,6 +205,8 @@ def __init__(self, args):
180205
self.dblist = self._collect_query(self.QueryDBList)
181206
logging.info('Collect biggest table...')
182207
self.biggest_tables = self._collect_biggest()
208+
logging.info('Collect locks info...')
209+
self.locks = self._collect_locks()
183210

184211
def collect(self):
185212
info = self.printable_info()
@@ -225,6 +252,7 @@ def format_out(info, val):
225252
out += format_out('PG SETTINGS', format_obj(self.settings))
226253
out += format_out('PG DBLIST', format_obj(self.dblist))
227254
out += format_out('TABLES LIST', format_obj(self.biggest_tables))
255+
out += format_out('CURRENT LOCKS', format_obj(self.locks))
228256
return out
229257

230258
def printable_info(self):
@@ -271,6 +299,25 @@ def format_out(key, val):
271299
for key in self.biggest_tables:
272300 F987
out += key_val_h1(
273301
key, self.biggest_tables[key], 30)
302+
for key in self.QueryPgSettings[2]:
303+
out += header_h1(key)
304+
for row in self.settings:
305+
for name in self.QueryPgSettings[2][key]:
306+
if row[0] == name:
307+
val = row[1]
308+
if row[2] is not None:
309+
val += ' {0}'.format(row[2])
310+
val = humansize(val)
311+
out += key_val_h1(
312+
name, val, 30)
313+
out += header_h1('Current Locks')
314+
out += key_val_h1(
315+
self.query_current_locks[1][0],
316+
"\t\t" + "\t\t".join(self.query_current_locks[1][1:]),
317+
30)
318+
for key in self.locks:
319+
out += key_val_h1(
320+
key, self.locks[key], 30)
274321
return out
275322

276323
def _collect_query(self, query_desc):
@@ -326,3 +373,19 @@ def _collect_biggest(self):
326373
for table_name in sorted(result, key=sizes.__getitem__, reverse=True):
327374
sorted_result[table_name] = result[table_name]
328375
return sorted_result
376+
377+
def _collect_locks(self):
378+
result, pids, sorted_result = {}, {}, OrderedDict({})
379+
try:
380+
for info in Pooler.query(self.query_current_locks[0]):
381+
blocked_pid = info[0]
382+
result[blocked_pid] = ''
383+
values = info[1:]
384+
pids[blocked_pid] = values[-1]
385+
for val in values:
386+
result[blocked_pid] = "{0}\t\t{1}".format(result[blocked_pid], val)
387+
except Exception as e:
388+
logging.error("Query locks error: {0}".format(e))
389+
for blocked_pid in sorted(result, key=pids.__getitem__, reverse=True):
390+
sorted_result[blocked_pid] = result[blocked_pid]
391+
return sorted_result

mamonsu/tools/zabbix_cli/dashboard.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from mamonsu.plugins.pgsql.health import PgHealth
99
from mamonsu.plugins.pgsql.instance import Instance
1010
from mamonsu.plugins.pgsql.oldest import Oldest
11-
from mamonsu.plugins.pgsql.pg_buffercache import PgBufferCache
1211
from mamonsu.plugins.pgsql.pg_locks import PgLocks
1312
from mamonsu.plugins.pgsql.replication import Replication
1413
from mamonsu.plugins.pgsql.wal import Wal
@@ -1052,7 +1051,7 @@ def generate_dashboard(template, uuid):
10521051
Connections.graph_name,
10531052
PgLocks.graph_name,
10541053
Instance.graphs_name["transactions"],
1055-
PgBufferCache.graph_name,
1054+
Memory.graph_name_free_used,
10561055
ArchiveCommand.key.format("[" + ArchiveCommand.Items[2][0] + "]"),
10571056
Databases.key_autovacumm.format("[]"),
10581057
BgWriter.graph_name_buffers,

packaging/debian/postinst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if [ "$1" = "configure" ]; then
1818

1919
mkdir -p /etc/mamonsu/plugins
2020
touch /etc/mamonsu/plugins/__init__.py
21-
[ -f /etc/mamonsu/agent.conf ] || cp /usr/share/mamonsu/example_linux.conf /etc/mamonsu/agent.conf
21+
[ -f /etc/mamonsu/agent.conf ] || cp /usr/share/mamonsu/example_linux.conf /etc/mamonsu/agent.conf && chown mamonsu:mamonsu /etc/mamonsu/agent.conf
2222

2323
chown mamonsu:mamonsu /var/log/mamonsu
2424
chown mamonsu:mamonsu /var/lib/mamonsu

packaging/debian/rules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ install: build
2727
binary-indep: build install
2828
dh_testdir -i
2929
dh_testroot -i
30-
install -m 0644 packaging/conf/example_linux.conf debian/mamonsu/usr/share/mamonsu
3130
dh_installchangelogs -i
3231
dh_installinit -i
3332
dh_installdebconf -i
3433
dh_installlogrotate -i
3534
dh_link -i
3635
dh_compress -i
3736
dh_fixperms -i
37+
install -m 0600 -o mamonsu -g mamonsu packaging/conf/example_linux.conf debian/mamonsu/usr/share/mamonsu
3838
dh_installdeb -i
3939
dh_gencontrol -i
4040
dh_md5sums -i

packaging/rpm/SPECS/mamonsu.spec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export PYTHONPATH=%{buildroot}%{python3_sitelib}
3030
%{__mkdir} -p %{buildroot}/%{_sysconfdir}/logrotate.d
3131
%{__mkdir} -p %{buildroot}/%{_datarootdir}/%{name}
3232

33-
%{__install} -m 0644 -p packaging/conf/example_linux.conf %{buildroot}/%{_sysconfdir}/%{name}/agent.conf
33+
%{__install} -m 0600 -p packaging/conf/example_linux.conf %{buildroot}/%{_sysconfdir}/%{name}/agent.conf
3434
%{__install} -m 0644 -p packaging/conf/template_linux.xml %{buildroot}/%{_datarootdir}/%{name}/template.xml
3535
%{__install} -m 0644 -p examples/*.py %{buildroot}/%{_datarootdir}/%{name}/
3636
%{__install} -m 0755 -p %{SOURCE1} %{buildroot}/%{_sysconfdir}/init.d/%{name}
@@ -69,6 +69,9 @@ chown mamonsu.mamonsu /var/log/mamonsu
6969
/sbin/service mamonsu stop >/dev/null 2>&1
7070
/sbin/chkconfig --del mamonsu
7171

72+
%post
73+
chown mamonsu.mamonsu /etc/mamonsu/agent.conf
74+
7275
%changelog
7376
* Mon Feb 21 2022 Alexandra Kuznetsova <a.kuznetsova@postgrespro.ru> - 3.4.0-1
7477
- added Server Version metric;

0 commit comments

Comments
 (0)
0