文档章节

jmxtrans+influxdb+grafana监控zookeeper实战

go4it
 go4it
发布于 2018/10/04 12:05
字数 1011
阅读 188
收藏 1

本文主要研究一下如何使用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

© 著作权归作者所有

go4it
粉丝 90
博文 1126
码字总数 1057866
作品 0
深圳
私信 提问
ZooKeeper教程资源收集(简介/原理/示例/解决方案)

菩提树下的杨过: ZooKeeper 笔记(1) 安装部署及hello world ZooKeeper 笔记(2) 监听数据变化 ZooKeeper 笔记(3) 实战应用之【统一配置管理】 ZooKeeper 笔记(4) 实战应用之【消除单点故障】...

easonjim
2017/09/05
0
0
docker入门到实战(6)在docker中安装和使用kafka

下载镜像 这里使用了wurstmeister/kafka和wurstmeister/zookeeper这两个版本的镜像,在hub.docker.com中可以搜索到。 1、docker pull wurstmeister/zookeeper 2、docker pull wurstmeister/...

编程老司机
2018/05/14
0
0
ZooKeeper分布式架构实战系列(02):Linux Ubuntu 18.04实战安装Zookeeper 3.4.13单节点模式

第2篇文章,我们来Linux实战安装Zookeeper 3.4 单节点模式,可以选择CentOS7或者Ubuntu 16或者18.04。 Zookeeper是开源分布式协调服务,一种集中式服务架构,用于维护分布式系统的配置信息,...

徐雷frank
03/31
0
0
zookeeper系列(二)实战master选举

master选举 考虑7*24小时向外提供服务的系统,不能有单点故障,于是我们使用集群,采用的是Master+Slave。集群中有一台主机和多台备机,由主机向外提供服务,备机监听主机状态,一旦主机宕机...

chenkangyao
2018/08/07
55
0
部署Mesos+zookeeper+Marathon+Docker实战

Mesos是什么? Mesos是Apache下的开源分布式资源管理框架,它被称为是分布式系统的内核。Mesos能够在同样的集群机器上运行多种分布式系统类型,更加动态有效率低共享资源。提供失败侦测,任务...

若此生无缘
2018/08/17
0
0

没有更多内容

加载失败,请刷新页面

加载更多

nginx访问日志/日志切割/静态文件过期时间/防盗链

Nginx访问日志主要记录部署在nginx上的网站访问数据,日志格式定义在nginx主配置文件中。 nginx主配置文件:/etc/nginx/nginx.conf 查看nginx主配置文件: ```markup [root@linux ~]# cat /e...

asnfuy
25分钟前
8
0
JS_高程4.变量,作用域和内存问题(2)执行环境及作用域

本文转载于:专业的前端网站➨JS_高程4.变量,作用域和内存问题(2)执行环境及作用域 1.执行环境:执行环境定义了变量或函数有权访问的其他数据,决定了它们各自的行为,       每个执...

前端老手
29分钟前
5
0
手机迅雷下载的文件,电脑上找不到问题

不知道手机迅雷怎么做到的,手机迅雷下载的文件,手机上可以看的到 但连电脑后, 电脑上看不到文件 . 尝试了打开查看隐藏文件, 但没有效果 . 手机上查询文件权限 也是对的 . 可读,可写, 不隐藏 ...

ol_O_O_lo
31分钟前
5
0
python学习11:Python tuple元组详解

元组是 Python 中另一个重要的序列结构,和列表类似,也是由一系列按特定顺序排序的元素组成。和列表不同的是,列表可以任意操作元素,是可变序列;而元组是不可变序列,即元组中的元素不可以...

太空堡垒185
43分钟前
5
0
Java实现数据结构之线性结构

一、顺序表 顺序表本质是使用数组储存数组的一种数据结构,在计算机的储存中是连续的分配内存的。 下面是我自己使用java实现的简单顺序表结构 package list; public class MyArrayList<E> { ...

daxiongdi
45分钟前
6
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部