Java Code Examples for com.alibaba.rocketmq.tools.admin.DefaultMQAdminExt#fetchBrokerRuntimeStats()

The following examples show how to use com.alibaba.rocketmq.tools.admin.DefaultMQAdminExt#fetchBrokerRuntimeStats() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrokerService.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@CmdTrace(cmdClazz = BrokerStatusSubCommand.class)
public Table brokerStats(String brokerAddr) throws Throwable {
    Throwable t = null;
    DefaultMQAdminExt defaultMQAdminExt = getDefaultMQAdminExt();
    try {
        defaultMQAdminExt.start();
        KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(brokerAddr);
        TreeMap<String, String> tmp = new TreeMap<String, String>();
        tmp.putAll(kvTable.getTable());
        return Table.Map2VTable(tmp);
    }
    catch (Throwable e) {
        logger.error(e.getMessage(), e);
        t = e;
    }
    finally {
        shutdownDefaultMQAdminExt(defaultMQAdminExt);
    }
    throw t;
}
 
Example 2
Source File: BrokerStatusSubCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        defaultMQAdminExt.start();

        String brokerAddr = commandLine.getOptionValue('b').trim();

        //获取broker一些全局统计信息 例如commitlog  全局offset等信息
        KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(brokerAddr);

        TreeMap<String, String> tmp = new TreeMap<String, String>();
        tmp.putAll(kvTable.getTable());

        Iterator<Entry<String, String>> it = tmp.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, String> next = it.next();
            System.out.printf("%-32s: %s\n", next.getKey(), next.getValue());
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 3
Source File: BrokerStatusSubCommand.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        defaultMQAdminExt.start();

        String brokerAddr = commandLine.getOptionValue('b').trim();

        KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(brokerAddr);


        TreeMap<String, String> tmp = new TreeMap<String, String>();
        tmp.putAll(kvTable.getTable());

        Iterator<Entry<String, String>> it = tmp.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, String> next = it.next();
            System.out.printf("%-32s: %s%n", next.getKey(), next.getValue());
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 4
Source File: BrokerStatusSubCommand.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(CommandLine commandLine, Options options, RPCHook rpcHook) {
    DefaultMQAdminExt defaultMQAdminExt = new DefaultMQAdminExt(rpcHook);

    defaultMQAdminExt.setInstanceName(Long.toString(System.currentTimeMillis()));

    try {
        defaultMQAdminExt.start();

        String brokerAddr = commandLine.getOptionValue('b').trim();

        KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(brokerAddr);

        // 为了排序
        TreeMap<String, String> tmp = new TreeMap<String, String>();
        tmp.putAll(kvTable.getTable());

        Iterator<Entry<String, String>> it = tmp.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, String> next = it.next();
            System.out.printf("%-32s: %s\n", next.getKey(), next.getValue());
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    finally {
        defaultMQAdminExt.shutdown();
    }
}
 
Example 5
Source File: ClusterListSubCommand.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 4 votes vote down vote up
private void printClusterMoreStats(final DefaultMQAdminExt defaultMQAdminExt) throws RemotingConnectException,
        RemotingTimeoutException, RemotingSendRequestException, InterruptedException, MQBrokerException {

    ClusterInfo clusterInfoSerializeWrapper = defaultMQAdminExt.examineBrokerClusterInfo();

    System.out.printf("%-16s  %-32s %14s %14s %14s %14s\n",//
        "#Cluster Name",//
        "#Broker Name",//
        "#InTotalYest",//
        "#OutTotalYest",//
        "#InTotalToday",//
        "#OutTotalToday"//
    );

    Iterator<Map.Entry<String, Set<String>>> itCluster = clusterInfoSerializeWrapper.getClusterAddrTable().entrySet().iterator();
    while (itCluster.hasNext()) {
        Map.Entry<String, Set<String>> next = itCluster.next();
        String clusterName = next.getKey();
        TreeSet<String> brokerNameSet = new TreeSet<String>();
        brokerNameSet.addAll(next.getValue());

        for (String brokerName : brokerNameSet) {
            BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
            if (brokerData != null) {

                Iterator<Map.Entry<Long, String>> itAddr = brokerData.getBrokerAddrs().entrySet().iterator();
                while (itAddr.hasNext()) {
                    Map.Entry<Long, String> next1 = itAddr.next();
                    long InTotalYest = 0;
                    long OutTotalYest = 0;
                    long InTotalToday = 0;
                    long OutTotalToday = 0;

                    try {
                        KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(next1.getValue());
                        String msgPutTotalYesterdayMorning = kvTable.getTable().get("msgPutTotalYesterdayMorning");
                        String msgPutTotalTodayMorning = kvTable.getTable().get("msgPutTotalTodayMorning");
                        String msgPutTotalTodayNow = kvTable.getTable().get("msgPutTotalTodayNow");
                        String msgGetTotalYesterdayMorning = kvTable.getTable().get("msgGetTotalYesterdayMorning");
                        String msgGetTotalTodayMorning = kvTable.getTable().get("msgGetTotalTodayMorning");
                        String msgGetTotalTodayNow = kvTable.getTable().get("msgGetTotalTodayNow");

                        InTotalYest = Long.parseLong(msgPutTotalTodayMorning) - Long.parseLong(msgPutTotalYesterdayMorning);
                        OutTotalYest = Long.parseLong(msgGetTotalTodayMorning) - Long.parseLong(msgGetTotalYesterdayMorning);

                        InTotalToday = Long.parseLong(msgPutTotalTodayNow) - Long.parseLong(msgPutTotalTodayMorning);
                        OutTotalToday = Long.parseLong(msgGetTotalTodayNow) - Long.parseLong(msgGetTotalTodayMorning);

                    }
                    catch (Exception e) {
                    }

                    System.out.printf("%-16s  %-32s %14d %14d %14d %14d\n",//
                        clusterName,//
                        brokerName,//
                        InTotalYest,//
                        OutTotalYest,//
                        InTotalToday,//
                        OutTotalToday//
                        );
                }
            }
        }

        if (itCluster.hasNext()) {
            System.out.println("");
        }
    }
}
 
Example 6
Source File: ClusterListSubCommand.java    From rocketmq with Apache License 2.0 4 votes vote down vote up
private void printClusterMoreStats(final DefaultMQAdminExt defaultMQAdminExt) throws RemotingConnectException,
        RemotingTimeoutException, RemotingSendRequestException, InterruptedException, MQBrokerException {

    ClusterInfo clusterInfoSerializeWrapper = defaultMQAdminExt.examineBrokerClusterInfo();

    System.out.printf("%-16s  %-32s %14s %14s %14s %14s%n",//
            "#Cluster Name",//
            "#Broker Name",//
            "#InTotalYest",//
            "#OutTotalYest",//
            "#InTotalToday",//
            "#OutTotalToday"//
    );

    Iterator<Map.Entry<String, Set<String>>> itCluster = clusterInfoSerializeWrapper.getClusterAddrTable().entrySet().iterator();
    while (itCluster.hasNext()) {
        Map.Entry<String, Set<String>> next = itCluster.next();
        String clusterName = next.getKey();
        TreeSet<String> brokerNameSet = new TreeSet<String>();
        brokerNameSet.addAll(next.getValue());

        for (String brokerName : brokerNameSet) {
            BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
            if (brokerData != null) {

                Iterator<Map.Entry<Long, String>> itAddr = brokerData.getBrokerAddrs().entrySet().iterator();
                while (itAddr.hasNext()) {
                    Map.Entry<Long, String> next1 = itAddr.next();
                    long InTotalYest = 0;
                    long OutTotalYest = 0;
                    long InTotalToday = 0;
                    long OutTotalToday = 0;

                    try {
                        KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(next1.getValue());
                        String msgPutTotalYesterdayMorning = kvTable.getTable().get("msgPutTotalYesterdayMorning");
                        String msgPutTotalTodayMorning = kvTable.getTable().get("msgPutTotalTodayMorning");
                        String msgPutTotalTodayNow = kvTable.getTable().get("msgPutTotalTodayNow");
                        String msgGetTotalYesterdayMorning = kvTable.getTable().get("msgGetTotalYesterdayMorning");
                        String msgGetTotalTodayMorning = kvTable.getTable().get("msgGetTotalTodayMorning");
                        String msgGetTotalTodayNow = kvTable.getTable().get("msgGetTotalTodayNow");

                        InTotalYest = Long.parseLong(msgPutTotalTodayMorning) - Long.parseLong(msgPutTotalYesterdayMorning);
                        OutTotalYest = Long.parseLong(msgGetTotalTodayMorning) - Long.parseLong(msgGetTotalYesterdayMorning);

                        InTotalToday = Long.parseLong(msgPutTotalTodayNow) - Long.parseLong(msgPutTotalTodayMorning);
                        OutTotalToday = Long.parseLong(msgGetTotalTodayNow) - Long.parseLong(msgGetTotalTodayMorning);

                    } catch (Exception e) {
                    }

                    System.out.printf("%-16s  %-32s %14d %14d %14d %14d%n",//
                            clusterName,//
                            brokerName,//
                            InTotalYest,//
                            OutTotalYest,//
                            InTotalToday,//
                            OutTotalToday//
                    );
                }
            }
        }

        if (itCluster.hasNext()) {
            System.out.println("");
        }
    }
}
 
Example 7
Source File: ClusterListSubCommand.java    From RocketMQ-Master-analyze with Apache License 2.0 4 votes vote down vote up
private void printClusterMoreStats(final DefaultMQAdminExt defaultMQAdminExt)
        throws RemotingConnectException, RemotingTimeoutException, RemotingSendRequestException,
        InterruptedException, MQBrokerException {

    ClusterInfo clusterInfoSerializeWrapper = defaultMQAdminExt.examineBrokerClusterInfo();

    System.out.printf("%-16s  %-32s %14s %14s %14s %14s\n", //
        "#Cluster Name", //
        "#Broker Name", //
        "#InTotalYest", //
        "#OutTotalYest", //
        "#InTotalToday", //
        "#OutTotalToday"//
    );

    Iterator<Map.Entry<String, Set<String>>> itCluster =
            clusterInfoSerializeWrapper.getClusterAddrTable().entrySet().iterator();
    while (itCluster.hasNext()) {
        Map.Entry<String, Set<String>> next = itCluster.next();
        String clusterName = next.getKey();
        TreeSet<String> brokerNameSet = new TreeSet<String>();
        brokerNameSet.addAll(next.getValue());

        for (String brokerName : brokerNameSet) {
            BrokerData brokerData = clusterInfoSerializeWrapper.getBrokerAddrTable().get(brokerName);
            if (brokerData != null) {

                Iterator<Map.Entry<Long, String>> itAddr =
                        brokerData.getBrokerAddrs().entrySet().iterator();
                while (itAddr.hasNext()) {
                    Map.Entry<Long, String> next1 = itAddr.next();
                    long InTotalYest = 0;
                    long OutTotalYest = 0;
                    long InTotalToday = 0;
                    long OutTotalToday = 0;

                    try {
                        KVTable kvTable = defaultMQAdminExt.fetchBrokerRuntimeStats(next1.getValue());
                        String msgPutTotalYesterdayMorning =
                                kvTable.getTable().get("msgPutTotalYesterdayMorning");
                        String msgPutTotalTodayMorning =
                                kvTable.getTable().get("msgPutTotalTodayMorning");
                        String msgPutTotalTodayNow = kvTable.getTable().get("msgPutTotalTodayNow");
                        String msgGetTotalYesterdayMorning =
                                kvTable.getTable().get("msgGetTotalYesterdayMorning");
                        String msgGetTotalTodayMorning =
                                kvTable.getTable().get("msgGetTotalTodayMorning");
                        String msgGetTotalTodayNow = kvTable.getTable().get("msgGetTotalTodayNow");

                        InTotalYest = Long.parseLong(msgPutTotalTodayMorning)
                                - Long.parseLong(msgPutTotalYesterdayMorning);
                        OutTotalYest = Long.parseLong(msgGetTotalTodayMorning)
                                - Long.parseLong(msgGetTotalYesterdayMorning);

                        InTotalToday = Long.parseLong(msgPutTotalTodayNow)
                                - Long.parseLong(msgPutTotalTodayMorning);
                        OutTotalToday = Long.parseLong(msgGetTotalTodayNow)
                                - Long.parseLong(msgGetTotalTodayMorning);

                    }
                    catch (Exception e) {
                    }

                    System.out.printf("%-16s  %-32s %14d %14d %14d %14d\n", //
                        clusterName, //
                        brokerName, //
                        InTotalYest, //
                        OutTotalYest, //
                        InTotalToday, //
                        OutTotalToday//
                    );
                }
            }
        }

        if (itCluster.hasNext()) {
            System.out.println("");
        }
    }
}