Search in sources :

Example 6 with BrokerStatsData

use of org.apache.rocketmq.common.protocol.body.BrokerStatsData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MQClientAPIImpl method viewBrokerStatsData.

public BrokerStatsData viewBrokerStatsData(String brokerAddr, String statsName, String statsKey, long timeoutMillis) throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException {
    ViewBrokerStatsDataRequestHeader requestHeader = new ViewBrokerStatsDataRequestHeader();
    requestHeader.setStatsName(statsName);
    requestHeader.setStatsKey(statsKey);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.VIEW_BROKER_STATS_DATA, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), brokerAddr), request, timeoutMillis);
    assert response != null;
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                byte[] body = response.getBody();
                if (body != null) {
                    return BrokerStatsData.decode(body, BrokerStatsData.class);
                }
            }
        default:
            break;
    }
    throw new MQClientException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ViewBrokerStatsDataRequestHeader(org.apache.rocketmq.common.protocol.header.ViewBrokerStatsDataRequestHeader) MQClientException(org.apache.rocketmq.client.exception.MQClientException) BrokerStatsData(org.apache.rocketmq.common.protocol.body.BrokerStatsData)

Example 7 with BrokerStatsData

use of org.apache.rocketmq.common.protocol.body.BrokerStatsData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class StatsAllSubCommand method printTopicDetail.

public static void printTopicDetail(final DefaultMQAdminExt admin, final String topic, final boolean activeTopic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    TopicRouteData topicRouteData = admin.examineTopicRouteInfo(topic);
    GroupList groupList = admin.queryTopicConsumeByWho(topic);
    double inTPS = 0;
    long inMsgCntToday = 0;
    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
        if (masterAddr != null) {
            try {
                BrokerStatsData bsd = admin.viewBrokerStatsData(masterAddr, BrokerStatsManager.TOPIC_PUT_NUMS, topic);
                inTPS += bsd.getStatsMinute().getTps();
                inMsgCntToday += compute24HourSum(bsd);
            } catch (Exception e) {
            }
        }
    }
    if (groupList != null && !groupList.getGroupList().isEmpty()) {
        for (String group : groupList.getGroupList()) {
            double outTPS = 0;
            long outMsgCntToday = 0;
            for (BrokerData bd : topicRouteData.getBrokerDatas()) {
                String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
                if (masterAddr != null) {
                    try {
                        String statsKey = String.format("%s@%s", topic, group);
                        BrokerStatsData bsd = admin.viewBrokerStatsData(masterAddr, BrokerStatsManager.GROUP_GET_NUMS, statsKey);
                        outTPS += bsd.getStatsMinute().getTps();
                        outMsgCntToday += compute24HourSum(bsd);
                    } catch (Exception e) {
                    }
                }
            }
            long accumulate = 0;
            try {
                ConsumeStats consumeStats = admin.examineConsumeStats(group, topic);
                if (consumeStats != null) {
                    accumulate = consumeStats.computeTotalDiff();
                    if (accumulate < 0) {
                        accumulate = 0;
                    }
                }
            } catch (Exception e) {
            }
            if (!activeTopic || (inMsgCntToday > 0) || (outMsgCntToday > 0)) {
                // 第二个参数默认是32,有时候消费者长度过长显示不去,修改为52
                System.out.printf("%-32s  %-52s %12d %11.2f %11.2f %14d %14d%n", UtilAll.frontStringAtLeast(topic, 32), // 有时候消费者长度过长显示不去,修改为52
                UtilAll.frontStringAtLeast(group, 52), accumulate, inTPS, outTPS, inMsgCntToday, outMsgCntToday);
            }
        }
    } else {
        if (!activeTopic || (inMsgCntToday > 0)) {
            // 第二个参数默认是32,有时候消费者长度过长显示不去,修改为52
            System.out.printf("%-32s  %-52s %12d %11.2f %11s %14d %14s%n", UtilAll.frontStringAtLeast(topic, 52), "", 0, inTPS, "", inMsgCntToday, "NO_CONSUMER");
        }
    }
}
Also used : GroupList(org.apache.rocketmq.common.protocol.body.GroupList) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) BrokerStatsData(org.apache.rocketmq.common.protocol.body.BrokerStatsData)

Aggregations

BrokerStatsData (org.apache.rocketmq.common.protocol.body.BrokerStatsData)7 MQClientException (org.apache.rocketmq.client.exception.MQClientException)4 ViewBrokerStatsDataRequestHeader (org.apache.rocketmq.common.protocol.header.ViewBrokerStatsDataRequestHeader)4 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)4 GroupList (org.apache.rocketmq.common.protocol.body.GroupList)3 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)3 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)3 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)2 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)2 BrokerStatsItem (org.apache.rocketmq.common.protocol.body.BrokerStatsItem)2 StatsItem (org.apache.rocketmq.common.stats.StatsItem)2 StatsSnapshot (org.apache.rocketmq.common.stats.StatsSnapshot)2 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)2 DefaultMessageStore (org.apache.rocketmq.store.DefaultMessageStore)2 SubCommandException (org.apache.rocketmq.tools.command.SubCommandException)2 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 ExecutionException (java.util.concurrent.ExecutionException)1