Created
May 4, 2016 09:38
-
-
Save vadv/513c2272ced9ebf19b3e3f40068946f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dmitry Vasilyev@WIN-N79ERR9IL9S MSYS /c/agent | |
$ ./mamonsu.exe -e template.xml -c agent.conf | |
[INFO] 2016-05-04 12:37:31,143 - root - Import module 'ExtPlugins' from directory C:\agent\ExtPlugins | |
[INFO] 2016-05-04 12:37:31,144 - root - Import plugin 'ExamplePlugin' from module 'ExtPlugins' | |
[INFO] 2016-05-04 12:37:31,145 - root - Import plugin 'StatementStats' from module 'ExtPlugins' | |
Dmitry Vasilyev@WIN-N79ERR9IL9S MSYS /c/agent | |
$ cat ExtPlugins/ | |
__init__.py __pycache__/ ExamplePlugin.py StatementStats.py | |
Dmitry Vasilyev@WIN-N79ERR9IL9S MSYS /c/agent | |
$ cat ExtPlugins/ExamplePlugin.py | |
# -*- coding: utf-8 -*- | |
from mamonsu.lib.plugin import Plugin | |
from mamonsu.plugins.pgsql.pool import Pooler | |
# Count all queries running more then 5 minutes | |
class ExamplePlugin(Plugin): | |
# execute method run() every 60s | |
Interval = 60 | |
def run(self, zbx): | |
# execute query on default database | |
result = Pooler.query(""" | |
select | |
count(*) | |
from pg_catalog.pg_stat_activity | |
where | |
state <> 'idle' and | |
now() - pg_stat_activity.query_start > interval '5 minutes' | |
""") | |
# send a resulting value to zabbix | |
zbx.send('pgsql.queries.long_count[]', result[0][0]) | |
# debug message | |
self.log.debug('some information for debug') | |
# Declare zabbix items for template | |
def items(self, template): | |
# debug message | |
self.log.debug('Declare zabbix items for template') | |
return template.item({ | |
'name': 'Count of long running queries', | |
'key': 'pgsql.queries.long_count[]' | |
}) | |
# Declare zabbix graphs for template | |
def graphs(self, template): | |
self.log.debug('Declare zabbix graps for template') | |
items = [ | |
{ | |
'key': 'pgsql.queries.long_count[]', | |
'color': 'DF0101', | |
'yaxisside': 0 | |
} | |
] | |
graph = {'name': 'PostgreSQL long running queries', 'items': items} | |
return template.graph(graph) | |
# Declare zabbix trigger for template | |
def triggers(self, template): | |
return template.trigger({ | |
'name': "Long running queries ({HOSTNAME}: {ITEM.LASTVALUE})", | |
'expression': "{#TEMPLATE:pgsql.queries.long_count[].last()}<10" | |
}) | |
Dmitry Vasilyev@WIN-N79ERR9IL9S MSYS /c/agent | |
$ ./mamonsu.exe -e template.xml -c agent.conf | |
[INFO] 2016-05-04 12:37:41,420 - root - Import module 'ExtPlugins' from directory C:\agent\ExtPlugins | |
[INFO] 2016-05-04 12:37:41,421 - root - Import plugin 'ExamplePlugin' from module 'ExtPlugins' | |
[INFO] 2016-05-04 12:37:41,422 - root - Import plugin 'StatementStats' from module 'ExtPlugins' | |
Dmitry Vasilyev@WIN-N79ERR9IL9S MSYS /c/agent | |
$ cat template.xml | grep -i 'Long run' | |
Двоичный файл (стандартный ввод) совпадает | |
Dmitry Vasilyev@WIN-N79ERR9IL9S MSYS /c/agent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment