com.alibaba.rocketmq.common.admin.ConsumeStats Java Examples

The following examples show how to use com.alibaba.rocketmq.common.admin.ConsumeStats. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MQClientAPIImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final String topic, final long timeoutMillis)
        throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException,
        MQBrokerException {
    GetConsumeStatsRequestHeader requestHeader = new GetConsumeStatsRequestHeader();
    requestHeader.setConsumerGroup(consumerGroup);
    requestHeader.setTopic(topic);

    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUME_STATS, requestHeader);

    RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis);
    switch (response.getCode()) {
    case ResponseCode.SUCCESS: {
        ConsumeStats consumeStats = ConsumeStats.decode(response.getBody(), ConsumeStats.class);
        return consumeStats;
    }
    default:
        break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #2
Source File: MQClientAPIImpl.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final String topic, final long timeoutMillis)
        throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException,
        MQBrokerException {
    GetConsumeStatsRequestHeader requestHeader = new GetConsumeStatsRequestHeader();
    requestHeader.setConsumerGroup(consumerGroup);
    requestHeader.setTopic(topic);

    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_CONSUME_STATS, requestHeader);

    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr),
            request, timeoutMillis);
    switch (response.getCode()) {
        case ResponseCode.SUCCESS: {
            ConsumeStats consumeStats = ConsumeStats.decode(response.getBody(), ConsumeStats.class);
            return consumeStats;
        }
        default:
            break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #3
Source File: ConsumerServiceImpl.java    From rocket-console with Apache License 2.0 6 votes vote down vote up
@Override
public List<TopicConsumerInfo> queryConsumeStatsList(final String topic, String groupName) {
    ConsumeStats consumeStats = null;
    try {
        consumeStats = mqAdminExt.examineConsumeStats(groupName); // todo  ConsumeStats examineConsumeStats(final String consumerGroup, final String topic) can use
    } catch (Exception e) {
        throw propagate(e);
    }
    List<MessageQueue> mqList = Lists.newArrayList(Iterables.filter(consumeStats.getOffsetTable().keySet(), new Predicate<MessageQueue>() {
        @Override
        public boolean apply(MessageQueue o) {
            return StringUtils.isBlank(topic) || o.getTopic().equals(topic);
        }
    }));
    Collections.sort(mqList);
    List<TopicConsumerInfo> topicConsumerInfoList = Lists.newArrayList();
    TopicConsumerInfo nowTopicConsumerInfo = null;
    for (MessageQueue mq : mqList) {
        if (nowTopicConsumerInfo == null || (!StringUtils.equals(mq.getTopic(), nowTopicConsumerInfo.getTopic()))) {
            nowTopicConsumerInfo = new TopicConsumerInfo(mq.getTopic());
            topicConsumerInfoList.add(nowTopicConsumerInfo);
        }
        nowTopicConsumerInfo.appendQueueStatInfo(QueueStatInfo.fromOffsetTableEntry(mq, consumeStats.getOffsetTable().get(mq)));
    }
    return topicConsumerInfoList;
}
 
Example #4
Source File: CloneGroupOffsetCommand.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    String srcGroup = commandLine.getOptionValue("s").trim();
    String destGroup = commandLine.getOptionValue("d").trim();
    String topic = commandLine.getOptionValue("t").trim();

    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName("admin-" + Long.toString(System.currentTimeMillis()));

    try {
        defaultMQAdminExt.start();
        ConsumeStats consumeStats = defaultMQAdminExt.examineConsumeStats(srcGroup);
        Set<MessageQueue> mqs = consumeStats.getOffsetTable().keySet();
        if (mqs != null && !mqs.isEmpty()) {
            TopicRouteData topicRoute = defaultMQAdminExt.examineTopicRouteInfo(topic);
            for (MessageQueue mq : mqs) {
                String addr = null;
                for (BrokerData brokerData : topicRoute.getBrokerDatas()) {
                    if (brokerData.getBrokerName().equals(mq.getBrokerName())) {
                        addr = brokerData.selectBrokerAddr();
                        break;
                    }
                }
                long offset = consumeStats.getOffsetTable().get(mq).getBrokerOffset();
                if (offset >= 0) {
                    defaultMQAdminExt.updateConsumeOffset(addr, destGroup, mq, offset);
                }
            }
        }
        System.out.printf("clone group offset success. srcGroup[%s], destGroup=[%s], topic[%s]",
                srcGroup, destGroup, topic);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example #5
Source File: ConsumerServiceImpl.java    From rocket-console with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> fetchBrokerNameSetBySubscriptionGroup(String group){
    Set<String> brokerNameSet = Sets.newHashSet();
    ConsumeStats consumeStats = null;
    try {
        consumeStats = mqAdminExt.examineConsumeStats(group);
    } catch (Exception err){
        throw propagate(err);
    }
    for(MessageQueue messageQueue : consumeStats.getOffsetTable().keySet()){
        brokerNameSet.add(messageQueue.getBrokerName());
    }
    return brokerNameSet;

}
 
Example #6
Source File: MQAdminExt.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
ConsumeStats examineConsumeStats(final String consumerGroup, final String topic) throws RemotingException, MQClientException,
InterruptedException, MQBrokerException;
 
Example #7
Source File: AdminBrokerProcessor.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, RemotingCommand request)
        throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final GetConsumeStatsRequestHeader requestHeader = (GetConsumeStatsRequestHeader) request
        .decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class);

    ConsumeStats consumeStats = new ConsumeStats();

    Set<String> topics = new HashSet<String>();
    if (UtilAll.isBlank(requestHeader.getTopic())) {
        topics = this.brokerController.getConsumerOffsetManager()
            .whichTopicByConsumer(requestHeader.getConsumerGroup());
    }
    else {
        topics.add(requestHeader.getTopic());
    }

    for (String topic : topics) {
        TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic);
        if (null == topicConfig) {
            log.warn("consumeStats, topic config not exist, {}", topic);
            continue;
        }

        /**
         * Consumer不在线的时候,也允许查询消费进度
         */
        {
            SubscriptionData findSubscriptionData = this.brokerController.getConsumerManager()
                .findSubscriptionData(requestHeader.getConsumerGroup(), topic);
            // 如果Consumer在线,而且这个topic没有被订阅,那么就跳过
            if (null == findSubscriptionData //
                    && this.brokerController.getConsumerManager()
                        .findSubscriptionDataCount(requestHeader.getConsumerGroup()) > 0) {
                log.warn("consumeStats, the consumer group[{}], topic[{}] not exist",
                    requestHeader.getConsumerGroup(), 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().getMaxOffsetInQuque(topic, i);
            if (brokerOffset < 0)
                brokerOffset = 0;

            long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(//
                requestHeader.getConsumerGroup(), //
                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);
        }

        long consumeTps = (long) this.brokerController.getBrokerStatsManager()
            .tpsGroupGetNums(requestHeader.getConsumerGroup(), topic);

        consumeTps += consumeStats.getConsumeTps();
        consumeStats.setConsumeTps(consumeTps);
    }

    byte[] body = consumeStats.encode();
    response.setBody(body);
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example #8
Source File: MonitorService.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
private void computeUndoneMsgs(final UndoneMsgs undoneMsgs, final ConsumeStats consumeStats) {
    long total = 0;
    long singleMax = 0;
    long delayMax = 0;
    Iterator<Entry<MessageQueue, OffsetWrapper>> it = consumeStats.getOffsetTable().entrySet().iterator();
    while (it.hasNext()) {
        Entry<MessageQueue, OffsetWrapper> next = it.next();
        MessageQueue mq = next.getKey();
        OffsetWrapper ow = next.getValue();
        long diff = ow.getBrokerOffset() - ow.getConsumerOffset();

        if (diff > singleMax) {
            singleMax = diff;
        }

        if (diff > 0) {
            total += diff;
        }

        // Delay
        if (ow.getLastTimestamp() > 0) {
            try {
                long maxOffset = this.defaultMQPullConsumer.maxOffset(mq);
                if (maxOffset > 0) {
                    PullResult pull = this.defaultMQPullConsumer.pull(mq, "*", maxOffset - 1, 1);
                    switch (pull.getPullStatus()) {
                        case FOUND:
                            long delay =
                                    pull.getMsgFoundList().get(0).getStoreTimestamp() - ow.getLastTimestamp();
                            if (delay > delayMax) {
                                delayMax = delay;
                            }
                            break;
                        case NO_MATCHED_MSG:
                        case NO_NEW_MSG:
                        case OFFSET_ILLEGAL:
                            break;
                        default:
                            break;
                    }
                }
            } catch (Exception e) {
            }
        }
    }

    undoneMsgs.setUndoneMsgsTotal(total);
    undoneMsgs.setUndoneMsgsSingleMQ(singleMax);
    undoneMsgs.setUndoneMsgsDelayTimeMills(delayMax);
}
 
Example #9
Source File: AdminBrokerProcessor.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final GetConsumeStatsRequestHeader requestHeader =
            (GetConsumeStatsRequestHeader) request.decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class);

    ConsumeStats consumeStats = new ConsumeStats();

    Set<String> topics = new HashSet<String>();
    if (UtilAll.isBlank(requestHeader.getTopic())) {
        topics = this.brokerController.getConsumerOffsetManager().whichTopicByConsumer(requestHeader.getConsumerGroup());
    } else {
        topics.add(requestHeader.getTopic());
    }

    for (String topic : topics) {
        TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic);
        if (null == topicConfig) {
            log.warn("consumeStats, topic config not exist, {}", topic);
            continue;
        }

        /**

         */
        {
            SubscriptionData findSubscriptionData =
                    this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getConsumerGroup(), topic);

            if (null == findSubscriptionData //
                    && this.brokerController.getConsumerManager().findSubscriptionDataCount(requestHeader.getConsumerGroup()) > 0) {
                log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", requestHeader.getConsumerGroup(), topic);
                continue;
            }
        }

        for (int i = 0; i < topicConfig.getReadQueueNums(); 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().getMaxOffsetInQuque(topic, i);
            if (brokerOffset < 0)
                brokerOffset = 0;

            long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(//
                    requestHeader.getConsumerGroup(), //
                    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(requestHeader.getConsumerGroup(), topic);

        consumeTps += consumeStats.getConsumeTps();
        consumeStats.setConsumeTps(consumeTps);
    }

    byte[] body = consumeStats.encode();
    response.setBody(body);
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example #10
Source File: ConsumeStatsList.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public List<Map<String, List<ConsumeStats>>> getConsumeStatsList() {
    return consumeStatsList;
}
 
Example #11
Source File: ConsumeStatsList.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public void setConsumeStatsList(List<Map<String, List<ConsumeStats>>> consumeStatsList) {
    this.consumeStatsList = consumeStatsList;
}
 
Example #12
Source File: MQClientAPIImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public ConsumeStats getConsumeStats(final String addr, final String consumerGroup,
        final long timeoutMillis) throws InterruptedException, RemotingTimeoutException,
                RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    return getConsumeStats(addr, consumerGroup, null, timeoutMillis);
}
 
