Search in sources :

Example 1 with TopicStatsTable

use of org.apache.rocketmq.common.admin.TopicStatsTable in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class DefaultMQAdminExtImpl method examineTopicStats.

@Override
public TopicStatsTable examineTopicStats(String topic) throws RemotingException, MQClientException, InterruptedException, MQBrokerException {
    TopicRouteData topicRouteData = this.examineTopicRouteInfo(topic);
    TopicStatsTable topicStatsTable = new TopicStatsTable();
    for (BrokerData bd : topicRouteData.getBrokerDatas()) {
        String addr = bd.selectBrokerAddr();
        if (addr != null) {
            TopicStatsTable tst = this.mqClientInstance.getMQClientAPIImpl().getTopicStatsInfo(addr, topic, timeoutMillis);
            topicStatsTable.getOffsetTable().putAll(tst.getOffsetTable());
        }
    }
    if (topicStatsTable.getOffsetTable().isEmpty()) {
        throw new MQClientException("Not found the topic stats info", null);
    }
    return topicStatsTable;
}
Also used : TopicStatsTable(org.apache.rocketmq.common.admin.TopicStatsTable) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) MQClientException(org.apache.rocketmq.client.exception.MQClientException) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData)

Example 2 with TopicStatsTable

use of org.apache.rocketmq.common.admin.TopicStatsTable in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class TopicStatusSubCommand method execute.

@Override
public void execute(final CommandLine commandLine, final Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        defaultMQAdminExt.start();
        String topic = commandLine.getOptionValue('t').trim();
        TopicStatsTable topicStatsTable = defaultMQAdminExt.examineTopicStats(topic);
        List<MessageQueue> mqList = new LinkedList<MessageQueue>();
        mqList.addAll(topicStatsTable.getOffsetTable().keySet());
        Collections.sort(mqList);
        System.out.printf("%-32s  %-4s  %-20s  %-20s    %s%n", "#Broker Name", "#QID", "#Min Offset", "#Max Offset", "#Last Updated");
        for (MessageQueue mq : mqList) {
            TopicOffset topicOffset = topicStatsTable.getOffsetTable().get(mq);
            String humanTimestamp = "";
            if (topicOffset.getLastUpdateTimestamp() > 0) {
                humanTimestamp = UtilAll.timeMillisToHumanString2(topicOffset.getLastUpdateTimestamp());
            }
            System.out.printf("%-32s  %-4d  %-20d  %-20d    %s%n", UtilAll.frontStringAtLeast(mq.getBrokerName(), 32), mq.getQueueId(), topicOffset.getMinOffset(), topicOffset.getMaxOffset(), humanTimestamp);
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : TopicOffset(org.apache.rocketmq.common.admin.TopicOffset) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) TopicStatsTable(org.apache.rocketmq.common.admin.TopicStatsTable) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) LinkedList(java.util.LinkedList) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException)

Example 3 with TopicStatsTable

use of org.apache.rocketmq.common.admin.TopicStatsTable in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class MQClientAPIImpl method getTopicStatsInfo.

public TopicStatsTable getTopicStatsInfo(final String addr, final String topic, final long timeoutMillis) throws InterruptedException, RemotingTimeoutException, RemotingSendRequestException, RemotingConnectException, MQBrokerException {
    GetTopicStatsInfoRequestHeader requestHeader = new GetTopicStatsInfoRequestHeader();
    requestHeader.setTopic(topic);
    RemotingCommand request = RemotingCommand.createRequestCommand(RequestCode.GET_TOPIC_STATS_INFO, requestHeader);
    RemotingCommand response = this.remotingClient.invokeSync(MixAll.brokerVIPChannel(this.clientConfig.isVipChannelEnabled(), addr), request, timeoutMillis);
    switch(response.getCode()) {
        case ResponseCode.SUCCESS:
            {
                TopicStatsTable topicStatsTable = TopicStatsTable.decode(response.getBody(), TopicStatsTable.class);
                return topicStatsTable;
            }
        default:
            break;
    }
    throw new MQBrokerException(response.getCode(), response.getRemark());
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) GetTopicStatsInfoRequestHeader(org.apache.rocketmq.common.protocol.header.GetTopicStatsInfoRequestHeader) TopicStatsTable(org.apache.rocketmq.common.admin.TopicStatsTable) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException)

