forked from samuel/python-munin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostgres_locks
More file actions
executable file
·50 lines (44 loc) · 1.2 KB
/
postgres_locks
File metadata and controls
executable file
·50 lines (44 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Based on a Perl plugin by an unknown author.
Show postgres lock statistics.
"""
from munin.postgres import MuninPostgresPlugin
class MuninPostgresLocksPlugin(MuninPostgresPlugin):
dbname_in_args = False
title = "Postgres locks"
args = "--base 1000"
vlabel = "Locks"
info = "Shows Postgresql locks"
fields = (
('locks', dict(
label = "Locks",
info = "Locks",
type = "GAUGE",
warning = 10,
critical = 20,
)),
('exlocks', dict(
label = "Exclusive locks",
info = "Exclusive locks",
type = "GAUGE",
warning = 5,
critical = 10,
)),
)
def execute(self):
c = self.cursor()
c.execute("SELECT mode, COUNT(mode) FROM pg_locks GROUP BY mode ORDER BY mode")
locks = 0
exlocks = 0
for row in c.fetchall():
if 'exclusive' in row[0].lower():
exlocks += row[1]
locks += row[1]
return dict(
locks = locks,
exlocks = exlocks,
)
if __name__ == "__main__":
MuninPostgresLocksPlugin().run()