Search in sources :

Example 1 with MetricNode

use of com.alibaba.csp.sentinel.node.metric.MetricNode in project Sentinel by alibaba.

the class SendMetricCommandHandler method addCpuUsageAndLoad.

/**
 * add current cpu usage and load to the metric list.
 *
 * @param list metric list, should not be null
 */
private void addCpuUsageAndLoad(List<MetricNode> list) {
    long time = TimeUtil.currentTimeMillis() / 1000 * 1000;
    double load = SystemRuleManager.getCurrentSystemAvgLoad();
    double usage = SystemRuleManager.getCurrentCpuUsage();
    if (load > 0) {
        MetricNode loadNode = toNode(load, time, Constants.SYSTEM_LOAD_RESOURCE_NAME);
        list.add(loadNode);
    }
    if (usage > 0) {
        MetricNode usageNode = toNode(usage, time, Constants.CPU_USAGE_RESOURCE_NAME);
        list.add(usageNode);
    }
}
Also used : MetricNode(com.alibaba.csp.sentinel.node.metric.MetricNode)

Example 2 with MetricNode

use of com.alibaba.csp.sentinel.node.metric.MetricNode in project Sentinel by alibaba.

the class MetricFetcher method handleBody.

private void handleBody(String[] lines, MachineInfo machine, Map<String, MetricEntity> map) {
    // logger.info("handleBody() lines=" + lines.length + ", machine=" + machine);
    if (lines.length < 1) {
        return;
    }
    for (String line : lines) {
        try {
            MetricNode node = MetricNode.fromThinString(line);
            if (shouldFilterOut(node.getResource())) {
                continue;
            }
            /*
                 * aggregation metrics by app_resource_timeSecond, ignore ip and port.
                 */
            String key = buildMetricKey(machine.getApp(), node.getResource(), node.getTimestamp());
            MetricEntity metricEntity = map.computeIfAbsent(key, s -> {
                MetricEntity initMetricEntity = new MetricEntity();
                initMetricEntity.setApp(machine.getApp());
                initMetricEntity.setTimestamp(new Date(node.getTimestamp()));
                initMetricEntity.setPassQps(0L);
                initMetricEntity.setBlockQps(0L);
                initMetricEntity.setRtAndSuccessQps(0, 0L);
                initMetricEntity.setExceptionQps(0L);
                initMetricEntity.setCount(0);
                initMetricEntity.setResource(node.getResource());
                return initMetricEntity;
            });
            metricEntity.addPassQps(node.getPassQps());
            metricEntity.addBlockQps(node.getBlockQps());
            metricEntity.addRtAndSuccessQps(node.getRt(), node.getSuccessQps());
            metricEntity.addExceptionQps(node.getExceptionQps());
            metricEntity.addCount(1);
        } catch (Exception e) {
            logger.warn("handleBody line exception, machine: {}, line: {}", machine.toLogString(), line);
        }
    }
}
Also used : MetricEntity(com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity) MetricNode(com.alibaba.csp.sentinel.node.metric.MetricNode) Date(java.util.Date) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException)

Example 3 with MetricNode

use of com.alibaba.csp.sentinel.node.metric.MetricNode in project Sentinel by alibaba.

the class MetricCollector method aggregate.

/**
 * aggregate the metrics, the metrics under the same resource will left the lasted value
 * @param metricNodeMap metrics map
 * @param metrics metrics info group by timestamp
 * @param node the node
 */
private void aggregate(Map<String, MetricNode> metricNodeMap, List<MetricNode> metrics, ClusterNode node) {
    if (metrics == null || metrics.size() == 0) {
        return;
    }
    for (MetricNode metricNode : metrics) {
        String resource = node.getName();
        metricNode.setResource(resource);
        metricNode.setClassification(node.getResourceType());
        MetricNode existMetricNode = metricNodeMap.get(resource);
        // always keep the MetricNode is the last
        if (existMetricNode != null && existMetricNode.getTimestamp() > metricNode.getTimestamp()) {
            continue;
        }
        metricNodeMap.put(resource, metricNode);
    }
}
Also used : MetricNode(com.alibaba.csp.sentinel.node.metric.MetricNode)

Example 4 with MetricNode

use of com.alibaba.csp.sentinel.node.metric.MetricNode in project pig by pig-mesh.

the class MetricFetcher method handleBody.

private void handleBody(String[] lines, MachineInfo machine, Map<String, MetricEntity> map) {
    // logger.info("handleBody() lines=" + lines.length + ", machine=" + machine);
    if (lines.length < 1) {
        return;
    }
    for (String line : lines) {
        try {
            MetricNode node = MetricNode.fromThinString(line);
            if (shouldFilterOut(node.getResource())) {
                continue;
            }
            /*
				 * aggregation metrics by app_resource_timeSecond, ignore ip and port.
				 */
            String key = buildMetricKey(machine.getApp(), node.getResource(), node.getTimestamp());
            MetricEntity metricEntity = map.computeIfAbsent(key, s -> {
                MetricEntity initMetricEntity = new MetricEntity();
                initMetricEntity.setApp(machine.getApp());
                initMetricEntity.setTimestamp(new Date(node.getTimestamp()));
                initMetricEntity.setPassQps(0L);
                initMetricEntity.setBlockQps(0L);
                initMetricEntity.setRtAndSuccessQps(0, 0L);
                initMetricEntity.setExceptionQps(0L);
                initMetricEntity.setCount(0);
                initMetricEntity.setResource(node.getResource());
                return initMetricEntity;
            });
            metricEntity.addPassQps(node.getPassQps());
            metricEntity.addBlockQps(node.getBlockQps());
            metricEntity.addRtAndSuccessQps(node.getRt(), node.getSuccessQps());
            metricEntity.addExceptionQps(node.getExceptionQps());
            metricEntity.addCount(1);
        } catch (Exception e) {
            logger.warn("handleBody line exception, machine: {}, line: {}", machine.toLogString(), line);
        }
    }
}
Also used : MetricEntity(com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity) MetricNode(com.alibaba.csp.sentinel.node.metric.MetricNode) Date(java.util.Date) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException)

Example 5 with MetricNode

use of com.alibaba.csp.sentinel.node.metric.MetricNode in project spring-boot-student by wyh-spring-ecosystem-student.

the class MetricFetcher method handleBody.

private void handleBody(String[] lines, MachineInfo machine, Map<String, MetricEntity> map) {
    // logger.info("handleBody() lines=" + lines.length + ", machine=" + machine);
    if (lines.length < 1) {
        return;
    }
    for (String line : lines) {
        try {
            MetricNode node = MetricNode.fromThinString(line);
            if (shouldFilterOut(node.getResource())) {
                continue;
            }
            /*
                 * aggregation metrics by app_resource_timeSecond, ignore ip and port.
                 */
            String key = buildMetricKey(machine.getApp(), node.getResource(), node.getTimestamp());
            MetricEntity entity = map.get(key);
            if (entity != null) {
                entity.addPassQps(node.getPassQps());
                entity.addBlockQps(node.getBlockQps());
                entity.addRtAndSuccessQps(node.getRt(), node.getSuccessQps());
                entity.addExceptionQps(node.getExceptionQps());
                entity.addCount(1);
            } else {
                entity = new MetricEntity();
                entity.setApp(machine.getApp());
                entity.setTimestamp(new Date(node.getTimestamp()));
                entity.setPassQps(node.getPassQps());
                entity.setBlockQps(node.getBlockQps());
                entity.setRtAndSuccessQps(node.getRt(), node.getSuccessQps());
                entity.setExceptionQps(node.getExceptionQps());
                entity.setCount(1);
                entity.setResource(node.getResource());
                map.put(key, entity);
            }
        } catch (Exception e) {
            logger.warn("handleBody line exception, machine: {}, line: {}", machine.toLogString(), line);
        }
    }
}
Also used : MetricEntity(com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity) MetricNode(com.alibaba.csp.sentinel.node.metric.MetricNode) Date(java.util.Date) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException)

Aggregations

MetricNode (com.alibaba.csp.sentinel.node.metric.MetricNode)13 MetricEntity (com.alibaba.csp.sentinel.dashboard.datasource.entity.MetricEntity)5 ConnectException (java.net.ConnectException)5 SocketTimeoutException (java.net.SocketTimeoutException)5 Date (java.util.Date)5 ClusterNode (com.alibaba.csp.sentinel.node.ClusterNode)1 MetricSearcher (com.alibaba.csp.sentinel.node.metric.MetricSearcher)1 ResourceWrapper (com.alibaba.csp.sentinel.slotchain.ResourceWrapper)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1