jmx2graphite
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.
bashdocker 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 ***es 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 https://github.com/hopsoft/docker-graphite-statsd. 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:
bashmkdir -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:
bash#!/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:
https://github.com/jmxtrans/jmxtrans I had several issues which got me stomped:
https://github.com/mk23/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.
https://github.com/sensu/sensu-community-plugins/blob/master/plugins/http/http-json-graphite.rb - 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.
https://github.com/niyonmaruz/fluent-plugin-jmx - 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).
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
docker search 限制
站内搜不到镜像
离线 save/load
插件要用 plugin install
WSL 拉取慢
安全与 digest
新手拉取配置
镜像合规机制
不支持 push
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
域名连通性排查
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务