jmxtrans+influxdb+grafana监控zookeeper实战

Wesley13
• 阅读 709

本文主要研究一下如何使用jmxtrans+influxdb+granfa监控zookeeper

配置zookeeper jmx

在conf目录下新增zookeeper-env.sh,并使用chmod +x赋予执行权限,内容如下

JMXLOCALONLY=false
JMXDISABLE=false
JMXPORT=8999
JMXAUTH=false
JMXSSL=false
  • 指定JMXPORT为8999

搭建influxdb及grafana

这里使用docker构建,如下

docker network create monitoring-network
docker run -d -p 8083:8083 -p 8086:8086 \
    --net monitoring-network  \
    --name influxdb  \
    influxdb:1.5.4
curl -POST http://192.168.99.100:8086/query --data-urlencode "q=CREATE DATABASE zookeeper"
docker run -d -p 3000:3000 --net monitoring-network --name grafana grafana/grafana:5.2.4
curl 'http://admin:admin@192.168.99.100:3000/api/datasources' -X POST \
-H 'Content-Type: application/json;charset=UTF-8' \
--data-binary '{"name":"influx","type":"influxdb","url":"http://192.168.99.100:8086",
"access":"proxy","isDefault":true,"database":"zookeeper","user":"admin","password":"admin"}'
  • 创建monitoring-network,让docker中的influxdb与grafana连通,然后使用rest api创建zookeeper数据库
  • 创建grafana并指定net为monitoring-network,然后使用rest api配置数据源

jmxtrans配置

  • 下载jmxtrans

    wget http://central.maven.org/maven2/org/jmxtrans/jmxtrans/270/jmxtrans-270-all.jar

  • 下载执行脚本

    wget -q https://raw.githubusercontent.com/jmxtrans/jmxtrans/master/jmxtrans/jmxtrans.sh chmod +x jmxtrans.sh

  • 配置zookeeper.json

    { "servers": [ { "port": 8999, "host": "localhost", "alias": "zk", "queries": [ { "outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory", "url" : "http://192.168.99.100:8086/", "database" : "zookeeper", "username" : "admin", "password" : "admin" } ], "obj": "org.apache.ZooKeeperService:name0=ReplicatedServer_id*", "attr": [ "QuorumSize" ] }, { "outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory", "url" : "http://192.168.99.100:8086/", "database" : "zookeeper", "username" : "admin", "password" : "admin" } ], "obj": "org.apache.ZooKeeperService:name0=ReplicatedServer_id*,name1=replica*,name2=", "attr": [ "MaxClientCnxnsPerHost", "MaxRequestLatency", "AvgRequestLatency", "MinRequestLatency", "MaxSessionTimeout", "MinSessionTimeout", "OutstandingRequests", "PacketsReceived", "PacketsSent", "PendingRevalidationCount", "TickTime" ] }, { "outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory", "url" : "http://192.168.99.100:8086/", "database" : "zookeeper", "username" : "admin", "password" : "admin" } ], "obj": "org.apache.ZooKeeperService:name0=ReplicatedServer_id,name1=replica*,name2=,name3=InMemoryDataTree", "attr": [ "NodeCount", "WatchCount" ] }, { "outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory", "url" : "http://192.168.99.100:8086/", "database" : "zookeeper", "username" : "admin", "password" : "admin" } ], "obj": "org.apache.ZooKeeperService:name0=ReplicatedServer_id,name1=replica*,name2=,name3=Connections,name4=,name5=", "resultAlias": "Clients", "attr": [ "AvgLatency", "LastLatency", "MaxLatency", "MinLatency", "OutstandingRequests", "PacketsReceived", "PacketsSent" ] }, { "outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory", "url" : "http://192.168.99.100:8086/", "database" : "zookeeper", "username" : "admin", "password" : "admin" } ], "obj": "org.apache.ZooKeeperService:name0=StandaloneServer_port", "resultAlias": "Clients", "attr": [ "AvgLatency", "LastLatency", "MaxLatency", "MinLatency", "OutstandingRequests", "PacketsReceived", "PacketsSent", "NumAliveConnections" ] }, { "outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory", "url" : "http://192.168.99.100:8086/", "database" : "zookeeper", "username" : "admin", "password" : "admin" } ], "obj": "java.lang:type=Memory", "resultAlias": "Memory", "attr": [ "HeapMemoryUsage", "NonHeapMemoryUsage" ] }, { "outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory", "url" : "http://192.168.99.100:8086/", "database" : "zookeeper", "username" : "admin", "password" : "admin" } ], "obj": "java.lang:type=OperatingSystem", "resultAlias": "Process", "attr": [ "OpenFileDescriptorCount", "ProcessCpuLoad" ] }, { "outputWriters" : [ { "@class" : "com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory", "url" : "http://192.168.99.100:8086/", "database" : "zookeeper", "username" : "admin", "password" : "admin" } ], "obj": "java.lang:type=Threading", "resultAlias": "Threading", "attr": [ "ThreadCount" ] } ], "numQueryThreads": 2 } ] }

