public void collectBrokerRuntimeStats()

in src/main/java/org/apache/rocketmq/exporter/task/MetricsCollectTask.java [648:693]


    public void collectBrokerRuntimeStats() {
        if (!rmqConfigure.isEnableCollect()) {
            return;
        }
        log.info("broker runtime stats collection task starting....");
        long start = System.currentTimeMillis();
        ClusterInfo clusterInfo = null;
        try {
            clusterInfo = mqAdminExt.examineBrokerClusterInfo();
        } catch (Exception ex) {
            log.error(String.format("collectBrokerRuntimeStats-get cluster info from namesrv error. address is %s", JSON.toJSONString(mqAdminExt.getNameServerAddressList())), ex);
            return;
        }

        Set<Map.Entry<String, BrokerData>> clusterEntries = clusterInfo.getBrokerAddrTable().entrySet();
        for (Map.Entry<String, BrokerData> clusterEntry : clusterEntries) {
            String masterAddr = clusterEntry.getValue().getBrokerAddrs().get(MixAll.MASTER_ID);
            String clusterName = clusterEntry.getValue().getCluster();

            KVTable kvTable = null;
            if (!StringUtils.isBlank(masterAddr)) {
                try {
                    kvTable = mqAdminExt.fetchBrokerRuntimeStats(masterAddr);
                } catch (RemotingConnectException | RemotingSendRequestException | RemotingTimeoutException | InterruptedException ex) {
                    log.error(String.format("collectBrokerRuntimeStats-get fetch broker runtime stats error, address=%s", masterAddr), ex);
                } catch (MQBrokerException ex) {
                    if (ex.getResponseCode() == ResponseCode.SYSTEM_ERROR) {
                        log.error(String.format("collectBrokerRuntimeStats-get fetch broker runtime stats error, address=%s, error=%s", masterAddr, ex.getErrorMessage()));
                    } else {
                        log.error(String.format("collectBrokerRuntimeStats-get fetch broker runtime stats error, address=%s", masterAddr), ex);
                    }
                }
            }
            if (kvTable == null || kvTable.getTable() == null || kvTable.getTable().isEmpty()) {
                continue;
            }
            try {
                BrokerRuntimeStats brokerRuntimeStats = new BrokerRuntimeStats(kvTable);
                metricsService.getCollector().addBrokerRuntimeStatsMetric(brokerRuntimeStats, clusterName, masterAddr, "");
            } catch (Exception ex) {
                log.error(String.format("collectBrokerRuntimeStats-parse or report broker runtime stats error, %s", JSON.toJSONString(kvTable)), ex);
            }
        }

        log.info("broker runtime stats collection task finished...." + (System.currentTimeMillis() - start));
    }