Search in sources :

Example 1 with HealthCheckTask

use of com.alibaba.nacos.naming.healthcheck.HealthCheckTask in project nacos by alibaba.

the class CatalogController method rt4Service.

/**
 * Get response time of service.
 *
 * @param request http request
 * @return response time information
 */
@RequestMapping("/rt/service")
public ObjectNode rt4Service(HttpServletRequest request) throws NacosException {
    String namespaceId = WebUtils.optional(request, CommonParams.NAMESPACE_ID, Constants.DEFAULT_NAMESPACE_ID);
    String serviceName = WebUtils.required(request, CommonParams.SERVICE_NAME);
    Service service = serviceManager.getService(namespaceId, serviceName);
    serviceManager.checkServiceIsNull(service, namespaceId, serviceName);
    ObjectNode result = JacksonUtils.createEmptyJsonNode();
    ArrayNode clusters = JacksonUtils.createEmptyArrayNode();
    for (Map.Entry<String, com.alibaba.nacos.naming.core.Cluster> entry : service.getClusterMap().entrySet()) {
        ObjectNode packet = JacksonUtils.createEmptyJsonNode();
        HealthCheckTask task = entry.getValue().getHealthCheckTask();
        packet.put("name", entry.getKey());
        packet.put("checkRTBest", task.getCheckRtBest());
        packet.put("checkRTWorst", task.getCheckRtWorst());
        packet.put("checkRTNormalized", task.getCheckRtNormalized());
        clusters.add(packet);
    }
    result.replace("clusters", clusters);
    return result;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) CatalogService(com.alibaba.nacos.naming.core.CatalogService) Service(com.alibaba.nacos.naming.core.Service) HealthCheckTask(com.alibaba.nacos.naming.healthcheck.HealthCheckTask) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Map(java.util.Map) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with HealthCheckTask

use of com.alibaba.nacos.naming.healthcheck.HealthCheckTask in project nacos by alibaba.

the class Cluster method init.

/**
 * Init cluster.
 */
public void init() {
    if (inited) {
        return;
    }
    checkTask = new HealthCheckTask(this);
    HealthCheckReactor.scheduleCheck(checkTask);
    inited = true;
}
Also used : HealthCheckTask(com.alibaba.nacos.naming.healthcheck.HealthCheckTask)

Aggregations

HealthCheckTask (com.alibaba.nacos.naming.healthcheck.HealthCheckTask)2 CatalogService (com.alibaba.nacos.naming.core.CatalogService)1 Service (com.alibaba.nacos.naming.core.Service)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Map (java.util.Map)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1