jmxtrans的作用是自动去jvm中获取所需要的jmx数据,并按照某种格式(json文件配置格式)输出到其他应用程序。
1. Jmxtrans 安装
wget http://central.maven.org/maven2/org/jmxtrans/jmxtrans/264/jmxtrans-264-dist.tar.gz
tar -xzvf jmxtrans-264-dist.tar.gz
cd jmxtrans-264
2.在该目录下新建文件,文件名为kafka.json,写入以下斜体内容。
{
"servers" : [ {
"port" : "xxxx",
"host" :"Kafka_ip",
"queries" : [
{
"outputWriters" : [ {
"@class" :"com.googlecode.jmxtrans.model.output.GraphiteWriterFactory",
"port" : 2003,
"host" :"ip",
"rootPrefix" :"kafka",
"flushStrategy" :"always",
"poolSize" : 10,
"protocol" :"tcp"
} ],
"obj" :"kafka.server:type=BrokerTopicMetrics,name=BytesOutPerSec",
"resultAlias":"TopicMetrics.BytesOutPerSec",
"attr" : [ "Count","OneMinuteRate","FiveMinuteRate", "FifteenMinuteRate" ]
},
{
"outputWriters" : [ {
"@class" :"com.googlecode.jmxtrans.model.output.GraphiteWriterFactory",
"port" : 2003,
"host" :"ip",
"rootPrefix" :"kafka",
"flushStrategy" :"always",
"poolSize" : 10,
"protocol" :"tcp"
} ],
"obj" :"kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec",
"resultAlias":"TopicMetrics.BytesInPerSec",
"attr" : ["Count","OneMinuteRate", "FiveMinuteRate","FifteenMinuteRate" ]
},
{
"outputWriters" : [ {
"@class" :"com.googlecode.jmxtrans.model.output.GraphiteWriterFactory",
"port" : 2003,
"host" :"ip",
"rootPrefix" :"kafka",
"flushStrategy" :"always",
"poolSize" : 10,
"protocol" :"tcp"
} ],
"obj" :"kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec",
"resultAlias":"TopicMetrics.MessagesInPerSec",
"attr" : ["Count","OneMinuteRate", "FiveMinuteRate","FifteenMinuteRate" ]
},
{
"outputWriters" : [ {
"@class" :"com.googlecode.jmxtrans.model.output.GraphiteWriterFactory",
"port" : 2003,
"host" :"ip",
"rootPrefix" :"kafka",
"flushStrategy" :"always",
"poolSize" : 10,
"protocol" :"tcp"
} ],
"obj" :"java.lang:type=Memory",
"resultAlias":"Memory",
"attr" : ["HeapMemoryUsage","NonHeapMemoryUsage" ]
} ],
"numQueryThreads" : 4
} ]
}
下载Jmxtrans的源码之后,发现配置中少了几个属性。不然数据上传不上去。
#启动jmxtrans
$bin /jmxtrans.sh start kafka.json
报错:
Cannot execute /usr/bin/jps -l!, switching to stock ps
File not found - lib/jmxtrans-all.jar
3.更改配置文件内容
~/projects/jmxtrans/jmxtrans-264/bin
$ vi jmxtrans.sh
更改如下:
JAVA_HOME的路径
JAR_FILE的路径
4.打开Graphite界面
Metrics下面有kafka这一文件夹,kafka下面还有Memory 和TopicMetrics的监控信息。
Grafana的监控界面