Example #13
Source File: MQClientAPIImpl.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
/**
 * 从Broker获取消费状态(进度)
 * 
 * @param addr
 * @param consumerGroup
 * @param topic
 * @param timeoutMillis
 * @return
 * @throws InterruptedException
 * @throws RemotingTimeoutException
 * @throws RemotingSendRequestException
 * @throws RemotingConnectException
 * @throws MQBrokerException
 */
public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final String topic,
        final long timeoutMillis) throws InterruptedException, RemotingTimeoutException,
                RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    String consumerGroupWithProjectGroup = consumerGroup;
    if (!UtilAll.isBlank(projectGroupPrefix)) {
        consumerGroupWithProjectGroup =
                VirtualEnvUtil.buildWithProjectGroup(consumerGroup, projectGroupPrefix);
    }

    GetConsumeStatsRequestHeader requestHeader = new GetConsumeStatsRequestHeader();
    requestHeader.setConsumerGroup(consumerGroupWithProjectGroup);
    requestHeader.setTopic(topic);

    RemotingCommand request =
            RemotingCommand.createRequestCommand(RequestCode.GET_CONSUME_STATS, requestHeader);

    RemotingCommand response = this.remotingClient.invokeSync(addr, request, timeoutMillis);
    switch (response.getCode()) {
    case ResponseCode.SUCCESS: {
        ConsumeStats consumeStats = ConsumeStats.decode(response.getBody(), ConsumeStats.class);
        if (!UtilAll.isBlank(projectGroupPrefix)) {
            HashMap<MessageQueue, OffsetWrapper> newTopicOffsetMap =
                    new HashMap<MessageQueue, OffsetWrapper>();
            for (Map.Entry<MessageQueue, OffsetWrapper> messageQueue : consumeStats.getOffsetTable()
                .entrySet()) {
                MessageQueue key = messageQueue.getKey();
                key.setTopic(VirtualEnvUtil.clearProjectGroup(key.getTopic(), projectGroupPrefix));
                newTopicOffsetMap.put(key, messageQueue.getValue());
            }
            consumeStats.setOffsetTable(newTopicOffsetMap);
        }

        return consumeStats;
    }
    default:
        break;
    }

    throw new MQBrokerException(response.getCode(), response.getRemark());
}
 