Example 4 with TopicStatsTable

use of org.apache.rocketmq.common.admin.TopicStatsTable in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class AdminBrokerProcessor method getTopicStatsInfo.

private RemotingCommand getTopicStatsInfo(ChannelHandlerContext ctx, RemotingCommand request) throws RemotingCommandException {
    final RemotingCommand response = RemotingCommand.createResponseCommand(null);
    final GetTopicStatsInfoRequestHeader requestHeader = (GetTopicStatsInfoRequestHeader) request.decodeCommandCustomHeader(GetTopicStatsInfoRequestHeader.class);
    final String topic = requestHeader.getTopic();
    TopicConfig topicConfig = this.brokerController.getTopicConfigManager().selectTopicConfig(topic);
    if (null == topicConfig) {
        response.setCode(ResponseCode.TOPIC_NOT_EXIST);
        response.setRemark("topic[" + topic + "] not exist");
        return response;
    }
    TopicStatsTable topicStatsTable = new TopicStatsTable();
    for (int i = 0; i < topicConfig.getWriteQueueNums(); i++) {
        MessageQueue mq = new MessageQueue();
        mq.setTopic(topic);
        mq.setBrokerName(this.brokerController.getBrokerConfig().getBrokerName());
        mq.setQueueId(i);
        TopicOffset topicOffset = new TopicOffset();
        long min = this.brokerController.getMessageStore().getMinOffsetInQueue(topic, i);
        if (min < 0)
            min = 0;
        long max = this.brokerController.getMessageStore().getMaxOffsetInQueue(topic, i);
        if (max < 0)
            max = 0;
        long timestamp = 0;
        if (max > 0) {
            timestamp = this.brokerController.getMessageStore().getMessageStoreTimeStamp(topic, i, max - 1);
        }
        topicOffset.setMinOffset(min);
        topicOffset.setMaxOffset(max);
        topicOffset.setLastUpdateTimestamp(timestamp);
        topicStatsTable.getOffsetTable().put(mq, topicOffset);
    }
    byte[] body = topicStatsTable.encode();
    response.setBody(body);
    response.setCode(ResponseCode.SUCCESS);
    response.setRemark(null);
    return response;
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) TopicOffset(org.apache.rocketmq.common.admin.TopicOffset) GetTopicStatsInfoRequestHeader(org.apache.rocketmq.common.protocol.header.GetTopicStatsInfoRequestHeader) MessageQueue(org.apache.rocketmq.common.message.MessageQueue) TopicStatsTable(org.apache.rocketmq.common.admin.TopicStatsTable) TopicConfig(org.apache.rocketmq.common.TopicConfig)

Example 5 with TopicStatsTable

use of org.apache.rocketmq.common.admin.TopicStatsTable in project rocketmq-externals by apache.

the class TopicServiceImplTest method stats.

@Test
public void stats() throws Exception {
    TopicStatsTable topicStatsTable = topicService.stats(TEST_CONSOLE_TOPIC);
    Assert.assertNotNull(topicStatsTable);
    Assert.assertEquals(topicStatsTable.getOffsetTable().size(), READ_QUEUE_NUM);
}
Also used : TopicStatsTable(org.apache.rocketmq.common.admin.TopicStatsTable) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

TopicStatsTable (org.apache.rocketmq.common.admin.TopicStatsTable)13 TopicOffset (org.apache.rocketmq.common.admin.TopicOffset)6 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)6 GetTopicStatsInfoRequestHeader (org.apache.rocketmq.common.protocol.header.GetTopicStatsInfoRequestHeader)4 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)4 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)4 Field (java.lang.reflect.Field)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 TreeSet (java.util.TreeSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)2 MQClientException (org.apache.rocketmq.client.exception.MQClientException)2 MQClientAPIImpl (org.apache.rocketmq.client.impl.MQClientAPIImpl)2