-
Notifications
You must be signed in to change notification settings - Fork 146
Exporting jHiccup metrics
Tomasz Grabiec edited this page Sep 19, 2016
·
3 revisions
Download jHiccup:
wget http://www.azul.com/files/jHiccup-2.0.6-dist.tar.gz
tar xvzf jHiccup-2.0.6-dist.tar.gz
Save the following script as jhiccup_exporter
, make executable, and put on PATH
:
#!/usr/bin/env python
#
# Exports jHiccup statistics from jHiccup log to collectd.
#
# Getting jHiccup agent:
#
# wget http://www.azul.com/files/jHiccup-2.0.6-dist.tar.gz
# tar xvzf jHiccup-2.0.6-dist.tar.gz
#
# Running the Java client to be monitored:
#
# export _JAVA_OPTIONS="$_JAVA_OPTIONS -javaagent:jHiccup-2.0.6/jHiccup.jar=\"-l hiccup.log -d 0 -i 1000\""
# cassandra-stress …
#
# Running this exporter:
#
# tail -f hiccup.log | ./jhiccup_exporter
#
# Exports the following metrics (in milliseconds):
#
# jhiccup-0/gauge-hiccup_max
#
import sys
import socket
import os
import time
hostname = socket.gethostname().split('.')[0]
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
server.connect('/var/run/collectd-unixsock')
def readlines(sock, recv_buffer=4096, delim='\n'):
buffer = ''
data = True
while data:
data = sock.recv(recv_buffer)
buffer += data
while buffer.find(delim) != -1:
line, buffer = buffer.split('\n', 1)
yield line
return
class ValuePack:
def __init__(self):
self.messages = []
self.time = time.time()
def add(self, plugin, plugin_instance, type, type_instance, val):
self.messages.append('PUTVAL "%s/%s-%s/%s-%s" %f:%f\n' % (hostname, plugin, plugin_instance, type, type_instance, self.time, val))
def send(self):
for msg in self.messages:
server.send(msg)
lines = readlines(server)
for msg in self.messages:
reply = next(lines)
if not reply.startswith('0 Success'):
print('collectd error: ' + reply)
start_time = time.time()
plugin = 'jhiccup'
plugin_instance = '0'
with os.fdopen(sys.stdin.fileno(), 'r', 1) as input:
while True:
line = sys.stdin.readline()
if line.startswith('#') or line.startswith('"'):
continue
if time.time() - start_time < 1.0: # Skip existing lines
continue
cols = line.split(',')
hiccup_max = float(cols[2].rstrip(','))
pack = ValuePack()
pack.add(plugin, plugin_instance, 'gauge', 'hiccup_max', hiccup_max)
pack.send()
server.close()
collectd must be configured with the UNIX socket plugin. The script assumes that the collectd socket is at /var/run/collectd-unixsock
.
Run the Java client to be monitored like this:
export _JAVA_OPTIONS="$_JAVA_OPTIONS -javaagent:jHiccup-2.0.6/jHiccup.jar=\"-l hiccup.log -d 0 -i 1000\""
cassandra-stress …
Then run the exporter on the log file:
tail -f hiccup.log | jhiccup_exporter
It will export the following collectd metric (maximum delay in milliseconds):
jhiccup-0/gauge-hiccup_max
You don't have to restart the exporter when restarting cassandra-stress (that's due to tail -f
).