Example #14
Source File: DefaultMQAdminExt.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
@Override
public ConsumeStats examineConsumeStats(String consumerGroup)
        throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    return examineConsumeStats(consumerGroup, null);
}
 
Example #15
Source File: DefaultMQAdminExt.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
@Override
public ConsumeStats examineConsumeStats(String consumerGroup, String topic)
        throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    return defaultMQAdminExtImpl.examineConsumeStats(consumerGroup, topic);
}
 
Example #16
Source File: MQAdminExt.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
public ConsumeStats examineConsumeStats(final String consumerGroup, final String topic)
throws RemotingException, MQClientException, InterruptedException, MQBrokerException;
 
Example #17
Source File: MonitorService.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
private void computeUndoneMsgs(final UndoneMsgs undoneMsgs, final ConsumeStats consumeStats) {
    long total = 0;
    long singleMax = 0;
    long delayMax = 0;
    Iterator<Entry<MessageQueue, OffsetWrapper>> it = consumeStats.getOffsetTable().entrySet().iterator();
    while (it.hasNext()) {
        Entry<MessageQueue, OffsetWrapper> next = it.next();
        MessageQueue mq = next.getKey();
        OffsetWrapper ow = next.getValue();
        long diff = ow.getBrokerOffset() - ow.getConsumerOffset();

        if (diff > singleMax) {
            singleMax = diff;
        }

        if (diff > 0) {
            total += diff;
        }

        // Delay
        if (ow.getLastTimestamp() > 0) {
            try {
                long maxOffset = this.defaultMQPullConsumer.maxOffset(mq);
                if (maxOffset > 0) {
                    PullResult pull = this.defaultMQPullConsumer.pull(mq, "*", maxOffset - 1, 1);
                    switch (pull.getPullStatus()) {
                    case FOUND:
                        long delay =
                                pull.getMsgFoundList().get(0).getStoreTimestamp() - ow.getLastTimestamp();
                        if (delay > delayMax) {
                            delayMax = delay;
                        }
                        break;
                    case NO_MATCHED_MSG:
                    case NO_NEW_MSG:
                    case OFFSET_ILLEGAL:
                        break;
                    default:
                        break;
                    }
                }
            }
            catch (Exception e) {
            }
        }
    }

    undoneMsgs.setUndoneMsgsTotal(total);
    undoneMsgs.setUndoneMsgsSingleMQ(singleMax);
    undoneMsgs.setUndoneMsgsDelayTimeMills(delayMax);
}
 
