当前位置:   article > 正文

监控数据指标kafka-metrics Prometheus(二)_没有kafka-metrics

没有kafka-metrics

Kafka metrics 所有的 metric 都可以通过 JMX 获取,暴露kafka metrics 支持两种方式

1.在 Kafka Broker 外部, 作为一个独立进程, 通过 JMX 的 RMI 接口读取数据.
这种方式的好处是有任何调整不需要重启 Kafka Broker 进程,
缺点是多维护了一个独立的进程。
2.在 Kafka Broker 进程内部读取 JMX 数据, 这样解析数据的逻辑就在 Kafka Broker
进程内部, 如果有任何调整, 需要重启 Broker。

选择暴露 kafka-metric 方式

第一种需要外部多维护一个程序,而且还要考虑之后各种版本升级,实现起来比较繁琐,还好的是github上有许多优秀的开源kafka_exporter
下载过来直接启动就好了。简单介绍下
git项目地址:https://github.com/danielqsj/kafka_exporter

  1. 下载 kafka_exporter(所在机器需与kafka集群网络相通)

wget
https://github.com/danielqsj/kafka_exporter/releases/download/v1.2.0/kafka_exporter-1.2.0.linux-amd64.tar.gz

解压: tar -zxvf kafka_exporter-1.2.0.linux-amd64.tar.gz

切到相应目录: cd kafka_exporter-1.2.0.linux-amd64

./kafka_exporter --kafka.server=kafkaIP或者域名:9092 &
(只需填写kafka集群的一个ip即可)

[root@prometheus prometheus]# yum install screen -y

[root@prometheus prometheus]# screen

[root@prometheus prometheus]# ./kafka_exporter --kafka.server=kafka03:9092

#按Ctrl+a+d后进入后台运行模式

对应的服务端口为9308

2.下载prometheus

wget
https://github.com/prometheus/prometheus/releases/download/v2.15.1/prometheus-2.15.1.linux-amd64.tar.gz

解压

tar -zxvf prometheus-2.15.1.linux-amd64.tar.gz

prometheus.yml为promethues配置文件,可以先启动验证服务可用性

cd ./prometheus-2.15.1.linux-amd64

prometheus.yml
这个文件是对应的配置文件,在未添加kafka_exporter之前可以先启动查看下服务是否正常

添加监控配置

在这里插入图片描述

重启prometheus

./prometheus --config.file=prometheus.yml --web.listen-address=:9090
–storage.tsdb.path=/data/prometheus &

在这里插入图片描述

  1. 下载grafana

wget https://dl.grafana.com/oss/release/grafana-7.1.5.linux-amd64.tar.gz

tar -zxvf grafana-7.1.5.linux-amd64.tar.gz

该grafana-server二进制需要工作目录是根安装目录,其中二进制文件以及public文件夹的位置。

通过运行以下命令启动Grafana:

./bin/grafana-server web

打开grafana的web页面 ip:3000,添加promethues数据源

在这里插入图片描述

导入监控图标,对于grafana的监控,官方有监控图标,不需要自己搞

在这里插入图片描述

官方的监控界面

在这里插入图片描述

生产环境的监控环境配置及对应查询语句

在这里插入图片描述

在这里插入图片描述

Grafana画图也有许多优秀的开源dashboard

第二种是读取 JMX 的数据. Prometheus 官方的组件 jmx_exporter 把两种实现都提供了:

jmx_prometheus_httpserver 通过独立进程读取 JMX 的数据

jmx_prometheus_javaagent 使用 Java Agent 方式, 尽量无侵入(仅需在 java
命令行中使用 -javaagent 参数)的启动 in-process library, 读取 JMX 数据.

Prometheus 采用了 PULL 方式, Prometheus 主动抓取 metrics 数据,
而不是靠客户端主动 PUSH 数据, 因此 jmx_prometheus 都是通过暴露 HTTP
端口的方式暴露 metrics 数据, 方便 Prometheus 抓取数据.

选择方案2

我们这里选择第二种jmx_prometheus_javaagent 方式收集kafka指标

部署流程:

下载jmx_prometheus_javaagent和kafka.yml

