Search in sources :

Example 1 with ClusterInfo

use of org.apache.rocketmq.common.protocol.body.ClusterInfo in project rocketmq-externals by apache.

the class ConsumerServiceImpl method queryGroupList.

@Override
@MultiMQAdminCmdMethod
public List<GroupConsumeInfo> queryGroupList() {
    Set<String> consumerGroupSet = Sets.newHashSet();
    try {
        ClusterInfo clusterInfo = mqAdminExt.examineBrokerClusterInfo();
        for (BrokerData brokerData : clusterInfo.getBrokerAddrTable().values()) {
            SubscriptionGroupWrapper subscriptionGroupWrapper = mqAdminExt.getAllSubscriptionGroup(brokerData.selectBrokerAddr(), 3000L);
            consumerGroupSet.addAll(subscriptionGroupWrapper.getSubscriptionGroupTable().keySet());
        }
    } catch (Exception err) {
        throw Throwables.propagate(err);
    }
    List<GroupConsumeInfo> groupConsumeInfoList = Lists.newArrayList();
    for (String consumerGroup : consumerGroupSet) {
        groupConsumeInfoList.add(queryGroup(consumerGroup));
    }
    Collections.sort(groupConsumeInfoList);
    return groupConsumeInfoList;
}
Also used : GroupConsumeInfo(org.apache.rocketmq.console.model.GroupConsumeInfo) ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) SubscriptionGroupWrapper(org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Example 2 with ClusterInfo

use of org.apache.rocketmq.common.protocol.body.ClusterInfo in project rocketmq-externals by apache.

the class ConsumerServiceImpl method examineSubscriptionGroupConfig.

@Override
@MultiMQAdminCmdMethod
public List<ConsumerConfigInfo> examineSubscriptionGroupConfig(String group) {
    List<ConsumerConfigInfo> consumerConfigInfoList = Lists.newArrayList();
    try {
        ClusterInfo clusterInfo = mqAdminExt.examineBrokerClusterInfo();
        for (String brokerName : clusterInfo.getBrokerAddrTable().keySet()) {
            // foreach brokerName
            String brokerAddress = clusterInfo.getBrokerAddrTable().get(brokerName).selectBrokerAddr();
            SubscriptionGroupConfig subscriptionGroupConfig = mqAdminExt.examineSubscriptionGroupConfig(brokerAddress, group);
            if (subscriptionGroupConfig == null) {
                continue;
            }
            consumerConfigInfoList.add(new ConsumerConfigInfo(Lists.newArrayList(brokerName), subscriptionGroupConfig));
        }
    } catch (Exception e) {
        throw propagate(e);
    }
    return consumerConfigInfoList;
}
Also used : ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) ConsumerConfigInfo(org.apache.rocketmq.console.model.request.ConsumerConfigInfo) SubscriptionGroupConfig(org.apache.rocketmq.common.subscription.SubscriptionGroupConfig) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Example 3 with ClusterInfo

use of org.apache.rocketmq.common.protocol.body.ClusterInfo in project rocketmq-externals by apache.

the class DashboardCollectTask method collectBroker.

@Scheduled(cron = "0 0/1 * * * ?")
public void collectBroker() {
    if (!rmqConfigure.isEnableDashBoardCollect()) {
        return;
    }
    try {
        Date date = new Date();
        ClusterInfo clusterInfo = mqAdminExt.examineBrokerClusterInfo();
        Set<Map.Entry<String, BrokerData>> clusterEntries = clusterInfo.getBrokerAddrTable().entrySet();
        Map<String, String> addresses = Maps.newHashMap();
        for (Map.Entry<String, BrokerData> clusterEntry : clusterEntries) {
            HashMap<Long, String> addrs = clusterEntry.getValue().getBrokerAddrs();
            Set<Map.Entry<Long, String>> addrsEntries = addrs.entrySet();
            for (Map.Entry<Long, String> addrEntry : addrsEntries) {
                addresses.put(addrEntry.getValue(), clusterEntry.getKey() + ":" + addrEntry.getKey());
            }
        }
        Set<Map.Entry<String, String>> entries = addresses.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            List<String> list = dashboardCollectService.getBrokerMap().get(entry.getValue());
            if (null == list) {
                list = Lists.newArrayList();
            }
            KVTable kvTable = fetchBrokerRuntimeStats(entry.getKey(), 3);
            if (kvTable == null) {
                continue;
            }
            String[] tpsArray = kvTable.getTable().get("getTotalTps").split(" ");
            BigDecimal totalTps = new BigDecimal(0);
            for (String tps : tpsArray) {
                totalTps = totalTps.add(new BigDecimal(tps));
            }
            BigDecimal averageTps = totalTps.divide(new BigDecimal(tpsArray.length), 5, BigDecimal.ROUND_HALF_UP);
            list.add(date.getTime() + "," + averageTps.toString());
            dashboardCollectService.getBrokerMap().put(entry.getValue(), list);
        }
        log.debug("Broker Collected Data in memory = {}" + JsonUtil.obj2String(dashboardCollectService.getBrokerMap().asMap()));
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : KVTable(org.apache.rocketmq.common.protocol.body.KVTable) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) Date(java.util.Date) BigDecimal(java.math.BigDecimal) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) HashMap(java.util.HashMap) Map(java.util.Map) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 4 with ClusterInfo

