Search in sources :

Example 26 with SubscriptionGroupWrapper

use of org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper in project rocketmq-comments by HScarb.

the class ExportMetricsCommand method execute.

@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) throws SubCommandException {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);
    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));
    try {
        String clusterName = commandLine.getOptionValue('c').trim();
        String filePath = !commandLine.hasOption('f') ? "/tmp/rocketmq/export" : commandLine.getOptionValue('f').trim();
        defaultMQAdminExt.start();
        Map<String, Map<String, Map<String, Object>>> evaluateReportMap = new HashMap<>();
        Map<String, Double> totalTpsMap = new HashMap<>();
        Map<String, Long> totalOneDayNumMap = new HashMap<>();
        initTotalMap(totalTpsMap, totalOneDayNumMap);
        ClusterInfo clusterInfoSerializeWrapper = defaultMQAdminExt.examineBrokerClusterInfo();
        Set<String> brokerNameSet = clusterInfoSerializeWrapper.getClusterAddrTable().get(clusterName);
        for (String brokerName : brokerNameSet) {
            BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
            if (brokerData != null) {
                String addr = brokerData.getBrokerAddrs().get(0L);
                KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(addr);
                Properties properties = defaultMQAdminExt.getBrokerConfig(addr);
                SubscriptionGroupWrapper subscriptionGroupWrapper = defaultMQAdminExt.getUserSubscriptionGroup(addr, 10000);
                Map<String, Map<String, Object>> brokerInfo = new HashMap<>();
                // broker environment,machine configuration
                brokerInfo.put("runtimeEnv", getRuntimeEnv(kvTable, properties));
                brokerInfo.put("runtimeQuota", getRuntimeQuota(kvTable, defaultMQAdminExt, addr, totalTpsMap, totalOneDayNumMap, subscriptionGroupWrapper));
                // runtime version
                brokerInfo.put("runtimeVersion", getRuntimeVersion(defaultMQAdminExt, subscriptionGroupWrapper));
                evaluateReportMap.put(brokerName, brokerInfo);
            }
        }
        String path = filePath + "/metrics.json";
        Map<String, Object> totalData = new HashMap<>();
        totalData.put("totalTps", totalTpsMap);
        totalData.put("totalOneDayNum", totalOneDayNumMap);
        Map<String, Object> result = new HashMap<>();
        result.put("evaluateReport", evaluateReportMap);
        result.put("totalData", totalData);
        MixAll.string2FileNotSafe(JSON.toJSONString(result, true), path);
        System.out.printf("export %s success", path);
    } catch (Exception e) {
        throw new SubCommandException(this.getClass().getSimpleName() + " command failed", e);
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
Also used : KVTable(org.apache.rocketmq.common.protocol.body.KVTable) SubCommandException(org.apache.rocketmq.tools.command.SubCommandException) HashMap(java.util.HashMap) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) Properties(java.util.Properties) 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) ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) DefaultMQAdminExt(org.apache.rocketmq.tools.admin.DefaultMQAdminExt) HashMap(java.util.HashMap) Map(java.util.Map) SubscriptionGroupWrapper(org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper)

Aggregations

SubscriptionGroupWrapper (org.apache.rocketmq.common.protocol.body.SubscriptionGroupWrapper)26 Map (java.util.Map)11 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)11 HashMap (java.util.HashMap)9 SubscriptionGroupConfig (org.apache.rocketmq.common.subscription.SubscriptionGroupConfig)9 MQClientException (org.apache.rocketmq.client.exception.MQClientException)7 BrokerData (org.apache.rocketmq.common.protocol.route.BrokerData)7 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)7 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 KVTable (org.apache.rocketmq.common.protocol.body.KVTable)5 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)5 TopicConfig (org.apache.rocketmq.common.TopicConfig)4 ClusterInfo (org.apache.rocketmq.common.protocol.body.ClusterInfo)4 TopicConfigSerializeWrapper (org.apache.rocketmq.common.protocol.body.TopicConfigSerializeWrapper)4 DefaultMQAdminExt (org.apache.rocketmq.tools.admin.DefaultMQAdminExt)4 Field (java.lang.reflect.Field)3 HashSet (java.util.HashSet)3 List (java.util.List)3 TreeMap (java.util.TreeMap)3