wget
https://raw.githubusercontent.com/prometheus/jmx_exporter/master/example_configs/kafka-0-8-2.yml

wget
https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/0.6/jmx_prometheus_javaagent-0.6.jar

打开 kafka-server-start.sh 文件

添加几行代码:

export JMX_PORT=“9999”

export
KAFKA_OPTS="-javaagent:/path/jmx_prometheus_javaagent-0.6.jar=9991:/path/kafka-0-8-2.yml"

然后重启kafka。
访问 http://localhost:9991/metrics 可以看到各种指标了。

监控指标

部分监控指标解释,不一定准确,请参考。还有参考 monitoring
kafafka
有详细的指标信息

指标 解释
kafka_server_replicafetchermanager_maxlag Max
kafka_server_replicamanager_isrexpands_total ISR expansion rate 扩大率(ISR是in-sync replicas的简写)
kafka_server_replicamanager_isrshrinks_total ISR shrink rate 收缩率
kafka_server_replicamanager_underreplicatedpartitions # of under replicated partitions (|ISR| < |all replicas|)
kafka_network_requestmetrics_responsesendtimems Time to send the response Produce
kafka_network_socketserver_networkprocessoravgidlepercent The average fraction of time the network processors are idle
kafka_network_requestmetrics_responsesendtimems
kafka_network_requestmetrics_requestqueuetimems Time the request waiting in the request queue Produce
kafka_network_requestmetrics_remotetimems Time the request waits for the follower Produce
kafka_network_requestmetrics_localtimems Time the request being processed at the leader Produce
kafka_log_logflushstats_logflushrateandtimems_count Log flush latency
kafka_server_replicafetchermanager_minfetchrate Max lag in messages btw follower and leader replicas > 4000
kafka_controller_controllerstats_uncleanleaderelectionspersec Unclean leader election has occurred last 15m
kafka_server_replicamanager_underreplicatedpartitions Under replicated partitions
kafka_controller_kafkacontroller_activecontrollercount 活跃的 Controller 的数量
kafka_controller_controllerstats_uncleanleaderelectionspersec 争议的 leader 选举次数
kafka_controller_controllerstats_controlledshutdownrateandtimems 将ISR中处于关闭状态的副本从集合中去除掉,返回一个新的ISR集合,然后选取第一个副本作为leader,然后令当前AR作为接收LeaderAndIsr请求的副本。
kafka_controller_kafkacontroller_offlinepartitionscount 从活着的ISR中选择一个broker作为leader,如果ISR中没有活着的副本,则从assignedReplicas中选择一个副本作为leader,leader选举成功后注册到Zookeeper中,并更新所有的缓存。
broker指标
kafka_server_brokertopicmetrics_messagesin_total 所有topic消息(进出)流量 消息写入总量
kafka_server_brokertopicmetrics_bytesrejected_total 扔掉的流量
kafka_server_brokertopicmetrics_failedfetchrequests_total 当前机器fetch请求失败的数量
kafka_server_brokertopicmetrics_bytesout_total 输出的流量
kafka_server_brokertopicmetrics_bytesin_total 输入的流量
kafka_server_brokertopicmetrics_failedproducerequests_total 当前机器produce请求失败的数量
kafka_server_replicamanager_partitioncount 该broker上的partition的数量
kafka_server_replicamanager_leadercount Leader的replica的数量
kafka_network_requestmetrics_totaltimems{FetchConsumer\FetchFollower\Produce} 一个请求FetchConsumer\FetchFollower\Produce耗费的所有时间

预警指标分析

kafka.server:type=ReplicaManager,name=UnderReplicatedPartitions **
含义: 正在复制的 Partition 的数量.
建议报警阈值: > 0 就建议报警. 但如果 Kafka 集群正在 reassign partition 时,
这个值也会 >0

kafka.controller:type=KafkaController,name=OfflinePartitionsCount
含义: 没有 Leader 的 Partition 的数量. 处于这个状态的 Partition 是不可读也不可写
建议报警阈值: >0 一旦出现就报警.

kafka.controller:type=KafkaController,name=ActiveControllerCount
含义: 活跃的 Controller 的数量.
建议报警阈值: != 0 就赶紧报警

