JMX to Graphite every x seconds in one command line
100K+
jmx2graphite is a one liner tool for polling JXM and writes into Graphite (every 30 seconds by default). You install & run it on every machine you want to poll its JMX.
Currently it only reads JMX from a jolokia agent running on a JVM, since exposing JMX is the simplest and easiest through Jolokia agent (1 liner - see below).
The reporting to graphite is done through the Pickle protocol, hence by default port 2004, since it's more efficient.
The metrics reported have the following names template:
[service-name].[service-host].[metric-name]
If you don't have docker, install it first - instructions here.
docker run -i -t -d --name jmx2graphite \
-e "JOLOKIA_URL=http://172.1.1.2:11001/jolokia/" \
-e "SERVICE_NAME=MyApp" \
-e "GRAPHITE_HOST=graphite.foo.com" \
-v /var/log/jmx2graphite:/var/log/jmx2graphite \
--rm=true
logzio/jmx2graphite
Environment variables
Rest of command
-v /var/log/jmx2graphite:/var/log/jmx2graphite: jmx2graphite by defaults writes its log (using Logback) to /var/log/jmx2graphite. This argument maps this directory to the host directory so you can easily view the logs from the place you run the docker command--rm=true: removes the docker image created upon using docker run command, so you can just call docker run command again.-javaagent:path-to-jolokia-jar-file.jar
For example:
-javaagent:/opt/jolokia/jolokia-jvm-1.3.2-agent.jar
By default it exposes an HTTP REST interface on port 8778. See here if you want to change it and configure it more. We run all of ours apps using Docker, so to avoid clashes when we map the 8778 port to a unique external port belonging only to this application.
If you never installed Graphite, this small guide below might be a good place to start. I'm using Docker since it's very easy to install this way.
We will install Graphite using a great docker image by hopsoft. I tried several and it was by far the easiest to work with.
Run the following to get basic Graphite up and running
docker run -d \
--name graphite \
-p 80:80 \
-p 2003:2003 \
-p 2004:2004 \
-p 8125:8125/udp \
-p 8126:8126
Now, let's copy out all of its existing configuration files so it will be easy to modify. I will assume you will place it at /home/ubuntu
cd /home/ubuntu
mkdir graphite
docker cp graphite:/opt/graphite/conf graphite
docker cp graphite:/opt/graphite/webapp/graphite graphite/webapp
Stop graphite by running docker stop graphite
Configuring Graphite: Now edit the following files:
/home/ubuntu/graphite/conf/carbon.conf:
/home/ubuntu/graphite/conf/storage-schemas.conf:
[default_1min_for_1day]
pattern = .*
retentions = 30s:24h,1min:7d,10min:1800d
If you have 10s:24h then when doing derivative, you will get null values for each missing 2 points in the 30sec window and the graph will be empty
Create some directories which normally are crearted by the docker image but since we're mounting /var/log to an empty directory of ours in the host, they don't exists:
mkdir -p /home/ubuntu/log/nginx
mkdir -p /home/ubuntu/log/carbon
mkdir -p /home/ubuntu/log/graphite
Run Graphite. I use the following short bash script run-graphite.sh:
#!/bin/bash
docker run -d \
--name graphite \
--rm=true \
--restart=always \
-p 80:80 \
-p 2003:2003 \
-p 2004:2004 \
-p 8125:8125/udp \
-p 8126:8126 \
-v /home/ubuntu/graphite/storage:/opt/graphite/storage \
-v /home/ubuntu/log:/var/log \
-v /home/ubuntu/graphite/conf:/opt/graphite/conf \
-v /home/ubuntu/graphite/webapp/graphite:/opt/graphite/webapp/graphite \
hopsoft/graphite-statsd
If you have an existing Graphite installation see the section above "configuring Graphite: Now edit the following files:".
I was looking for a tool I can just drop in place, have a 1-liner run command which will then run every 10 seconds, poll my JVM JMX entirely and dump it to Graphite. Of course I started Googling and saw the following:
JMXTrans I had several issues which got me stomped:
jmxproxy It's an HTTP REST server allowing you to fetch mbeans from a given JVM using REST to it. You are supposed to have one per your cluster. Great work there. The biggest drawback here was that you have to specify a predefined list of mbeans to retrieve - I wanted it all - it's too much work to compose the list of mbeans for: Camel, Kafka, Zookeeper, your own, etc.
Sensu plugin - Aside from the prequisite of Sensu, again you must supply a predefined list of beans.
Collectd plugin - Must have collectd and also, same as before, specify a list of mbeans and their attributes in a quite complicated config file. This also requires installing another collectd plugin.
Fluentd JMX plugin - Must have fluentd installed. Must specify list of mbeans and their attributes. Works against Jolokia only (same as jmx2graphite)
So after spending roughly 1.5 days fighting with those tools and not getting what I wanted, I sat down to write my own.
Docker enables jmx2graphite to install and run in one command line! Just about any other solution will requires more steps for installation, and not to mention the development efforts.
We welcome any contribution! You can help in the following way:
TBD
#License
See the LICENSE file for license rights and limitations (MIT).
Content type
Image
Digest
sha256:51daef5cc…
Size
87.5 MB
Last updated
about 4 years ago
docker pull logzio/jmx2graphite