Search in sources :

Example 1 with GetConsumeStatsInBrokerHeader

use of org.apache.rocketmq.common.protocol.header.GetConsumeStatsInBrokerHeader in project rocketmq by apache.

the class MQClientAPIImpl method fetchConsumeStatsInBroker.

public ConsumeStatsList fetchConsumeStatsInBroker(String brokerAddr, boolean isOrder, long timeoutMillis) throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException {
    GetConsumeStatsInBrokerHeader requestHeader = new GetConsumeStatsInBrokerHeader();
    requestHeader.setIsOrder(isOrder);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CONSUME_STATS, 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 ConsumeStatsList.decode(body, ConsumeStatsList.class);
                }
            }
        default:
            break;
    }
    throw new MQClientException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ConsumeStatsList(org.apache.rocketmq.common.protocol.body.ConsumeStatsList) GetConsumeStatsInBrokerHeader(org.apache.rocketmq.common.protocol.header.GetConsumeStatsInBrokerHeader) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 2 with GetConsumeStatsInBrokerHeader

use of org.apache.rocketmq.common.protocol.header.GetConsumeStatsInBrokerHeader in project rocketmq by apache.

the class AdminBrokerProcessor method fetchAllConsumeStatsInBroker.

private RemotingCommand fetchAllConsumeStatsInBroker(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    GetConsumeStatsInBrokerHeader requestHeader = (GetConsumeStatsInBrokerHeader) request.decodeCommandCustomHeader(GetConsumeStatsInBrokerHeader.class);
    boolean isOrder = requestHeader.isOrder();
    ConcurrentMap<String, SubscriptionGroupConfig> subscriptionGroups = brokerController.getSubscriptionGroupManager().getSubscriptionGroupTable();
    List<Map<String, List<ConsumeStats>>> /* subscriptionGroupName */
    brokerConsumeStatsList = new ArrayList<Map<String, List<ConsumeStats>>>();
    long totalDiff = 0L;
    for (String group : subscriptionGroups.keySet()) {
        Map<String, List<ConsumeStats>> subscripTopicConsumeMap = new HashMap<String, List<ConsumeStats>>();
        Set<String> topics = this.brokerController.getConsumerOffsetManager().whichTopicByConsumer(group);
        List<ConsumeStats> consumeStatsList = new ArrayList<ConsumeStats>();
        for (String topic : topics) {
            ConsumeStats consumeStats = new ConsumeStats();
            TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic);
            if (null == topicConfig) {
                log.warn("consumeStats, topic config not exist, {}", topic);
                continue;
            }
            if (isOrder && !topicConfig.isOrder()) {
                continue;
            }
            {
                SubscriptionData findSubscriptionData = this.brokerController.getConsumerManager().findSubscriptionData(group, topic);
                if (null == findSubscriptionData && this.brokerController.getConsumerManager().findSubscriptionDataCount(group) > 0) {
                    log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", group, topic);
                    continue;
                }
            }
            for (int i = 0; i < topicConfig.getWriteQueueNums(); i++) {
                MessageQueue mq = new MessageQueue();
                mq.setTopic(topic);
                mq.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName());
                mq.setQueueId(i);
                OffsetWrapper offsetWrapper = new OffsetWrapper();
                long brokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i);
                if (brokerOffset < 0)
                    brokerOffset = 0;
                long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(group, topic, i);
                if (consumerOffset < 0)
                    consumerOffset = 0;
                offsetWrapper.setBrokerOffset(brokerOffset);
                offsetWrapper.setConsumerOffset(consumerOffset);
                long timeOffset = consumerOffset - 1;
                if (timeOffset >= 0) {
                    long lastTimestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, timeOffset);
                    if (lastTimestamp > 0) {
                        offsetWrapper.setLastTimestamp(lastTimestamp);
                    }
                }
                consumeStats.getOffsetTable().put(mq, offsetWrapper);
            }
            double consumeTps = this.brokerController.getBrokerStatsManager().tpsGroupGetNums(group, topic);
            consumeTps += consumeStats.getConsumeTps();
            consumeStats.setConsumeTps(consumeTps);
            totalDiff += consumeStats.computeTotalDiff();
            consumeStatsList.add(consumeStats);
        }
        subscripTopicConsumeMap.put(group, consumeStatsList);
        brokerConsumeStatsList.add(subscripTopicConsumeMap);
    }
    ConsumeStatsList consumeStats = new ConsumeStatsList();
    consumeStats.setBrokerAddr(brokerController.getBrokerAddr());
    consumeStats.setConsumeStatsList(brokerConsumeStatsList);
    consumeStats.setTotalDiff(totalDiff);
    response.setBody(consumeStats.encode());
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
Also used : ConsumeStatsList(org.apache.rocketmq.common.protocol.body.ConsumeStatsList) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TopicConfig(org.apache.rocketmq.common.TopicConfig) SubscriptionGroupConfig(org.apache.rocketmq.common.subscription.SubscriptionGroupConfig) OffsetWrapper(org.apache.rocketmq.common.admin.OffsetWrapper) RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) GetConsumeStatsInBrokerHeader(org.apache.rocketmq.common.protocol.header.GetConsumeStatsInBrokerHeader) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) ArrayList(java.util.ArrayList) ConsumeStatsList(org.apache.rocketmq.common.protocol.body.ConsumeStatsList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 3 with GetConsumeStatsInBrokerHeader

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

the class MQClientAPIImpl method fetchConsumeStatsInBroker.

public ConsumeStatsList fetchConsumeStatsInBroker(String brokerAddr, boolean isOrder, long timeoutMillis) throws MQClientException, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException, InterruptedException {
    GetConsumeStatsInBrokerHeader requestHeader = new GetConsumeStatsInBrokerHeader();
    requestHeader.setIsOrder(isOrder);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_BROKER_CONSUME_STATS, 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 ConsumeStatsList.decode(body, ConsumeStatsList.class);
                }
            }
        default:
            break;
    }
    throw new MQClientException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) ConsumeStatsList(org.apache.rocketmq.common.protocol.body.ConsumeStatsList) GetConsumeStatsInBrokerHeader(org.apache.rocketmq.common.protocol.header.GetConsumeStatsInBrokerHeader) MQClientException(org.apache.rocketmq.client.exception.MQClientException)

