分享

Kafka监控工具:JmxTool

问题导读

1.kafka使用什么工具可以监控?
2.是如何开启JmxTool工具?
3.如何查看消息入站速率?





Kafka使用Yammer Metrics在服务器和Scala客户端中进行度量报告。 Java客户端使用Kafka Metrics,这是一种内置的度量标准注册表,可最大限度地减少传入客户端应用程序的传递依赖性。 两者都通过JMX公开指标,并且可以配置为使用可插入的统计报告来报告统计数据,以连接到监控系统。

所有Kafka费率指标都有相应的累积计数指标,后缀为-total。 例如,记录消耗率具有名为records-consume-total的对应度量。

查看可用指标的最简单方法是启动jconsole并将其指向正在运行的kafka客户端或服务器; 这允许使用JMX浏览所有指标。



Kafka开放了N多JMX指标,很多框架可以帮助我们实时捕获这些JMX metrics的值。实际上,Kafka还提供了一个非常方便的工具:JmxTool。

严格来说,JmxTool不是一个框架,而是Kafka社区默认提供的一个工具,用于实时查看JMX监控指标。如果用户一时找不到合适工具来监测JMX指标可以考虑使用该工具“临时救急”一下。

打开终端进入到Kafka安装目录下,输入命令bin/kafka-run-class.sh kafka.tools.JmxTool便可以得到JmxTool工具的帮助信息,如下图所示:

1.png

    假设我们要实时监控broker端JMX指标:消息入站速率。只需要执行以下命令即可:
  1. bin/kafka-run-class.sh kafka.tools.JmxTool --object-name kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec --jmx-url service:jmx:rmi:///jndi/rmi://:9997/jmxrmi --date-format "YYYY-MM-dd HH:mm:ss" --attributes FifteenMinuteRate --reporting-interval 5000
复制代码


    运行结果如下图所示,BytesInPerSec的值每5秒会打印在控制台上:
  1. >kafka_2.12-2.0.0 rrd$ bin/kafka-run-class.sh kafka.tools.JmxTool --object-name kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec --jmx-url service:jmx:rmi:///jndi/rmi://:9997/jmxrmi --date-format "YYYY-MM-dd HH:mm:ss" --attributes FifteenMinuteRate --reporting-interval 5000
  2. Trying to connect to JMX url: service:jmx:rmi:///jndi/rmi://:9997/jmxrmi.
  3. "time","kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec:FifteenMinuteRate"
  4. 2018-08-10 14:52:15,784224.2587058166
  5. 2018-08-10 14:52:20,1003401.2319497257
  6. 2018-08-10 14:52:25,1125080.6160773218
  7. 2018-08-10 14:52:30,1593394.1860063889
  8. 2018-08-10 14:52:35,1993957.4168548603
  9. 2018-08-10 14:52:40,2357721.0311160865
  10. 2018-08-10 14:52:45,2841690.084352943
  11. 2018-08-10 14:52:50,2965280.638911543
  12. 2018-08-10 14:52:55,2948852.533463836
  13. 2018-08-10 14:53:00,2932515.442217301
  14. 2018-08-10 14:53:05,2916268.8609394296
  15. 2018-08-10 14:53:10,2900112.2881912384
复制代码



上述命令中的kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec可以替换成Kafka提供的其他JMX指标

完整的JMX指标列表参见https://kafka.apache.org/documentation/#monitoring


##########################################################
下面是部分内容,如英文能力较强,建议直接参考上面英文


英文能力有限,大家多多提建议:

