Search in sources :

Example 11 with GroupList

use of org.apache.rocketmq.common.protocol.body.GroupList 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)

Example 12 with GroupList

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

the class TopicListSubCommand 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();
        if (commandLine.hasOption('c')) {
            ClusterInfo clusterInfo = defaultMQAdminExt.examineBrokerClusterInfo();
            System.out.printf("%-20s  %-48s  %-48s%n", "#Cluster Name", "#Topic", "#Consumer Group");
            TopicList topicList = defaultMQAdminExt.fetchAllTopicList();
            for (String topic : topicList.getTopicList()) {
                if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX) || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) {
                    continue;
                }
                String clusterName = "";
                GroupList groupList = new GroupList();
                try {
                    clusterName = this.findTopicBelongToWhichCluster(topic, clusterInfo, defaultMQAdminExt);
                    groupList = defaultMQAdminExt.queryTopicConsumeByWho(topic);
                } catch (Exception e) {
                }
                if (null == groupList || groupList.getGroupList().isEmpty()) {
                    groupList = new GroupList();
                    groupList.getGroupList().add("");
                }
                for (String group : groupList.getGroupList()) {
                    System.out.printf("%-20s  %-48s  %-48s%n", UtilAll.frontStringAtLeast(clusterName, 20), UtilAll.frontStringAtLeast(topic, 48), UtilAll.frontStringAtLeast(group, 48));
                }
            }
        } else {
            TopicList topicList = defaultMQAdminExt.fetchAllTopicList();
            for (String topic : topicList.getTopicList()) {
                System.out.printf("%s%n", topic);
            }
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException)

Example 13 with GroupList

use of org.apache.rocketmq.common.protocol.body.GroupList in project rocketmq by apache.

the class DefaultMQAdminExtTest method testQueryTopicConsumeByWho.

@Test
public void testQueryTopicConsumeByWho() throws InterruptedException, RemotingException, MQClientException, MQBrokerException {
    GroupList groupList = defaultMQAdminExt.queryTopicConsumeByWho("UnitTest");
    assertThat(groupList.getGroupList().contains("consumer-group-two")).isTrue();
}
Also used : GroupList(org.apache.rocketmq.common.protocol.body.GroupList) Test(org.junit.Test)

Example 14 with GroupList

use of org.apache.rocketmq.common.protocol.body.GroupList in project rocketmq by apache.

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)) {
                System.out.printf("%-32s  %-32s %12d %11.2f %11.2f %14d %14d%n", UtilAll.frontStringAtLeast(topic, 32), UtilAll.frontStringAtLeast(group, 32), accumulate, inTPS, outTPS, inMsgCntToday, outMsgCntToday);
            }
        }
    } else {
        if (!activeTopic || (inMsgCntToday > 0)) {
            System.out.printf("%-32s  %-32s %12d %11.2f %11s %14d %14s%n", UtilAll.frontStringAtLeast(topic, 32), "", 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)

Example 15 with GroupList

use of org.apache.rocketmq.common.protocol.body.GroupList in project rocketmq by apache.

the class TopicListSubCommand 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();
        if (commandLine.hasOption('c')) {
            ClusterInfo clusterInfo = defaultMQAdminExt.examineBrokerClusterInfo();
            System.out.printf("%-20s  %-48s  %-48s%n", "#Cluster Name", "#Topic", "#Consumer Group");
            TopicList topicList = defaultMQAdminExt.fetchAllTopicList();
            for (String topic : topicList.getTopicList()) {
                if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX) || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) {
                    continue;
                }
                String clusterName = "";
                GroupList groupList = new GroupList();
                try {
                    clusterName = this.findTopicBelongToWhichCluster(topic, clusterInfo, defaultMQAdminExt);
                    groupList = defaultMQAdminExt.queryTopicConsumeByWho(topic);
                } catch (Exception e) {
                }
                if (null == groupList || groupList.getGroupList().isEmpty()) {
                    groupList = new GroupList();
                    groupList.getGroupList().add("");
                }
                for (String group : groupList.getGroupList()) {
                    System.out.printf("%-20s  %-48s  %-48s%n", UtilAll.frontStringAtLeast(clusterName, 20), UtilAll.frontStringAtLeast(topic, 48), UtilAll.frontStringAtLeast(group, 48));
                }
            }
        } else {
            TopicList topicList = defaultMQAdminExt.fetchAllTopicList();
            for (String topic : topicList.getTopicList()) {
                System.out.printf("%s%n", topic);
            }
        }
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) MQClientException(org.apache.rocketmq.client.exception.MQClientException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException)

Aggregations

GroupList (org.apache.rocketmq.common.protocol.body.GroupList)16 MQClientException (org.apache.rocketmq.client.exception.MQClientException)7 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)6 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)6 ArrayList (java.util.ArrayList)4 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)4 TopicList (org.apache.rocketmq.common.protocol.body.TopicList)4 QueryTopicConsumeByWhoRequestHeader (org.apache.rocketmq.common.protocol.header.QueryTopicConsumeByWhoRequestHeader)4 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)4 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)4 SubCommandException (org.apache.rocketmq.tools.command.SubCommandException)4 BrokerStatsData (org.apache.rocketmq.common.protocol.body.BrokerStatsData)3 ConsumerConnection (org.apache.rocketmq.common.protocol.body.ConsumerConnection)3 SubscriptionData (org.apache.rocketmq.common.protocol.heartbeat.SubscriptionData)3 TopicRouteData (org.apache.rocketmq.common.protocol.route.TopicRouteData)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Field (java.lang.reflect.Field)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2