Search in sources :

Example 6 with MultiMQAdminCmdMethod

use of org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod in project rocketmq-externals by apache.

the class ConsumerServiceImpl method deleteSubGroup.

@Override
@MultiMQAdminCmdMethod
public boolean deleteSubGroup(DeleteSubGroupRequest deleteSubGroupRequest) {
    try {
        ClusterInfo clusterInfo = mqAdminExt.examineBrokerClusterInfo();
        for (String brokerName : deleteSubGroupRequest.getBrokerNameList()) {
            logger.info("addr={} groupName={}", clusterInfo.getBrokerAddrTable().get(brokerName).selectBrokerAddr(), deleteSubGroupRequest.getGroupName());
            mqAdminExt.deleteSubscriptionGroup(clusterInfo.getBrokerAddrTable().get(brokerName).selectBrokerAddr(), deleteSubGroupRequest.getGroupName());
        }
    } catch (Exception e) {
        throw propagate(e);
    }
    return true;
}
Also used : ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Example 7 with MultiMQAdminCmdMethod

use of org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod in project rocketmq-externals by apache.

the class ConsumerServiceImpl method queryConsumeStatsListByTopicName.

@Override
@MultiMQAdminCmdMethod
public Map<String, /*groupName*/
TopicConsumerInfo> queryConsumeStatsListByTopicName(String topic) {
    Map<String, TopicConsumerInfo> group2ConsumerInfoMap = Maps.newHashMap();
    try {
        GroupList groupList = mqAdminExt.queryTopicConsumeByWho(topic);
        for (String group : groupList.getGroupList()) {
            List<TopicConsumerInfo> topicConsumerInfoList = null;
            try {
                topicConsumerInfoList = queryConsumeStatsList(topic, group);
            } catch (Exception ignore) {
            }
            group2ConsumerInfoMap.put(group, CollectionUtils.isEmpty(topicConsumerInfoList) ? new TopicConsumerInfo(topic) : topicConsumerInfoList.get(0));
        }
        return group2ConsumerInfoMap;
    } catch (Exception e) {
        throw propagate(e);
    }
}
Also used : GroupList(org.apache.rocketmq.common.protocol.body.GroupList) TopicConsumerInfo(org.apache.rocketmq.console.model.TopicConsumerInfo) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Example 8 with MultiMQAdminCmdMethod

use of org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod in project rocketmq-externals by apache.

the class DashboardCollectTask method collectTopic.

