Hi,
I'm trying to monitor Haproxy with Zabbix but I've got UNSUPPORTED ITEMS.
/home/haproxy.py
Zabbix Agent v1.8.2 (revision 11211) (29 March 2010)
In Zabbix-Server:
If a run "python /home/haproxy.py"
And "zabbix_agentd -t haproxy.srvup"
Someone could help me?
Thanks,
I'm trying to monitor Haproxy with Zabbix but I've got UNSUPPORTED ITEMS.
Code:
UserParameter=haproxy.srvup,/usr/bin/python /home/haproxy.py | grep "Numbers_of_servers_UP" | cut -d: -f2 UserParameter=haproxy.srvdown,/usr/bin/python /home/haproxy.py | grep "Numbers_of_servers_down" | cut -d: -f2 UserParameter=haproxy.nbsessions,/usr/bin/python /home/haproxy.py | grep "Numbers_of_sessions:" | cut -d: -f2 UserParameter=haproxy.bin,/usr/bin/python /home/haproxy.py | grep "Traffic_In" | cut -d: -f2 UserParameter=haproxy.bout,/usr/bin/python /home/haproxy.py | grep "Traffic_Out" | cut -d: -f2
Code:
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
# stdlib
import logging
import socket
from cStringIO import StringIO
from time import time
from traceback import format_exc
logger = logging.getLogger(__name__)
class HAProxyStats(object):
def __init__(self, socket_name=None):
self.socket_name = socket_name
def execute(self, command, extra="", timeout=200):
if extra:
command = command + ' ' + extra
buff = StringIO()
end = time() + timeout
client = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
client.connect(self.socket_name)
client.send(command + '\n')
while time() <= end:
data = client.recv(4096)
if data:
buff.write(data)
else:
return buff.getvalue()
except Exception, e:
msg = 'An error has occurred, e=[{e}]'.format(e=format_exc(e))
logger.error(msg)
raise
finally:
client.close()
if __name__ == '__main__':
stats = HAProxyStats('/tmp/haproxy.sock')
# info = stats.execute('show info')
# print(info)
stat = stats.execute('show stat')
# print(stat)
srvup = 0
srvdown = 0
bytesin = 0
bytesout = 0
csession = 0
array = []
line = []
word = ''
for c in stat:
if c != '\n':
if c != ',':
word += c
else:
line.append(word)
word = ''
else:
if len(line) > 0:
array.append(line)
line = []
for line in array:
if len(line) > 4:
if line[1] == 'BACKEND' and line[0] != "ha_stats":
if (line[17]) == 'UP':
srvup += 1
else:
srvdown += 1
csession += int(line[4])
bytesin += long(line[8])
bytesout += long(line[9])
print ("Numbers_of_servers_UP:" + str(srvup))
print ("Numbers_of_servers_down:" + str(srvdown))
print ("Numbers_of_sessions:" + str(csession))
print ("Traffic_In:" + str(bytesin))
print ("Traffic_Out:" + str(bytesout))
In Zabbix-Server:
Code:
Description: Servers UP Type: Zabbix agent (active) Key: haproxy.srvup Type of information: Numeric (unsigned) Data type: decimal
Code:
Numbers_of_servers_UP:22 Numbers_of_servers_down:0 Numbers_of_sessions:55 Traffic_In:22256984 Traffic_Out:22587416
Code:
haproxy.srvup [m|ZBX_NOTSUPPORTED]
Thanks,
Comment