jmxtrans docker-compose 运行
以下是一个简单的demo,使用jmxtrans 进行jmx 指标的处理,项目使用docker-compose 运行
同时写入数据到graphite
环境准备
- docker-compose文件
version: "3"
services:
graphite:
image: graphiteapp/graphite-statsd
ports:
- "80:80"
- "2003-2004:2003-2004"
- "2023-2024:2023-2024"
- "8125:8125/udp"
- "8126:8126"
jmxtrans:
build:
context: ./
dockerfile: Dockerfile-jmxtrans
app:
build: ./
image: dalongrong/java-jmx-openjdk
container_name: app
ports:
- "8080:8080"
- "30384:30384"
- dockerfile 说明
包含了一个spring boot 的项目app
Dockerfile
FROM openjdk:8u222-jdk
LABEL AUTHOR="dalongrong"
LABEL EMAIL="1141591465@qq.com"
WORKDIR /
COPY webapi-0.0.1-SNAPSHOT.jar /webapi-0.0.1-SNAPSHOT.jar
COPY docker-entrypiont.sh /docker-entrypiont.sh
RUN chmod +x /docker-entrypiont.sh
EXPOSE 30384 8080
ENTRYPOINT [ "/docker-entrypiont.sh" ]
docker-entrypiont.sh:
#!/bin/sh
java \
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=30384 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.rmi.port=30384 \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.host=app \
-Djava.rmi.server.hostname=app \
-jar /webapi-0.0.1-SNAPSHOT.jar
jmxtrans Dockerfile-jmxtrans
#!/bin/sh
java -jar /jmxtrans-270-all.jar -f /jmxtrans.json
jmxtrans 配置json 文件jmxtrans.json
{
"servers": [{
"port": "30384",
"host": "app",
"numQueryThreads" : 4,
"queries": [
{
"obj": "Tomcat:type=ThreadPool,name=\"http-nio-8080\"",
"resultAlias":"http-nio-8080",
"attr": ["acceptCount","currentThreadsBusy","currentThreadCount"],
"outputWriters": [{
"@class": "com.googlecode.jmxtrans.model.output.GraphiteWriterFactory",
"port": 2003,
"host": "graphite",
"rootPrefix":"webapi",
"typeNames" : ["name"],
"flushStrategy" :"always",
"poolSize" : 10
}]
},
{
"obj": "java.lang:type=Memory",
"resultAlias":"Memory",
"attr" : [ "HeapMemoryUsage", "NonHeapMemoryUsage" ],
"outputWriters": [{
"@class": "com.googlecode.jmxtrans.model.output.GraphiteWriterFactory",
"port": 2003,
"host": "graphite",
"rootPrefix":"webapi",
"typeNames" : ["name"],
"flushStrategy" :"always",
"poolSize" : 10
}]
}
,
{
"obj": "java.lang:type=ClassLoading",
"resultAlias":"ClassLoading",
"attr": ["TotalLoadedClassCount","LoadedClassCount","UnloadedClassCount"],
"outputWriters": [{
"@class": "com.googlecode.jmxtrans.model.output.GraphiteWriterFactory",
"port": 2003,
"rootPrefix":"webapi",
"typeNames" : ["name"],
"flushStrategy" :"always",
"poolSize" : 10,
"host": "graphite"
}]
}
]
}]
}
配置说明
- jmx 服务app
主要是通过运行的时候启动jmx 配置,具体可以参考docker-entrypiont.sh - jmxtrans
通过docker 运行,主要是配置文件jmxtrans.json 添加了几个查询,同时通过GraphiteWriter
写入数据到Graphite
几个参数的说明,如果看了官方的wiki 以及代码就会发现,有几个参数是必须写的,但是wiki 不是很清楚
主要是rootPrefix
,flushStrategy
,typeNames
启动&&测试
- 启动
docker-compose up -d
- 效果
说明
以上是一个简单的docker-compose 运行,实际上我们可以进行扩展,添加更多的jmx 指标,对于kuberntes 的运行方式,可以参考类似的方式,只是
我们可以使用localhost 在pod 中运行多个容器的方式解决,还是比较方便的
参考资料
https://github.com/jmxtrans/jmxtrans/wiki/GraphiteWriter
https://github.com/jmxtrans/jmxtrans/wiki/Queries
https://github.com/rongfengliang/openjdk-docker-jmx/tree/jmxtrans
https://github.com/rongfengliang/jmxtrans-docker-compose
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2018-07-22 goaccess nginx日志分析工具简单使用
2015-07-22 WebApiThrottle限流框架