@Scheduled(cron = "30 0/1 * * * ?")
@MultiMQAdminCmdMethod(timeoutMillis = 5000)
public void collectTopic() {
    if (!rmqConfigure.isEnableDashBoardCollect()) {
        return;
    }
    Date date = new Date();
    Stopwatch stopwatch = Stopwatch.createStarted();
    try {
        TopicList topicList = mqAdminExt.fetchAllTopicList();
        Set<String> topicSet = topicList.getTopicList();
        for (String topic : topicSet) {
            if (topic.startsWith(MixAll.RETRY_GROUP_TOPIC_PREFIX) || topic.startsWith(MixAll.DLQ_GROUP_TOPIC_PREFIX)) {
                continue;
            }
            TopicRouteData topicRouteData = mqAdminExt.examineTopicRouteInfo(topic);
            GroupList groupList = mqAdminExt.queryTopicConsumeByWho(topic);
            double inTPS = 0;
            long inMsgCntToday = 0;
            double outTPS = 0;
            long outMsgCntToday = 0;
            for (BrokerData bd : topicRouteData.getBrokerDatas()) {
                String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID);
                if (masterAddr != null) {
                    try {
                        stopwatch.start();
                        log.info("start time: {}", stopwatch.toString());
                        BrokerStatsData bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.TOPIC_PUT_NUMS, topic);
                        stopwatch.stop();
                        log.info("stop time : {}", stopwatch.toString());
                        stopwatch.reset();
                        inTPS += bsd.getStatsMinute().getTps();
                        inMsgCntToday += StatsAllSubCommand.compute24HourSum(bsd);
                    } catch (Exception e) {
                    // throw Throwables.propagate(e);
                    }
                }
            }
            if (groupList != null && !groupList.getGroupList().isEmpty()) {
                for (String group : groupList.getGroupList()) {
                    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 = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.GROUP_GET_NUMS, statsKey);
                                outTPS += bsd.getStatsMinute().getTps();
                                outMsgCntToday += StatsAllSubCommand.compute24HourSum(bsd);
                            } catch (Exception e) {
                            // throw Throwables.propagate(e);
                            }
                        }
                    }
                }
            }
            List<String> list;
            try {
                list = dashboardCollectService.getTopicMap().get(topic);
            } catch (ExecutionException e) {
                throw Throwables.propagate(e);
            }
            if (null == list) {
                list = Lists.newArrayList();
            }
            list.add(date.getTime() + "," + new BigDecimal(inTPS).setScale(5, BigDecimal.ROUND_HALF_UP) + "," + inMsgCntToday + "," + new BigDecimal(outTPS).setScale(5, BigDecimal.ROUND_HALF_UP) + "," + outMsgCntToday);
            dashboardCollectService.getTopicMap().put(topic, list);
        }
        log.debug("Topic Collected Data in memory = {}" + JsonUtil.obj2String(dashboardCollectService.getTopicMap().asMap()));
    } catch (Exception err) {
        throw Throwables.propagate(err);
    }
}
Also used : BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) Stopwatch(com.google.common.base.Stopwatch) Date(java.util.Date) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) BigDecimal(java.math.BigDecimal) TopicRouteData(org.apache.rocketmq.common.protocol.route.TopicRouteData) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) ExecutionException(java.util.concurrent.ExecutionException) BrokerStatsData(org.apache.rocketmq.common.protocol.body.BrokerStatsData) Scheduled(org.springframework.scheduling.annotation.Scheduled) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)

Example 9 with MultiMQAdminCmdMethod

use of org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod in project rocketmq-externals by apache.

the class MQAdminAspect method aroundMQAdminMethod.

@Around(value = "mQAdminMethodPointCut() || multiMQAdminMethodPointCut()")
public Object aroundMQAdminMethod(ProceedingJoinPoint joinPoint) throws Throwable {
    long start = System.currentTimeMillis();
    Object obj = null;
    try {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        MultiMQAdminCmdMethod multiMQAdminCmdMethod = method.getAnnotation(MultiMQAdminCmdMethod.class);
        if (multiMQAdminCmdMethod != null && multiMQAdminCmdMethod.timeoutMillis() > 0) {
            MQAdminInstance.initMQAdminInstance(multiMQAdminCmdMethod.timeoutMillis());
        } else {
            MQAdminInstance.initMQAdminInstance(0);
        }
        obj = joinPoint.proceed();
    } finally {
        MQAdminInstance.destroyMQAdminInstance();
        logger.debug("op=look method={} cost={}", joinPoint.getSignature().getName(), System.currentTimeMillis() - start);
    }
    return obj;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod) MultiMQAdminCmdMethod(org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod) Method(java.lang.reflect.Method) Around(org.aspectj.lang.annotation.Around)

Aggregations

MultiMQAdminCmdMethod (org.apache.rocketmq.console.aspect.admin.annotation.MultiMQAdminCmdMethod)9 MQClientException (org.apache.rocketmq.client.exception.MQClientException)7 ClusterInfo (org.apache.rocketmq.common.protocol.body.ClusterInfo)3 GroupList (org.apache.rocketmq.common.protocol.body.GroupList)3 ConsumeStats (org.apache.rocketmq.common.admin.ConsumeStats)2 MessageQueue (org.apache.rocketmq.common.message.MessageQueue)2 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)2 GroupConsumeInfo (org.apache.rocketmq.console.model.GroupConsumeInfo)2 TopicConsumerInfo (org.apache.rocketmq.console.model.TopicConsumerInfo)2 Predicate (com.google.common.base.Predicate)1 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 Method (java.lang.reflect.Method)1 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 List (java.util.List)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 RollbackStats (org.apache.rocketmq.common.admin.RollbackStats)1 BrokerStatsData (org.apache.rocketmq.common.protocol.body.BrokerStatsData)1