1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-09-19 09:03:20 +00:00

beanstalkd python3

This commit is contained in:
lifeofguenter 2021-03-09 22:27:45 +01:00 committed by Lars Kruse
parent b6912e7649
commit 58c7801fd2

View file

@ -1,46 +1,53 @@
#!/usr/bin/env python #!/usr/bin/env python3
import sys, re import os
from beanstalk import serverconn, protohandler import sys
# Temporary workaround until my patch is merged. from pystalk import BeanstalkClient
if not protohandler._namematch.match('ABZDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-+/;.$_()'):
protohandler._namematch = re.compile(r'^[a-zA-Z0-9+\(\)/;.$_][a-zA-Z0-9+\(\)/;.$_-]{0,199}$')
STATES = ['ready', 'reserved', 'urgent', 'delayed', 'buried'] STATES = ['ready', 'reserved', 'urgent', 'delayed', 'buried']
def connect(host='localhost', port=11300):
return serverconn.ServerConn(host, port) def connect():
return BeanstalkClient(
os.getenv('host', 'localhost'),
os.getenv('port', '11300'),
)
def config(): def config():
c = connect() c = connect()
tubes = c.list_tubes()['data'] tubes = c.list_tubes()
print_config(tubes) print_config(tubes)
def print_config(tubes, graph_title='Beanstalkd jobs', graph_vlabel='count'): def print_config(tubes, graph_title='Beanstalkd jobs', graph_vlabel='count'):
for tube in tubes: for tube in tubes:
print 'multigraph job_count_' + tube print(f'multigraph job_count_{tube}')
print 'graph_title %s (%s)' % (graph_title, tube,) print(f'graph_title {graph_title} ({tube})')
print 'graph_order ' + ' '.join(STATES) print(f'graph_order {" ".join(STATES)}')
print 'graph_vlabel ' + graph_vlabel print(f'graph_vlabel {graph_vlabel}')
for state in STATES: for state in STATES:
print '%s.label %s' % (state, state,) print(f'{state}.label {state}')
print print()
def run(): def run():
c = connect() c = connect()
tubes = c.list_tubes()['data'] tubes = c.list_tubes()
print_values(tubes, c) print_values(tubes, c)
def print_values(tubes, c): def print_values(tubes, c):
for tube in tubes: for tube in tubes:
print 'multigraph job_count_' + tube print(f'multigraph job_count_{tube}')
stats = c.stats_tube(tube)['data'] stats = c.stats_tube(tube)
for state in STATES: for state in STATES:
key = 'current-jobs-' + state key = 'current-jobs-' + state
value = stats[key] value = stats[key]
print '%s.value %d' % (state, value,) print(f'{state}.value {value}')
print print()
def main(): def main():
if len(sys.argv) > 1 and sys.argv[1] == "config": if len(sys.argv) > 1 and sys.argv[1] == "config":
@ -48,5 +55,6 @@ def main():
else: else:
run() run()
if __name__ == "__main__": if __name__ == "__main__":
main() main()