Skip to content

Commit 7eb9a25

Browse files
author
Dmitry Vasilyev
committed
Connect via unix_socket, keep alive log message
1 parent e8c1a01 commit 7eb9a25

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

mamonsu/plugins/pgsql/_connection.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ def _check_connect(self):
4949
if not self.query_completed_succ:
5050
self.log.debug('[db: {0}] Connecting...'.format(self.database))
5151
self._close()
52+
host, unix_sock = os.environ.get('PGHOST'), None
53+
if host.startswith('/'):
54+
unix_sock, host = host, None
5255
self.conn = connect(
5356
user=os.environ.get('PGUSER'),
5457
password=os.environ.get('PGPASSWORD'),
55-
host=os.environ.get('PGHOST'),
58+
unix_sock=unix_sock,
59+
host=host,
5660
port=int(os.environ.get('PGPORT') or 5432),
5761
database=self.database
5862
)

mamonsu/plugins/pgsql/health.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def __init__(self, config):
1515
# алертим, если cache hit меньше чем %
1616
self.TriggerCacheHitLessThen = self.config.fetch(
1717
'health', 'cache', int)
18+
# счетчик, для сообщения в лог
19+
self.counter = 0
1820

1921
def run(self, zbx):
2022

@@ -31,6 +33,11 @@ def run(self, zbx):
3133
from pg_stat_database')
3234
zbx.send('pgsql.cache[hit]', int(result[0][0]))
3335

36+
self.counter += 1
37+
if self.counter > 9:
38+
self.log.info('=== Keep alive ===')
39+
self.counter = 0
40+
3441
def items(self, template):
3542
result = template.item({
3643
'name': 'PostgreSQL: ping',

0 commit comments

Comments
 (0)