Search in sources :

Example 1 with ClientConfigMetricRequest

use of com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest in project nacos by alibaba.

the class ClientMetricsController method getClientMetrics.

/**
 * Get client config listener lists of subscriber in local machine.
 */
@GetMapping("/current")
public Map<String, Object> getClientMetrics(@RequestParam("ip") String ip, @RequestParam(value = "dataId", required = false) String dataId, @RequestParam(value = "group", required = false) String group, @RequestParam(value = "tenant", required = false) String tenant) {
    Map<String, Object> metrics = new HashMap<>(16);
    List<Connection> connectionsByIp = connectionManager.getConnectionByIp(ip);
    for (Connection connectionByIp : connectionsByIp) {
        try {
            ClientConfigMetricRequest clientMetrics = new ClientConfigMetricRequest();
            if (StringUtils.isNotBlank(dataId)) {
                clientMetrics.getMetricsKeys().add(ClientConfigMetricRequest.MetricsKey.build(CACHE_DATA, GroupKey2.getKey(dataId, group, tenant)));
                clientMetrics.getMetricsKeys().add(ClientConfigMetricRequest.MetricsKey.build(SNAPSHOT_DATA, GroupKey2.getKey(dataId, group, tenant)));
            }
            ClientConfigMetricResponse request1 = (ClientConfigMetricResponse) connectionByIp.request(clientMetrics, 1000L);
            metrics.putAll(request1.getMetrics());
        } catch (Exception e) {
            Loggers.CORE.error("Get config metrics error from client ip={},dataId={},group={},tenant={},error={}", ip, dataId, group, tenant, e);
        }
    }
    return metrics;
}
Also used : ClientConfigMetricRequest(com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest) HashMap(java.util.HashMap) Connection(com.alibaba.nacos.core.remote.Connection) ClientConfigMetricResponse(com.alibaba.nacos.api.config.remote.response.ClientConfigMetricResponse) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

ClientConfigMetricRequest (com.alibaba.nacos.api.config.remote.request.ClientConfigMetricRequest)1 ClientConfigMetricResponse (com.alibaba.nacos.api.config.remote.response.ClientConfigMetricResponse)1 Connection (com.alibaba.nacos.core.remote.Connection)1 HashMap (java.util.HashMap)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1