放在跟jmxtrans.sh脚本同一个目录下即可自动加载

  • 启动

    JAR_FILE=jmxtrans-270-all.jar ./jmxtrans.sh start

  • 日志输出实例

    2018-10-04 11:28:30 [main] level org.quartz.impl.StdSchedulerFactory [StdSchedulerFactory.java:1179] - Using default implementation for ThreadExecutor 2018-10-04 11:28:30 [main] level org.quartz.core.SchedulerSignalerImpl [SchedulerSignalerImpl.java:60] - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl 2018-10-04 11:28:30 [main] level org.quartz.core.QuartzScheduler [QuartzScheduler.java:229] - Quartz Scheduler v.1.8.6 created. 2018-10-04 11:28:30 [main] level org.quartz.simpl.RAMJobStore [RAMJobStore.java:139] - RAMJobStore initialized. 2018-10-04 11:28:30 [main] level org.quartz.core.QuartzScheduler [QuartzScheduler.java:255] - Scheduler meta-data: Quartz Scheduler (v1.8.6) 'ServerScheduler' with instanceId 'Mars.local1538623710548' Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally. NOT STARTED. Currently in standby mode. Number of jobs executed: 0 Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads. Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.

    2018-10-04 11:28:30 [main] level org.quartz.impl.StdSchedulerFactory [StdSchedulerFactory.java:1324] - Quartz scheduler 'ServerScheduler' initialized from an externally opened InputStream. 2018-10-04 11:28:30 [main] level org.quartz.impl.StdSchedulerFactory [StdSchedulerFactory.java:1328] - Quartz scheduler version: 1.8.6 2018-10-04 11:28:30 [main] level org.quartz.core.QuartzScheduler [QuartzScheduler.java:2267] - JobFactory set to: com.googlecode.jmxtrans.guice.GuiceJobFactory@263f04ca 2018-10-04 11:28:30 [main] level com.googlecode.jmxtrans.JmxTransformer [JmxTransformer.java:177] - Starting Jmxtrans on : . 2018-10-04 11:28:30 [main] level org.quartz.core.QuartzScheduler [QuartzScheduler.java:519] - Scheduler ServerScheduler_$_Mars.local1538623710548 started. 2018-10-04 11:28:30 [main] level com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory [InfluxDbWriterFactory.java:121] - Result Tags to write set to: [ResultAttribute(name=typeName), ResultAttribute(name=objDomain), ResultAttribute(name=className), ResultAttribute(name=attributeName)] 2018-10-04 11:28:30 [main] level com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory [InfluxDbWriterFactory.java:102] - Connecting to url: http://192.168.99.100:8086/ as: username: admin 2018-10-04 11:28:31 [main] level com.googlecode.jmxtrans.model.output.InfluxDbWriterFactory [InfluxDbWriterFactory.java:121] - Result Tags to write set to: [ResultAttribute(name=typeName), ResultAttribute(name=objDomain), ResultAttribute(name=className), ResultAttribute(name=attributeName)]

查询influxdb数据

docker exec -it influxdb influx
Connected to http://localhost:8086 version 1.5.4
InfluxDB shell version: 1.5.4
> use zookeeper
Using database zookeeper
> show MEASUREMENTS
name: measurements
name
----
Clients
Memory
Process
Threading
> show series from "Memory"
key
---
Memory,attributeName=HeapMemoryUsage,className=sun.management.MemoryImpl,hostname=zk,objDomain=java.lang,typeName=type\=Memory
Memory,attributeName=NonHeapMemoryUsage,className=sun.management.MemoryImpl,hostname=zk,objDomain=java.lang,typeName=type\=Memory
  • 之后通过select * from "Memory"可以查看具体指标数据
  • 查询到有数据之后,就可以在grafana上面进行配置可视化,然后进行监控

小结

对于zookeeper、kafka之类应用来说,内置了jmx,因而其监控可以通过jmxtrans进行指标收集转换,然后输出到influxdb或者graphite或者prometheus等,最后通过grafana进行可视化及监控报警。

doc

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
4个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Stella981 Stella981
3年前
KVM调整cpu和内存
一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
10个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这