kafka.server:type=ReplicaManager,name=PartitionCount
含义: 集群中 Partition 的总数
建议报警阈值: 感觉这个报警不可控.

kafka_controller_controllerstats_leaderelectionrateandtimems
含义: Leader election rate 领导人选举率

UncleanLeaderElectionsPerSec
含义: Unclean leader election rate 争议的 leader 选举次数

描述:所有的topic的消息速率(消息数/秒)
Mbean名:“kafka.server”:name=“AllTopicsMessagesInPerSec”,type=“BrokerTopicMetrics”
正常的值:

描述:所有的topic的流入数据速率(字节/秒)
Mbean名:“kafka.server”:name=“AllTopicsBytesInPerSec”,type=“BrokerTopicMetrics”
正常的值:

描述:producer或Fetch-consumer或Fetch-follower的请求速率(请求次数/秒)
Mbean名:“kafka.network”:name="{Produce|Fetch-consumer|Fetch-follower}-RequestsPerSec",type=“RequestMetrics”
正常的值:

描述:所有的topic的流出数据速率(字节/秒)
Mbean名:
“kafka.server”:name=“AllTopicsBytesOutPerSec”,type=“BrokerTopicMetrics”
正常的值:

描述:刷日志的速率和耗时
Mbean名: “kafka.log”:name=“LogFlushRateAndTimeMs”,type=“LogFlushStats”
正常的值:

描述:正在做复制的partition的数量(|ISR| < |all replicas|)
Mbean名:“kafka.server”:name=“UnderReplicatedPartitions”,type=“ReplicaManager”
正常的值:0

描述:当前的broker是否为controller
Mbean名:“kafka.controller”:name=“ActiveControllerCount”,type=“KafkaController”
正常的值:在集群中只有一个broker的这个值为1

描述:选举leader的速率
Mbean名:“kafka.controller”:name=“LeaderElectionRateAndTimeMs”,type=“ControllerStats”
正常的值:如果有broker挂了,此值非0

描述:Unclean的leader选举速率
Mbean名:“kafka.controller”:name=“UncleanLeaderElectionsPerSec”,type=“ControllerStats”
正常的值:0

描述:该broker上的partition的数量
Mbean名: “kafka.server”:name=“PartitionCount”,type=“ReplicaManager”
正常的值:应在各个broker中平均分布

描述:Leader的replica的数量
Mbean名: “kafka.server”:name=“LeaderCount”,type=“ReplicaManager”
正常的值:应在各个broker中平均分布

描述:ISR的收缩(shrink)速率
Mbean名:“kafka.server”:name=“ISRShrinksPerSec”,type=“ReplicaManager”
正常的值:如果一个broker挂掉了,一些partition的ISR会收缩。当那个broker重新起来时,一旦它的replica完全跟上,ISR会扩大(expand)。除此之外,正常情况下,此值和下面的扩大速率都是0。

描述:ISR的扩大(expansion)速率
Mbean名: “kafka.server”:name=“ISRExpandsPerSec”,type=“ReplicaManager”
正常的值:参见ISR的收缩(shrink)速率

描述:follower落后leader replica的最大的消息数量
Mbean名:“kafka.server”:name="([-.\w]+)-MaxLag",type=“ReplicaFetcherManager”
正常的值:小于replica.lag.max.messages

描述:每个follower replica落后的消息速率
Mbean名:“kafka.server”:name="([-.\w]+)-ConsumerLag",type=“FetcherLagMetrics”
正常的值:小于replica.lag.max.messages

描述:等待producer purgatory的请求数
Mbean名:“kafka.server”:name=“PurgatorySize”,type=“ProducerRequestPurgatory”
正常的值:如果ack=-1,应为非0值

描述:等待fetch purgatory的请求数
Mbean名:“kafka.server”:name=“PurgatorySize”,type=“FetchRequestPurgatory”
正常的值:依赖于consumer的fetch.wait.max.ms的设置

