首页 > 代码库 > MQTT---HiveMQ源码详解(十)Netty-Statistics
MQTT---HiveMQ源码详解(十)Netty-Statistics
HiveMQ中的内置的统计非常之多,多到可怕,几乎你能想到的统计hivemq都已经帮你想全了;同时第三方plugin还可以定义属于自己的统计。
它的实现采用了Metric框架实现统计、度量。收集的数据可以通过多种数据报告接口,这样可以监控broker运行中的各种数据来监控broker。
所谓统计无外乎就是采集埋点、输出报告
采集埋点
类图
通过StatisticsInitializer实现handlerAdded方法,为pipeline中添加GlobalTrafficCounter(流量计数器)、GlobalMqttMessageCounter(mqtt消息数量计数器)、MqttConnectionCounterHandler(mqtt连接数量计数器)
GlobalTrafficCounter继承netty的GlobalTrafficShapingHandler,来获得流量计数器,来统计当前(最后5秒)的读/写流量、累计的读/写流量。
GlobalMqttMessageCounter根据当前的mqtt消息类型,来分类统计每种mqtt消息的读/写的数量和吞吐。
MqttConnectionCounterHandler通过监听mqtt connect消息以及当前Channel的closeFuture来统计总连接数、当前连接数;MqttConnectionCounter数据细粒度的一个带ReadWriteLock的统计器来为当前连接数提供increase、decrease以及当前连接数、最大连接数查询的类。
这样通过统计的handler对连接、流量、数量进行统计,达到统计埋点,以达到收集broker中的流量信息。
官网还为我们提供了jvm监控插件。
https://github.com/hivemq/jvm-metrics-plugin
输出报告
既然数据已经收集到Metric中,那么输出就相对来说很简单了,而且输出都是属于个性化的需求,hivemq则采用的是plugin的方式来输出报告的,官网为我们提供了几种输出的插件。
1、以$SYS主题发布出去。https://github.com/hivemq/hivemq-sys-topic-plugin
2、输出到influxdb中去。https://github.com/hivemq/influxdb-monitoring-plugin
内置的采集信息列举
下面的列举基本上都是见名知意的,博主就不给大家一一解释了。
private final Counter incomingMessageCount;
private final Counter outgoingMessageCount;
private final Meter incomingMessageRate;
private final Meter outgoingMessageRate;
private final Meter outgoingConnAckRate;
private final Counter outgoingConnAckCount;
private final Meter incomingConnectRate;
private final Counter incomingConnectCount;
private final Meter incomingDisconnectRate;
private final Counter incomingDisconnectCount;
private final Meter incomingPingReqRate;
private final Counter incomingPingReqCount;
private final Meter outgoingPingRespRate;
private final Counter outgoingPingRespCount;
private final Meter incomingPubAckRate;
private final Counter incomingPubAckCount;
private final Meter outgoingPubAckRate;
private final Counter outgoingPubAckCount;
private final Meter incomingPubCompRate;
private final Counter incomingPubCompCount;
private final Meter outgoingPubCompRate;
private final Counter outgoingPubCompCount;
private final Meter incomingPublishRate;
private final Counter incomingPublishCount;
private final Meter outgoingPublishRate;
private final Counter outgoingPublishCount;
private final Meter incomingPubRecRate;
private final Counter incomingPubRecCount;
private final Meter outgoingPubRecRate;
private final Counter outgoingPubRecCount;
private final Meter incomingPubRelRate;
private final Counter incomingPubRelCount;
private final Meter outgoingPubRelRate;
private final Counter outgoingPubRelCount;
private final Meter outgoingSubAckRate;
private final Counter outgoingSubAckCount;
private final Meter incomingSubscribeRate;
private final Counter incomingSubscribeCount;
private final Meter outgoingUnsubAckRate;
private final Counter outgoingUnsubAckCount;
private final Meter incomingUnsubscribeRate;
private final Counter incomingUnsubscribeCount;
private final Counter halfFullQueueCount;
private final Meter droppedMessageRate;
private final Counter droppedMessageCount;
private final Meter publishQueueRate;
private final Counter publishQueueSize;
private final Counter persistentSessionsActive;
private final Histogram connectionsOverallMean;
private final Histogram incomingMessageSizeMean;
private final Histogram outgoingMessageSizeMean;
private final Histogram incomingPublishSizeMean;
private final Histogram outgoingPublishSizeMean;
private final Histogram retainedMessagesMean;
private final Meter retainedMessagesRate;
private final Counter subscriptionsCurrent;
private final Timer pluginTimerAfterLoginSuccess;
private final Timer pluginTimerAfterLoginFailed;
private final Timer pluginTimerAuthentication;
private final Timer pluginTimerRestrictions;
private final Timer pluginTimerAuthorization;
private final Timer pluginTimerPermissionsDisconnectPublish;
private final Timer pluginTimerPermissionsDisconnectSubscribe;
private final Timer pluginTimerConnect;
private final Timer pluginTimerDisconnect;
private final Timer pluginTimerConnAckSend;
private final Timer pluginTimerPubAckSend;
private final Timer pluginTimerPubAckReceived;
private final Timer pluginTimerPubCompReceived;
private final Timer pluginTimerPublishReceived;
private final Timer pluginTimerPublishSend;
private final Timer pluginTimerSubscribe;
private final Timer pluginTimerUnsubscribe;
private final Timer pluginTimerPing;
private final Timer pluginTimerPubRelReceived;
private final Timer pluginTimerPubRecReceived;
private final Timer pluginTimerPubCompSend;
private final Timer pluginTimerPubRecSend;
private final Timer pluginTimerPubRelSend;
private final Timer pluginTimerSubAckSend;
private final Timer pluginTimerUnsubAckSend;
private final Meter totalExceptionRate;
MQTT交流群:221405150
MQTT---HiveMQ源码详解(十)Netty-Statistics