use of org.apache.rocketmq.common.protocol.body.ClusterInfo in project rocketmq-externals by apache.

the class ClusterServiceImplTest method list.

@Test
@SuppressWarnings("unchecked")
public void list() throws Exception {
    Map<String, Object> clusterMap = clusterService.list();
    ClusterInfo clusterInfo = (ClusterInfo) clusterMap.get("clusterInfo");
    Map<String, Map<Long, Object>> /* brokerDetail */
    brokerServerMap = (Map<String, Map<Long, Object>>) clusterMap.get("brokerServer");
    Assert.assertNotNull(clusterInfo);
    Assert.assertNotNull(brokerServerMap);
    Assert.assertNotNull(clusterInfo.getBrokerAddrTable().get(TestConstant.TEST_BROKER_NAME));
    Assert.assertNotNull(brokerServerMap.get(TestConstant.TEST_BROKER_NAME));
}
Also used : ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) Map(java.util.Map) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with ClusterInfo

use of org.apache.rocketmq.common.protocol.body.ClusterInfo in project rocketmq-externals by apache.

the class ClusterServiceImpl method list.

@Override
public Map<String, Object> list() {
    try {
        Map<String, Object> resultMap = Maps.newHashMap();
        ClusterInfo clusterInfo = mqAdminExt.examineBrokerClusterInfo();
        logger.info("op=look_clusterInfo {}", JsonUtil.obj2String(clusterInfo));
        Map<String, Map<Long, Object>> /* brokerDetail */
        brokerServer = Maps.newHashMap();
        for (BrokerData brokerData : clusterInfo.getBrokerAddrTable().values()) {
            Map<Long, Object> brokerMasterSlaveMap = Maps.newHashMap();
            for (Map.Entry<Long, String> /* broker address */
            brokerAddr : brokerData.getBrokerAddrs().entrySet()) {
                KVTable kvTable = mqAdminExt.fetchBrokerRuntimeStats(brokerAddr.getValue());
                // KVTable kvTable = mqAdminExt.fetchBrokerRuntimeStats("127.0.0.1:10911");
                brokerMasterSlaveMap.put(brokerAddr.getKey(), kvTable.getTable());
            }
            brokerServer.put(brokerData.getBrokerName(), brokerMasterSlaveMap);
        }
        resultMap.put("clusterInfo", clusterInfo);
        resultMap.put("brokerServer", brokerServer);
        return resultMap;
    } catch (Exception err) {
        throw Throwables.propagate(err);
    }
}
Also used : ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) KVTable(org.apache.rocketmq.common.protocol.body.KVTable) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) Map(java.util.Map)

Aggregations

ClusterInfo (org.apache.rocketmq.common.protocol.body.ClusterInfo)8 Map (java.util.Map)3 MQClientException (org.apache.rocketmq.client.exception.MQClientException)3 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)3 MultiMQAdminCmdMethod (org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)3 KVTable (org.apache.rocketmq.common.protocol.body.KVTable)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 TopicConfig (org.apache.rocketmq.common.TopicConfig)1 SubscriptionGroupWrapper (org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper)1 SubscriptionGroupConfig (org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)1 GroupConsumeInfo (org.apache.rocketmq.console.model.GroupConsumeInfo)1 ConsumerConfigInfo (org.apache.rocketmq.console.model.request.ConsumerConfigInfo)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Scheduled (org.springframework.scheduling.annotation.Scheduled)1