描述:一个请求(producer,Fetch-Consumer,Fetch-Follower)耗费的所有时间
Mbean名:“kafka.network”:name="{Produce|Fetch-Consumer|Fetch-Follower}-TotalTimeMs",type=“RequestMetrics”
正常的值:包括了queue, local, remote和response send time

描述:请求(producer,Fetch-Consumer,Fetch-Follower)在请求队列中的等待时间
Mbean名:“kafka.network”:name="{Produce|Fetch-Consumer|Fetch-Follower}-QueueTimeMs",type=“RequestMetrics”
正常的值:

描述:请求(producer,Fetch-Consumer,Fetch-Follower)在leader处理请求花的时间
Mbean名:“kafka.network”:name="{Produce|Fetch-Consumer|Fetch-Follower}-LocalTimeMs",type=“RequestMetrics”
正常的值:

描述:请求(producer,Fetch-Consumer,Fetch-Follower)等待follower花费的时间
Mbean名:“kafka.network”:name="{Produce|Fetch-Consumer|Fetch-Follower}-RemoteTimeMs",type=“RequestMetrics”
正常的值:producer的ack=-1时,非0才正常

描述:发送响应花费的时间
Mbean名:“kafka.network”:name="{Produce|Fetch-Consumer|Fetch-Follower}-ResponseSendTimeMs",type=“RequestMetrics”
正常的值:

描述:consumer落后producer的消息数量
Mbean名:“kafka.consumer”:name="([-.\w]+)-MaxLag",type=“ConsumerFetcherManager”
正常的值:
建议对GC耗时和其他参数和诸如系统CPU,I/O时间等等进行监控。在client端,建议对"消息数量/字节数"的速率(全局的和对于每一个topic),请求的"速率/大小/耗时"进行监控。还有consumer端,所有partition的最大的落后情况和最小的fetch请求的速率。consumer为了能跟上,最大落后数量需要少于一个threshold并且最小fetch速率需要大于0.

Grafana画图 上传 下面 json文件