Example #18
Source File: MQClientAPIImpl.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final long timeoutMillis)
        throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException,
        MQBrokerException {
    return getConsumeStats(addr, consumerGroup, null, timeoutMillis);
}
 
Example #19
Source File: MQAdminExt.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
ConsumeStats examineConsumeStats(final String consumerGroup) throws RemotingException, MQClientException, InterruptedException,
MQBrokerException;
 
Example #20
Source File: DefaultMQAdminExt.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public ConsumeStats examineConsumeStats(String consumerGroup, String topic) throws RemotingException, MQClientException,
        InterruptedException, MQBrokerException {
    return defaultMQAdminExtImpl.examineConsumeStats(consumerGroup, topic);
}
 
Example #21
Source File: DefaultMQAdminExt.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
@Override
public ConsumeStats examineConsumeStats(String consumerGroup) throws RemotingException, MQClientException, InterruptedException,
        MQBrokerException {
    return examineConsumeStats(consumerGroup, null);
}
 
Example #22
Source File: MQClientAPIImpl.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
public ConsumeStats getConsumeStats(final String addr, final String consumerGroup, final long timeoutMillis)
        throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException,
        MQBrokerException {
    return getConsumeStats(addr, consumerGroup, null, timeoutMillis);
}
 
Example #23
Source File: MQAdminExtImpl.java    From rocket-console with Apache License 2.0 4 votes vote down vote up
@Override
public ConsumeStats examineConsumeStats(String consumerGroup, String topic)
        throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    return MQAdminInstance.threadLocalMQAdminExt().examineConsumeStats(consumerGroup, topic);
}
 
Example #24
Source File: MQAdminExtImpl.java    From rocket-console with Apache License 2.0 4 votes vote down vote up
@Override
public ConsumeStats examineConsumeStats(String consumerGroup)
        throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    return MQAdminInstance.threadLocalMQAdminExt().examineConsumeStats(consumerGroup);
}
 
