@Override
    public List<MetricFamilySamples> collect() {
        List<MetricFamilySamples> result = new ArrayList<>();
        result.addAll(clientTotal.collect());
        result.addAll(clientFail.collect());
        result.addAll(serverTotal.collect());
        result.addAll(serverFail.collect());
        result.addAll(requestSize.collect());
        result.addAll(responseSize.collect());
        result.addAll(providerCounter.collect());
        result.addAll(consumerCounter.collect());

        ServerConfig serverConfig = serverConfigReference.get();
        ThreadPoolExecutor threadPoolExecutor = executorReference.get();
        if (serverConfig != null) {
            threadPoolConfigCore.labels(commonLabelValues)
                    .set(serverConfig.getCoreThreads());
            result.addAll(threadPoolConfigCore.collect());


            threadPoolConfigMax.labels(commonLabelValues)
                    .set(serverConfig.getMaxThreads());
            result.addAll(threadPoolConfigMax.collect());


            threadPoolConfigQueue.labels(commonLabelValues)
                    .set(serverConfig.getQueues());
            result.addAll(threadPoolConfigQueue.collect());
        }


        if (threadPoolExecutor != null) {
            threadPoolActive.labels(commonLabelValues)
                    .set(threadPoolExecutor.getActiveCount());
            result.addAll(threadPoolActive.collect());

            threadPoolIdle.labels(commonLabelValues)
                    .set(threadPoolExecutor.getPoolSize() - threadPoolExecutor.getActiveCount());
            result.addAll(threadPoolIdle.collect());


            threadPoolQueue.labels(commonLabelValues)
                    .set(threadPoolExecutor.getQueue().size());
            result.addAll(threadPoolQueue.collect());
        }

        return result;
    }
@Test
    public void testPrometheusMetricsCollect2() throws Exception {
        MetricsBuilder metricsBuilder = new MetricsBuilder();
        // set buckets
        metricsBuilder.getClientTotalBuilder()
                .exponentialBuckets(1, 2, 15);
        metricsBuilder.getClientFailBuilder()
                .linearBuckets(0, 5, 15);

        Map<String, String> testLabels = new HashMap<>();
        testLabels.put("from", "test");

        try (SofaRpcMetricsCollector collector = new SofaRpcMetricsCollector(testLabels, metricsBuilder)) {
            CollectorRegistry registry = new CollectorRegistry();
            collector.register(registry);

            SofaRequest request = buildRequest();
            SofaResponse successResponse = buildSuccessResponse();
            SofaResponse failResponse = buildFailResponse();
            RpcInternalContext.getContext()
                    .setAttachment(RpcConstants.INTERNAL_KEY_CLIENT_ELAPSE, 100)
                    .setAttachment(RpcConstants.INTERNAL_KEY_IMPL_ELAPSE, 10)
                    .setAttachment(RpcConstants.INTERNAL_KEY_REQ_SIZE, 3)
                    .setAttachment(RpcConstants.INTERNAL_KEY_RESP_SIZE, 4);

            List<Collector.MetricFamilySamples> samplesList;

            EventBus.post(new ClientEndInvokeEvent(request, successResponse, null));
            EventBus.post(new ClientEndInvokeEvent(request, failResponse, null));

            EventBus.post(new ProviderPubEvent(new ProviderConfig<>()));

            EventBus.post(new ConsumerSubEvent(new ConsumerConfig<>()));

            ServerConfig serverConfig = new ServerConfig();
            EventBus.post(new ServerStartedEvent(serverConfig, new ThreadPoolExecutor(1, 1,
                    0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>())));

            samplesList = collector.collect();
            Assert.assertEquals(samplesList.size(), 14);

//            new HTTPServer(new InetSocketAddress(9000),registry);
//            Thread.currentThread().join();
        }
    }