@GetMapping("/metrics")
    public ObjectNode metrics(HttpServletRequest request) {
        boolean onlyStatus = Boolean.parseBoolean(WebUtils.optional(request, "onlyStatus", "true"));
        ObjectNode result = JacksonUtils.createEmptyJsonNode();
        result.put("status", serverStatusManager.getServerStatus().name());
        if (onlyStatus) {
            return result;
        }
        Collection<String> allClientId = clientManager.allClientId();
        int connectionBasedClient = 0;
        int ephemeralIpPortClient = 0;
        int persistentIpPortClient = 0;
        int responsibleClientCount = 0;
        int responsibleIpCount = 0;
        for (String clientId : allClientId) {
            if (clientId.contains(IpPortBasedClient.ID_DELIMITER)) {
                if (clientId.endsWith(ClientConstants.PERSISTENT_SUFFIX)) {
                    persistentIpPortClient += 1;
                } else {
                    ephemeralIpPortClient += 1;
                }
            } else {
                connectionBasedClient += 1;
            }
            Client client = clientManager.getClient(clientId);
            if (clientManager.isResponsibleClient(client)) {
                responsibleClientCount += 1;
                responsibleIpCount += client.getAllPublishedService().size();
            }
        }
        result.put("serviceCount", MetricsMonitor.getDomCountMonitor().get());
        result.put("instanceCount", MetricsMonitor.getIpCountMonitor().get());
        result.put("subscribeCount", MetricsMonitor.getSubscriberCount().get());
        result.put("responsibleInstanceCount", responsibleIpCount);
        result.put("clientCount", allClientId.size());
        result.put("connectionBasedClientCount", connectionBasedClient);
        result.put("ephemeralIpPortClientCount", ephemeralIpPortClient);
        result.put("persistentIpPortClientCount", persistentIpPortClient);
        result.put("responsibleClientCount", responsibleClientCount);
        result.put("cpu", EnvUtil.getCpu());
        result.put("load", EnvUtil.getLoad());
        result.put("mem", EnvUtil.getMem());
        return result;
    }
@Test
    void testMetrics() {
        Mockito.when(serverStatusManager.getServerStatus()).thenReturn(ServerStatus.UP);
        Collection<String> clients = new HashSet<>();
        clients.add("1628132208793_127.0.0.1_8080");
        clients.add("127.0.0.1:8081#true");
        clients.add("127.0.0.1:8082#false");
        Mockito.when(clientManager.allClientId()).thenReturn(clients);
        Client client = new IpPortBasedClient("127.0.0.1:8081#true", true);
        client.addServiceInstance(Service.newService("", "", ""), new InstancePublishInfo());
        Mockito.when(clientManager.getClient("127.0.0.1:8081#true")).thenReturn(client);
        Mockito.when(clientManager.isResponsibleClient(client)).thenReturn(Boolean.TRUE);
        
        MockHttpServletRequest servletRequest = new MockHttpServletRequest();
        servletRequest.addParameter("onlyStatus", "false");
        ObjectNode objectNode = operatorController.metrics(servletRequest);
        
        assertEquals(1, objectNode.get("responsibleInstanceCount").asInt());
        assertEquals(ServerStatus.UP.toString(), objectNode.get("status").asText());
        assertEquals(3, objectNode.get("clientCount").asInt());
        assertEquals(1, objectNode.get("connectionBasedClientCount").asInt());
        assertEquals(1, objectNode.get("ephemeralIpPortClientCount").asInt());
        assertEquals(1, objectNode.get("persistentIpPortClientCount").asInt());
        assertEquals(1, objectNode.get("responsibleClientCount").asInt());
    }