Example #25
Source File: ConsumeStatsList.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public void setConsumeStatsList(List<Map<String, List<ConsumeStats>>> consumeStatsList) {
    this.consumeStatsList = consumeStatsList;
}
 
Example #26
Source File: ConsumeStatsList.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
public List<Map<String, List<ConsumeStats>>> getConsumeStatsList() {
    return consumeStatsList;
}
 
Example #27
Source File: AdminBrokerProcessor.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
private RemotingCommand getConsumeStats(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final GetConsumeStatsRequestHeader requestHeader =
            (GetConsumeStatsRequestHeader) request.decodeCommandCustomHeader(GetConsumeStatsRequestHeader.class);

    ConsumeStats consumeStats = new ConsumeStats();

    Set<String> topics = new HashSet<String>();
    if (UtilAll.isBlank(requestHeader.getTopic())) {
        topics = this.brokerController.getConsumerOffsetManager().whichTopicByConsumer(requestHeader.getConsumerGroup());
    }
    else {
        topics.add(requestHeader.getTopic());
    }

    for (String topic : topics) {
        TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic);
        if (null == topicConfig) {
            log.warn("consumeStats, topic config not exist, {}", topic);
            continue;
        }
        {
            SubscriptionData findSubscriptionData =
                    this.brokerController.getConsumerManager().findSubscriptionData(requestHeader.getConsumerGroup(), topic);
            if (null == findSubscriptionData //
                    && this.brokerController.getConsumerManager().findSubscriptionDataCount(requestHeader.getConsumerGroup()) > 0) {
                log.warn("consumeStats, the consumer group[{}], topic[{}] not exist", requestHeader.getConsumerGroup(), topic);
                continue;
            }
        }

        for (int i = 0; i < topicConfig.getReadQueueNums(); 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().getMaxOffsetInQuque(topic, i);
            if (brokerOffset < 0)
                brokerOffset = 0;

            long consumerOffset = this.brokerController.getConsumerOffsetManager().queryOffset(//
                requestHeader.getConsumerGroup(),//
                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(requestHeader.getConsumerGroup(), topic);

        consumeTps += consumeStats.getConsumeTps();
        consumeStats.setConsumeTps(consumeTps);
    }

    byte[] body = consumeStats.encode();
    response.setBody(body);
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
 
Example #28
Source File: MonitorService.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
private void computeUndoneMsgs(final UndoneMsgs undoneMsgs, final ConsumeStats consumeStats) {
    long total = 0;
    long singleMax = 0;
    long delayMax = 0;
    Iterator<Entry<MessageQueue, OffsetWrapper>> it = consumeStats.getOffsetTable().entrySet().iterator();
    while (it.hasNext()) {
        Entry<MessageQueue, OffsetWrapper> next = it.next();
        MessageQueue mq = next.getKey();
        OffsetWrapper ow = next.getValue();
        long diff = ow.getBrokerOffset() - ow.getConsumerOffset();

        if (diff > singleMax) {
            singleMax = diff;
        }

        if (diff > 0) {
            total += diff;
        }

        // Delay
        if (ow.getLastTimestamp() > 0) {
            try {
                long maxOffset = this.defaultMQPullConsumer.maxOffset(mq);
                if (maxOffset > 0) {
                    PullResult pull = this.defaultMQPullConsumer.pull(mq, "*", maxOffset - 1, 1);
                    switch (pull.getPullStatus()) {
                    case FOUND:
                        long delay =
                                pull.getMsgFoundList().get(0).getStoreTimestamp() - ow.getLastTimestamp();
                        if (delay > delayMax) {
                            delayMax = delay;
                        }
                        break;
                    case NO_MATCHED_MSG:
                    case NO_NEW_MSG:
                    case OFFSET_ILLEGAL:
                        break;
                    default:
                        break;
                    }
                }
            }
            catch (Exception e) {
            }
        }
    }

    undoneMsgs.setUndoneMsgsTotal(total);
    undoneMsgs.setUndoneMsgsSingleMQ(singleMax);
    undoneMsgs.setUndoneMsgsDelayTimeMills(delayMax);
}
 
Example #29
Source File: MQAdminExt.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
ConsumeStats examineConsumeStats(final String consumerGroup, final String topic) throws RemotingException, MQClientException,
InterruptedException, MQBrokerException;
 
Example #30
Source File: MQAdminExt.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
ConsumeStats examineConsumeStats(final String consumerGroup) throws RemotingException, MQClientException, InterruptedException,
MQBrokerException;