描述
MBEAN 名称
正常值
消息速率kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec
来自clients的速率字节kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec
来自其他brokers的字节速率kafka.server:type=BrokerTopicMetrics,name=ReplicationBytesInPerSec
请求率kafka.network:type=RequestMetrics,name=RequestsPerSec,request={Produce|FetchConsumer|FetchFollower}
错误率kafka.network:type=RequestMetrics,name=ErrorsPerSec,request=([-.\w]+),error=([-.\w]+)Number of errors in responses counted
per-request-type, per-error-code.
If a response contains multiple errors,
all are counted. error=NONE indicates
successful responses.
请求大小(字节)kafka.network:type=RequestMetrics,name=RequestBytes,request=([-.\w]+)Size of requests for each request type.
临时内存大小(以字节为单位)kafka.network:type=RequestMetrics,name=TemporaryMemoryBytes,request={Produce|Fetch}Temporary memory used for message
format conversions and decompression.
消息转换时间kafka.network:type=RequestMetrics,name=MessageConversionsTimeMs,request={Produce|Fetch}Time in milliseconds spent on
message format conversions.
消息转换率kafka.server:type=BrokerTopicMetrics,name={Produce|Fetch}MessageConversionsPerSec,topic=([-.\w]+)Number of records which required
message format conversion.
向客户发送速率kafka.server:type=BrokerTopicMetrics,name=BytesOutPerSec
对其他brokers的字节输出率kafka.server:type=BrokerTopicMetrics,name=ReplicationBytesOutPerSec
Log flush 率和时        kafka.log:type=LogFlushStats,name=LogFlushRateAndTimeMs
# of under replicated partitions (|ISR| < |all replicas|)kafka.server:type=ReplicaManager,name=UnderReplicatedPartitions0
# of under minIsr partitions (|ISR| < min.insync.replicas)kafka.server:type=ReplicaManager,name=UnderMinIsrPartitionCount0
离线日志目录数kafka.log:type=LogManager,name=OfflineLogDirectoryCount0
Is controller active on brokerkafka.controller:type=KafkaController,name=ActiveControllerCountonly one broker in the cluster should have 1
Leader选举率kafka.controller:type=ControllerStats,name=LeaderElectionRateAndTimeMsnon-zero when there are broker failures
Unclean leader 选举率kafka.controller:type=ControllerStats,name=UncleanLeaderElectionsPerSec0
Partition countskafka.server:type=ReplicaManager,name=PartitionCountmostly even across brokers
Leader replica countskafka.server:type=ReplicaManager,name=LeaderCountmostly even across brokers
ISR shrink ratekafka.server:type=ReplicaManager,name=IsrShrinksPerSecIf a broker goes down, ISR for
some of the partitions will shrink.
When that broker is up again,
ISR will be expanded once the
replicas are fully caught up.
Other than that, the expected
value for both ISR shrink rate
and expansion rate is 0.
ISR expansion ratekafka.server:type=ReplicaManager,name=IsrExpandsPerSecSee above
follower 和leader 副本之间的消息中的最大延迟kafka.server:type=ReplicaFetcherManager,name=MaxLag,clientId=Replicalag should be proportional to the
maximum batch size of a produce request.
每个follower 的副本消息延迟kafka.server:type=FetcherLagMetrics,name=ConsumerLag,clientId=([-.\w]+),topic=([-.\w]+),partition=([0-9]+)lag should be proportional to
the maximum batch size of a
produce request.
请求在生产者清洗中等待kafka.server:type=DelayedOperationPurgatory,name=PurgatorySize,delayedOperation=Producenon-zero if ack=-1 is used
请求等待在fetch purgatorykafka.server:type=DelayedOperationPurgatory,name=PurgatorySize,delayedOperation=Fetchsize depends on fetch.wait.max.ms in the consumer
请求总时间kafka.network:type=RequestMetrics,name=TotalTimeMs,request={Produce|FetchConsumer|FetchFollower}broken into queue, local, remote and response send time
请求在请求队列中等待的时间kafka.network:type=RequestMetrics,name=RequestQueueTimeMs,request={Produce|FetchConsumer|FetchFollower}
请求在leader处理的时间kafka.network:type=RequestMetrics,name=LocalTimeMs,request={Produce|FetchConsumer|FetchFollower}
请求等待follower的时间kafka.network:type=RequestMetrics,name=RemoteTimeMs,request={Produce|FetchConsumer|FetchFollower}non-zero for produce requests when ack=-1
请求在响应队列中等待的时间kafka.network:type=RequestMetrics,name=ResponseQueueTimeMs,request={Produce|FetchConsumer|FetchFollower}
Time to send the responsekafka.network:type=RequestMetrics,name=ResponseSendTimeMs,request={Produce|FetchConsumer|FetchFollower}
Number of messages the consumer lags behind the producer by. Published by the consumer, not broker.消费者落后于生产者的消息数量。 由消费者发布,而不是broker。Old consumer:kafka.consumer:type=ConsumerFetcherManager,name=MaxLag,clientId=([-.\w]+)
New consumer:kafka.consumer:type=consumer-fetch-manager-metrics,client-id={client-id} Attribute: records-lag-max
network processors空闲的平均时间分数kafka.network:type=SocketServer,name=NetworkProcessorAvgIdlePercentbetween 0 and 1, ideally > 0.3
请求处理程序线程空闲的平均时间部分kafka.server:type=KafkaRequestHandlerPool,name=RequestHandlerAvgIdlePercentbetween 0 and 1, ideally > 0.3
Bandwidth quota metrics per (user, client-id), user or client-idkafka.server:type={Produce|Fetch},user=([-.\w]+),client-id=([-.\w]+)Two attributes. throttle-time indicates
the amount of time in ms the client
was throttled. Ideally = 0. byte-rate indicates
the data produce/consume rate of the
client in bytes/sec. For (user, client-id) quotas,
both user and client-id are specified.
If per-client-id quota is applied to the client,
user is not specified. If per-user quota is applied,
client-id is not specified.
每个(用户,客户端ID),用户或客户端ID的带宽配额指标kafka.server:type=Request,user=([-.\w]+),client-id=([-.\w]+)Two attributes. throttle-time indicates
the amount of time in ms the client
was throttled. Ideally = 0.
request-time indicates the percentage
of time spent in broker network and
I/O threads to process requests from
client group. For (user, client-id) quotas,
both user and client-id are specified.
If per-client-id quota is applied to the client,
user is not specified. If per-user quota is applied,
client-id is not specified.
Requests exempt from throttlingkafka.server:type=Requestexempt-throttle-time indicates
the percentage of time spent in broker
network and I/O threads to process
requests that are exempt from throttling.
ZooKeeper客户端请求延迟kafka.server:type=ZooKeeperClientMetrics,name=ZooKeeperRequestLatencyMsLatency in millseconds for ZooKeeper
requests from broker.
ZooKeeper连接状态kafka.server:type=SessionExpireListener,name=SessionStateConnection status of broker's ZooKeeper
session which may be one of Disconnected|SyncConnected|AuthFailed
|ConnectedReadOnly|SaslAuthenticated|Expired.





本帖被以下淘专辑推荐:

欢迎加入about云群425860289432264021 ,云计算爱好者群,关注about云腾讯认证空间

已有(2)人评论

跳转到指定楼层
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条