{

“__inputs”: [

{

“name”: “DS_PROMETHEUS”,

“label”: “Prometheus”,

“description”: “”,

“type”: “datasource”,

“pluginId”: “prometheus”,

“pluginName”: “Prometheus”

}

],

“__requires”: [

{

“type”: “grafana”,

“id”: “grafana”,

“name”: “Grafana”,

“version”: “5.0.4”

},

{

“type”: “panel”,

“id”: “graph”,

“name”: “Graph”,

“version”: “5.0.0”

},

{

“type”: “datasource”,

“id”: “prometheus”,

“name”: “Prometheus”,

“version”: “5.0.0”

},

{

“type”: “panel”,

“id”: “singlestat”,

“name”: “Singlestat”,

“version”: “5.0.0”

}

],

“annotations”: {

“list”: [

{

“builtIn”: 1,

“datasource”: “-- Grafana --”,

“enable”: true,

“hide”: true,

“iconColor”: “rgba(0, 211, 255, 1)”,

“name”: “Annotations & Alerts”,

“type”: “dashboard”

}

]

},

“description”: “Example of an Kafka Dashboard for DC/OS 1.12”,

“editable”: true,

“gnetId”: 9018,

“graphTooltip”: 0,

“id”: null,

“links”: [],

“panels”: [

{

“aliasColors”: {},

“bars”: false,

“dashLength”: 10,

“dashes”: false,

“datasource”: “${DS_PROMETHEUS}”,

“fill”: 1,

“gridPos”: {

“h”: 10,

“w”: 12,

“x”: 0,

“y”: 0

},

“id”: 114,

“legend”: {

“avg”: false,

“current”: false,

“max”: false,

“min”: false,

“show”: true,

“total”: false,

“values”: false

},

“lines”: true,

“linewidth”: 1,

“links”: [],

“nullPointMode”: “null”,

“percentage”: false,

“pointradius”: 5,

“points”: false,

“renderer”: “flot”,

“seriesOverrides”: [],

“spaceLength”: 10,

“stack”: false,

“steppedLine”: false,

“targets”: [

{

“expr”: “rate(process_cpu_seconds_total{job=\“kafka\”}[1m])”,

“format”: “time_series”,

“intervalFactor”: 1,

“legendFormat”: “{ {instance}}”,

“refId”: “A”

}

],

“thresholds”: [],

“timeFrom”: null,

“timeShift”: null,

“title”: “CPU Usage”,

“tooltip”: {

“shared”: true,

“sort”: 0,

“value_type”: “individual”

},

“type”: “graph”,

“xaxis”: {

“buckets”: null,

“mode”: “time”,

“name”: null,

“show”: true,

“values”: []

},

“yaxes”: [

{

“format”: “short”,

“label”: null,

“logBase”: 1,

“max”: null,

“min”: null,

“show”: true

},

{

“format”: “short”,

“label”: null,

“logBase”: 1,

“max”: null,

“min”: null,

“show”: true

}

]

},

{

“aliasColors”: {},

“bars”: false,

“dashLength”: 10,

“dashes”: false,

“datasource”: “${DS_PROMETHEUS}”,

“fill”: 1,

“gridPos”: {

“h”: 10,

“w”: 12,

“x”: 12,

“y”: 0

},

“id”: 118,

“legend”: {

“avg”: false,

“current”: false,

“max”: false,

“min”: false,

“show”: true,

“total”: false,

“values”: false

},

“lines”: true,

“linewidth”: 1,

“links”: [],

“nullPointMode”: “null”,

“percentage”: false,

“pointradius”: 5,

“points”: false,

“renderer”: “flot”,

“seriesOverrides”: [],

“spaceLength”: 10,

“stack”: false,

“steppedLine”: false,

“targets”: [

{

“expr”: “sum
without(gc)(rate(jvm_gc_collection_seconds_sum{job=\“kafka\”}[5m]))”,

“format”: “time_series”,

“intervalFactor”: 1,

“legendFormat”: “{ {instance}}”,

“refId”: “A”

}

],

“thresholds”: [],

“timeFrom”: null,

“timeShift”: null,

“title”: “Time spent in GC”,

“tooltip”: {

“shared”: true,

“sort”: 0,

“value_type”: “individual”

},

“type”: “graph”,

“xaxis”: {

“buckets”: null,

“mode”: “time”,

“name”: null,

“show”: true,

“values”: []

},

“yaxes”: [

{

“format”: “short”,

“label”: null,

“logBase”: 1,

“max”: null,

“min”: null,

“show”: true

},

{

“format”: “short”,

“label”: null,

“logBase”: 1,

“max”: null,

“min”: null,

“show”: true

}

]

},

{

“aliasColors”: {},

“bars”: false,

“dashLength”: 10,

“dashes”: false,

“datasource”: “${DS_PROMETHEUS}”,

“fill”: 1,

“gridPos”: {

“h”: 9,

“w”: 12,

“x”: 0,

“y”: 10

},

“id”: 116,

“legend”: {

“avg”: false,

“current”: false,

“max”: false,

“min”: false,

“show”: true,

“total”: false,

“values”: false

},

“lines”: true,

“linewidth”: 1,

“links”: [],

“nullPointMode”: “null”,

“percentage”: false,

“pointradius”: 5,

“points”: false,

“renderer”: “flot”,

“seriesOverrides”: [],

“spaceLength”: 10,

“stack”: false,

“steppedLine”: false,

“targets”: [

{

“expr”: “sum without(area)(jvm_memory_bytes_used{job=\“kafka\”})”,

“format”: “time_series”,

“intervalFactor”: 1,

“legendFormat”: “{ {instance}}”,

“refId”: “A”

}

],

“thresholds”: [],

“timeFrom”: null,

“timeShift”: null,

“title”: “JVM Memory Used”,

“tooltip”: {

“shared”: true,

“sort”: 0,

“value_type”: “individual”

},

“type”: “graph”,

“xaxis”: {

“buckets”: null,

“mode”: “time”,

“name”: null,

“show”: true,

“values”: []

},

“yaxes”: [

{

“format”: “short”,

“label”: null,

“logBase”: 1,

“max”: null,

“min”: null,

“show”: true

},

{

“format”: “short”,

“label”: null,

“logBase”: 1,

“max”: null,

“min”: null,

“show”: true

}

]

},

{

“aliasColors”: {},

“bars”: false,

“dashLength”: 10,

“dashes”: false,

“datasource”: “${DS_PROMETHEUS}”,

“fill”: 1,

“gridPos”: {

“h”: 9,

“w”: 12,

“x”: 12,

“y”: 10

},

“id”: 42,

“legend”: {

“avg”: false,

“current”: false,

“max”: false,

“min”: false,

“show”: true,

“total”: false,

“values”: false

},

“lines”: true,

“linewidth”: 1,

“links”: [],

“nullPointMode”: “null”,

“percentage”: false,

“pointradius”: 5,

“points”: false,

“renderer”: “flot”,

“seriesOverrides”: [],

“spaceLength”: 10,

“stack”: false,

“steppedLine”: false,

“targets”: [

{

“expr”: “go_memstats_heap_inuse_bytes”,

“format”: “time_series”,

“intervalFactor”: 1,

“legendFormat”: “{ {instance}}”,

“refId”: “A”

}

],

“thresholds”: [],

“timeFrom”: null,

“timeShift”: null,

“title”: “Heap Memory in Use”,

“tooltip”: {

“shared”: true,

“sort”: 0,

“value_type”: “individual”

},

“type”: “graph”,

“xaxis”: {

“buckets”: null,

“mode”: “time”,

“name”: null,

“show”: true,

“values”: []

},

“yaxes”: [

{

“format”: “decbytes”,

“label”: null,

“logBase”: 1,

“max”: null,

“min”: null,

“show”: true

},

{

“format”: “short”,

“label”: null,

“logBase”: 1,

“max”: null,

“min”: null,

“show”: true

}

],

“yaxis”: {

“align”: false,

“alignLevel”: null

}

},

{

“collapsed”: false,

“gridPos”: {

“h”: 1,

“w”: 24,

“x”: 0,

“y”: 19

},

“id”: 38,

“panels”: [],

“title”: “”,

“type”: “row”

},

{

“aliasColors”: {},

“bars”: false,

“dashLength”: 10,

“dashes”: false,

“datasource”: “${DS_PROMETHEUS}”,

“fill”: 1,

“gridPos”: {

“h”: 9,

“w”: 12,

“x”: 0,

“y”: 20

},

“id”: 120,

“legend”: {

“avg”: false,

“current”: false,

“max”: false,

“min”: false,

“show”: false,

“total”: false,

“values”: false

},

“lines”: true,

“linewidth”: 1,

“links”: [],

“nullPointMode”: “null”,

“percentage”: false,

“pointradius”: 5,

“points”: false,

“renderer”: “flot”,

“seriesOverrides”: [],

“spaceLength”: 10,

“stack”: false,

“steppedLine”: false,

“targets”: [

{

“expr”: “sum
without(instance)(rate(kafka_server_brokertopicmetrics_bytesin_total{job=\“kafka\”,topic!=\”\"}[5m]))",

“format”: “time_series”,

“intervalFactor”: 1,

“legendFormat”: “{ {topic}}”,

“refId”: “A”

}

],

“thresholds”: [],

“timeFrom”: null,

“timeShift”: null,

“title”: “Bytes In Per Topic”,

“tooltip”: {

“shared”: true,

“sort”: 0,

“value_type”: “individual”

},

“type”: “graph”,

“xaxis”: {

“buckets”: null,

“mode”: “time”,

“name”: null,

“show”: true,

“values”: []

},

“yaxes”: [

{

“format”: “short”,

“label”: null,

“logBase”: 1,

“max”: null,

“min”: null,

“show”: true

},

{

“format”: “short”,

“label”: null,

“logBase”: 1,

“max”: null,

“min”: null,

“show”: true

}

]

},

{

“aliasColors”: {},

“bars”: false,

“dashLength”: 10,

“dashes”: false,

“datasource”: “${DS_PROMETHEUS}”,

“fill”: 1,

“gridPos”: {

“h”: 9,

“w”: 12,

“x”: 12,

“y”: 20

},

“id”: 122,

“legend”: { </

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Li_阴宅/article/detail/952479
推荐阅读
相关标签
  

闽ICP备14008679号