Example 4 with GetConsumeStatsInBrokerHeader

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

the class AdminBrokerProcessor method fetchAllConsumeStatsInBroker.

private RemotingCommand fetchAllConsumeStatsInBroker(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    GetConsumeStatsInBrokerHeader requestHeader = (GetConsumeStatsInBrokerHeader) request.decodeCommandCustomHeader(GetConsumeStatsInBrokerHeader.class);
    boolean isOrder = requestHeader.isOrder();
    ConcurrentMap<String, SubscriptionGroupConfig> subscriptionGroups = brokerController.getSubscriptionGroupManager().getSubscriptionGroupTable();
    List<Map<String, List<ConsumeStats>>> /* subscriptionGroupName */
    brokerConsumeStatsList = new ArrayList<Map<String, List<ConsumeStats>>>();
    long totalDiff = 0L;
    for (String group : subscriptionGroups.keySet()) {
        Map<String, List<ConsumeStats>> subscripTopicConsumeMap = new HashMap<String, List<ConsumeStats>>();
        Set<String> topics = this.brokerController.getConsumerOffsetManager().whichTopicByConsumer(group);
        List<ConsumeStats> consumeStatsList = new ArrayList<ConsumeStats>();
        for (String topic : topics) {
            ConsumeStats consumeStats = new ConsumeStats();
            TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic);
            if (null == topicConfig) {
                log.warn("consumeStats, topic config not exist, {}", topic);
                continue;
            }
            if (isOrder && !topicConfig.isOrder()) {
                continue;
            }
            /**
             */
            {
                SubscriptionData findSubscriptionData = this.brokerController.getConsumerManager().findSubscriptionData(group, topic);
                if (// 
                null == findSubscriptionData && this.brokerController.getConsumerManager().findSubscriptionDataCount(group) > 0) {
                    log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", group, topic);
                    continue;
                }
            }
            for (int i = 0; i < topicConfig.getWriteQueueNums(); i++) {
                MessageQueue mq = new MessageQueue();
                mq.setTopic(topic);
                mq.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName());
                mq.setQueueId(i);
                OffsetWrapper offsetWrapper = new OffsetWrapper();
                long brokerOffset = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i);
                if (brokerOffset < 0)
                    brokerOffset = 0;
                long consumerOffset = // 
                this.brokerController.getConsumerOffsetManager().queryOffset(// 
                group, // 
                topic, i);
                if (consumerOffset < 0)
                    consumerOffset = 0;
                offsetWrapper.setBrokerOffset(brokerOffset);
                offsetWrapper.setConsumerOffset(consumerOffset);
                long timeOffset = consumerOffset - 1;
                if (timeOffset >= 0) {
                    long lastTimestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, timeOffset);
                    if (lastTimestamp > 0) {
                        offsetWrapper.setLastTimestamp(lastTimestamp);
                    }
                }
                consumeStats.getOffsetTable().put(mq, offsetWrapper);
            }
            double consumeTps = this.brokerController.getBrokerStatsManager().tpsGroupGetNums(group, topic);
            consumeTps += consumeStats.getConsumeTps();
            consumeStats.setConsumeTps(consumeTps);
            totalDiff += consumeStats.computeTotalDiff();
            consumeStatsList.add(consumeStats);
        }
        subscripTopicConsumeMap.put(group, consumeStatsList);
        brokerConsumeStatsList.add(subscripTopicConsumeMap);
    }
    ConsumeStatsList consumeStats = new ConsumeStatsList();
    consumeStats.setBrokerAddr(brokerController.getBrokerAddr());
    consumeStats.setConsumeStatsList(brokerConsumeStatsList);
    consumeStats.setTotalDiff(totalDiff);
    response.setBody(consumeStats.encode());
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
Also used : ConsumeStatsList(org.apache.rocketmq.common.protocol.body.ConsumeStatsList) ConsumeStats(org.apache.rocketmq.common.admin.ConsumeStats) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TopicConfig(org.apache.rocketmq.common.TopicConfig) SubscriptionGroupConfig(org.apache.rocketmq.common.subscription.SubscriptionGroupConfig) OffsetWrapper(org.apache.rocketmq.common.admin.OffsetWrapper) RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) GetConsumeStatsInBrokerHeader(org.apache.rocketmq.common.protocol.header.GetConsumeStatsInBrokerHeader) SubscriptionData(org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) ArrayList(java.util.ArrayList) ConsumeStatsList(org.apache.rocketmq.common.protocol.body.ConsumeStatsList) List(java.util.List) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Aggregations

ConsumeStatsList (org.apache.rocketmq.common.protocol.body.ConsumeStatsList)4 GetConsumeStatsInBrokerHeader (org.apache.rocketmq.common.protocol.header.GetConsumeStatsInBrokerHeader)4 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2 TopicConfig (org.apache.rocketmq.common.TopicConfig)2 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)2 OffsetWrapper (org.apache.rocketmq.common.admin.OffsetWrapper)2 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)2 GroupList (org.apache.rocketmq.common.protocol.body.GroupList)2 TopicList (org.apache.rocketmq.common.protocol.body.TopicList)2 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)2 SubscriptionGroupConfig (org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)2