Kafka使用jmxtrans+influxdb+grafana监控JMX指标(2)

#创建数据库
create database "db_name"
#显示所有的数据库
show databases
#删除数据库
drop database "db_name"
#使用数据库
use db_name
#显示该数据库中所有的表
show measurements
#创建表,直接在插入数据的时候指定表名
insert test,host=127.0.0.1,monitor_name=test count=1
#删除表
drop measurement "measurement_name"
#退出
quit

安装jmxtrans

jmxtrans的作用是自动去jvm中获取所有jmx格式数据,并按照某种格式(json文件配置格式)输出到其他应用程序(本例中的influxDB)。

下载jmxtrans rpm安装包

wget
--2019-04-10 03:18:14-- 
Resolving central.maven.org (central.maven.org)... 151.101.40.209
Connecting to central.maven.org (central.maven.org)|151.101.40.209|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 18750744 (18M) [application/x-rpm]
Saving to: ‘jmxtrans-270.rpm’

100%[================================================================================================================================================================================>] 18,750,744 342KB/s in 43s

2019-04-10 03:18:59 (422 KB/s) - ‘jmxtrans-270.rpm’ saved [18750744/18750744]

安装rpm包

rpm -ivh jmxtrans-270.rpm
Preparing... ################################# [100%]
Updating / installing...
 1:jmxtrans-270-1 ################################# [100%]

jmxtrans相关路径

jmxtrans安装目录:/usr/share/jmxtrans
json文件默认目录:/var/lib/jmxtrans/
日志路径:/var/log/jmxtrans/jmxtrans.log

配置json,jmxtrans的github上有一段示例配置

{
  "servers" : [ {
    "port" : "1099",
    "host" : "w2",
    "queries" : [ {
      "obj" : "java.lang:type=Memory",
      "attr" : [ "HeapMemoryUsage", "NonHeapMemoryUsage" ],
      "resultAlias":"jvmMemory",
      "outputWriters" : [ {
        "@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory",
        "url" : "http://127.0.0.1:8086/",
        "username" : "admin",
        "password" : "admin",
        "database" : "jmxDB",
        "tags"    : {"application" : "kafka"}
      } ]
    } ]
  } ]
}

host:监控服务器

port:jmx端口

obj:对应jmx的ObjectName,就是我们要监控的指标

attr:对应ObjectName的属性,可以理解为我们要监控的指标的值

resultAlias:对应metric 的名称,在InfluxDB里面就是MEASUREMENTS名

tags:对应InfluxDB的tag功能,对与存储在同一个MEASUREMENTS里面的不同监控指标可以做区分,我们在用Grafana绘图的时候会用到,建议对每个监控指标都打上tags

启动jmxtrans

service jmxtrans start
Starting JmxTrans...

查看日志没有报错即为成功

tail /var/log/jmxtrans/jmxtrans.log
INFO  | jvm 1    | 2019/04/10 04:44:31 |  Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
INFO  | jvm 1    | 2019/04/10 04:44:31 |  Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.
INFO  | jvm 1    | 2019/04/10 04:44:31 |
INFO  | jvm 1    | 2019/04/10 04:44:31 | 2019-04-10 04:44:31 [WrapperSimpleAppMain] INFO  org.quartz.impl.StdSchedulerFactory - Quartz scheduler 'ServerScheduler' initialized from an externally opened InputStream.
INFO  | jvm 1    | 2019/04/10 04:44:31 | 2019-04-10 04:44:31 [WrapperSimpleAppMain] INFO  org.quartz.impl.StdSchedulerFactory - Quartz scheduler version: 1.8.6
INFO  | jvm 1    | 2019/04/10 04:44:31 | 2019-04-10 04:44:31 [WrapperSimpleAppMain] INFO  org.quartz.core.QuartzScheduler - JobFactory set to: com.googlecode.jmxtrans.guice.GuiceJobFactory@23822296
2019-04-10 04:44:31 [WrapperSimpleAppMain] level com.googlecode.jmxtrans.JmxTransformer [JmxTransformer.java:177] - Starting Jmxtrans on : /var/lib/jmxtrans
2019-04-10 04:44:31 [WrapperSimpleAppMain] level org.quartz.core.QuartzScheduler [QuartzScheduler.java:519] - Scheduler ServerScheduler_$_node11554885871753 started.
INFO  | jvm 1    | 2019/04/10 04:44:31 | 2019-04-10 04:44:31 [WrapperSimpleAppMain] INFO  c.googlecode.jmxtrans.JmxTransformer - Starting Jmxtrans on : /var/lib/jmxtrans
INFO  | jvm 1    | 2019/04/10 04:44:31 | 2019-04-10 04:44:31 [WrapperSimpleAppMain] INFO  org.quartz.core.QuartzScheduler - Scheduler ServerScheduler_$_node11554885871753 started.

附上两段通用的json文件

base_127.0.0.1.json

View Code
  topicA_1.json

View Code
  安装Grafana

Grafana是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知。

下载jmxtrans rpm安装包

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/6c9d2b24e66e4d4e601f49a516ffa762.html