private void innEnableOrDisableMetricsStats(boolean enable,
            String statsType,
            HttpServletRequest req,
            StringBuilder sBuffer) {
        ProcessResult result = new ProcessResult();
        // get input metric type
        BrokerStatsType inMetricType = null;
        for (BrokerStatsType metricType : BrokerStatsType.values()) {
            if (metricType.getName().equalsIgnoreCase(statsType)) {
                inMetricType = metricType;
                break;
            }
        }
        if (inMetricType == null) {
            sBuffer.append("{\"result\":false,\"errCode\":400,\"errMsg\":")
                    .append("\"Unmatched stat type, allowed stat type are : [");
            int count = 0;
            for (BrokerStatsType metricType : BrokerStatsType.values()) {
                if (count++ > 0) {
                    sBuffer.append(",");
                }
                sBuffer.append(metricType.getName());
            }
            sBuffer.append("]\"}");
            return;
        }
        // Operate separately according to the specified statistic type
        if (inMetricType == BrokerStatsType.WEBAPI
                || inMetricType == BrokerStatsType.ALL) {
            WebCallStatsHolder.setStatsStatus(enable);
        }
        if (inMetricType == BrokerStatsType.SERVICESTATUS
                || inMetricType == BrokerStatsType.ALL) {
            BrokerSrvStatsHolder.setDetailStatsStatus(enable);
        }
        if (inMetricType == BrokerStatsType.MSGSTORE
                || inMetricType == BrokerStatsType.ALL) {
            // Check if the specified topic is included
            if (!WebParameterUtils.getStringParamValue(req,
                    WebFieldDef.COMPSTOPICNAME, false, null, sBuffer, result)) {
                WebParameterUtils.buildFailResult(sBuffer, result.getErrMsg());
                return;
            }
            Set<String> topicNameSet = (Set<String>) result.getRetData();
            // set topic's statistic status
            Map<String, ConcurrentHashMap<Integer, MessageStore>> msgTopicStores =
                    broker.getStoreManager().getMessageStores();
            if (topicNameSet.isEmpty()) {
                for (ConcurrentHashMap<Integer, MessageStore> storeMap : msgTopicStores.values()) {
                    if (storeMap == null) {
                        continue;
                    }
                    for (MessageStore msgStore : storeMap.values()) {
                        if (msgStore == null) {
                            continue;
                        }
                        msgStore.getMsgStoreStatsHolder().setStatsStatus(enable);
                    }
                }
            } else {
                ConcurrentHashMap<Integer, MessageStore> storeMap;
                for (String topicName : topicNameSet) {
                    storeMap = msgTopicStores.get(topicName);
                    if (storeMap == null) {
                        continue;
                    }
                    for (MessageStore msgStore : storeMap.values()) {
                        if (msgStore == null) {
                            continue;
                        }
                        msgStore.getMsgStoreStatsHolder().setStatsStatus(true);
                    }
                }
            }
        }
        // builder return result
        WebParameterUtils.buildSuccessResult(sBuffer);
    }
Disable or Enable broker's statistics functions

@param enable     whether enable or disable
@param statsType  the statistics type to be operated on
@param req        HttpServletRequest
@param sBuffer    query result
inlong-tubemq/tubemq-server/src/main/java/org/apache/inlong/tubemq/server/broker/web/BrokerAdminServlet.java