public static synchronized String getMetric(MetricVisitor visitor, MetricsAction.RequestParams requestParams) {
        if (!hasInit) {
            return "";
        }

        // update the metrics first
        updateMetrics();

        // jvm
        JvmStatCollector jvmStatCollector = new JvmStatCollector();
        JvmStats jvmStats = jvmStatCollector.stats();
        visitor.visitJvm(jvmStats);

        // starrocks metrics
        for (Metric metric : STARROCKS_METRIC_REGISTER.getMetrics()) {
            visitor.visit(metric);
        }

        // database metrics
        collectDatabaseMetrics(visitor);

        // table metrics
        if (requestParams.isCollectTableMetrics()) {
            collectTableMetrics(visitor, requestParams.isMinifyTableMetrics());
        }

        // materialized view metrics
        if (requestParams.isCollectMVMetrics()) {
            MaterializedViewMetricsRegistry.collectMaterializedViewMetrics(visitor, requestParams.isMinifyMVMetrics());
        }

        // histogram
        SortedMap<String, Histogram> histograms = METRIC_REGISTER.getHistograms();
        for (Map.Entry<String, Histogram> entry : histograms.entrySet()) {
            visitor.visitHistogram(entry.getKey(), entry.getValue());
        }
        ResourceGroupMetricMgr.visitQueryLatency();

        // collect routine load process metrics
        if (Config.enable_routine_load_lag_metrics) {
            collectRoutineLoadProcessMetrics(visitor);
        }

        if (Config.memory_tracker_enable) {
            collectMemoryUsageMetrics(visitor);
        }

        // collect http metrics
        HttpMetricRegistry.getInstance().visit(visitor);

        // collect starmgr related metrics as well
        StarMgrServer.getCurrentState().visitMetrics(visitor);

        // node info
        visitor.getNodeInfo();
        return visitor.build();
    }
@Test
    public void testGetMetric() throws Exception {
        starRocksAssert.useDatabase("test_metric")
                .withTable("create table t1 (c1 int, c2 string)" +
                        " distributed by hash(c1) " +
                        " properties('replication_num'='1') ");
        Table t1 = starRocksAssert.getTable("test_metric", "t1");

        // update metric
        TableMetricsEntity entity = TableMetricsRegistry.getInstance().getMetricsEntity(t1.getId());
        entity.counterScanBytesTotal.increase(1024L);

        // verify metric
        JsonMetricVisitor visitor = new JsonMetricVisitor("m");
        MetricsAction.RequestParams params = new MetricsAction.RequestParams(true, true, true, true);
        MetricRepo.getMetric(visitor, params);
        String json = visitor.build();
        Assert.assertTrue(StringUtils.isNotEmpty(json));
        Assert.assertTrue(json.contains("test_metric"));
    }