Stub of a collectd role for fedmsg process health.

This commit is contained in:
Ralph Bean 2014-04-30 16:04:47 +00:00
parent 26b3dffd89
commit b5f6044085
3 changed files with 90 additions and 0 deletions

View file

@ -0,0 +1,72 @@
#!/usr/bin/env python
""" fedmsg-service-collectd.py -- produce collectd stats on fedmsg daemons """
import json
import os
import pprint
import socket
import sys
import time
import zmq
hostname = socket.gethostname().split('.')[0]
def print_consumer(service, consumer):
timestamp = int(time.time())
print "PUTVAL %s/%s/queue_length-%s interval=5 %i:%i" % (
hostname,
service,
'%s_backlog' % consumer['name'],
timestamp,
consumer['backlog']
)
print "PUTVAL %s/%s/gauge-%s interval=5 %i:%i" % (
hostname,
service,
'%s_exceptions' % consumer['name'],
timestamp,
consumer['exceptions']
)
def print_producer(service, producer):
timestamp = int(time.time())
print "PUTVAL %s/%s/gauge-%s interval=5 %i:%i" % (
hostname,
service,
'%s_exceptions' % producer['name'],
timestamp,
producer['exceptions']
)
if __name__ == '__main__':
service, = sys.argv[-1:]
fname = '/var/run/fedmsg/monitoring-%s.socket' % service
if not os.path.exists(fname):
print "UNKNOWN - %s does not exist" % fname
sys.exit(3)
connect_to = "ipc:///%s" % fname
ctx = zmq.Context()
s = ctx.socket(zmq.SUB)
s.connect(connect_to)
s.setsockopt(zmq.SUBSCRIBE, '')
try:
while True:
msg = s.recv()
msg = json.loads(msg)
for consumer in msg['consumers']:
if consumer['initialized']:
print_consumer(service, consumer)
for producer in msg['producers']:
if producer['initialized']:
print_producer(service, producer)
except KeyboardInterrupt:
pass

View file

@ -0,0 +1,14 @@
---
- name: Copy in /usr/local/bin/fedmsg-service-collectd
copy: >
src=fedmsg-service-collectd.py
dest=/usr/local/bin/fedmsg-service-collectd
mode=0755
notify: restart collectd
- name: Copy in /etc/collectd.d/fedmsg-service.conf
template: >
src=fedmsg-service.conf
dest=/etc/collectd.d/{{ process }}-conf
notify: restart collectd

View file

@ -0,0 +1,4 @@
LoadPlugin exec
<Plugin exec>
Exec "{{ process }}" "/usr/local/bin/fedmsg-service-collectd {{ process }}"
</Plugin>