Переглянути джерело

Record total inbound traffic data in metric file (#555)

- Regard the total inbound as a "virtual node" with the name `__total_inbound_traffic__`

Signed-off-by: Carpenter Lee <hooleeucas@163.com>
master
Carpenter Lee Eric Zhao 5 роки тому
джерело
коміт
341b6426f0
2 змінених файлів з 18 додано та 12 видалено
  1. +2
    -0
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/Constants.java
  2. +16
    -12
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricTimerListener.java

+ 2
- 0
sentinel-core/src/main/java/com/alibaba/csp/sentinel/Constants.java Переглянути файл

@@ -38,6 +38,8 @@ public final class Constants {
public final static String ROOT_ID = "machine-root";
public final static String CONTEXT_DEFAULT_NAME = "sentinel_default_context";

public final static String TOTAL_IN_RESOURCE_NAME = "__total_inbound_traffic__";

public final static DefaultNode ROOT = new EntranceNode(new StringResourceWrapper(ROOT_ID, EntryType.IN),
Env.nodeBuilder.buildClusterNode());



+ 16
- 12
sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricTimerListener.java Переглянути файл

@@ -21,6 +21,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;

import com.alibaba.csp.sentinel.Constants;
import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.log.RecordLog;
import com.alibaba.csp.sentinel.node.ClusterNode;
@@ -38,23 +39,13 @@ public class MetricTimerListener implements Runnable {
@Override
public void run() {
Map<Long, List<MetricNode>> maps = new TreeMap<Long, List<MetricNode>>();

for (Entry<ResourceWrapper, ClusterNode> e : ClusterBuilderSlot.getClusterNodeMap().entrySet()) {
String name = e.getKey().getName();
ClusterNode node = e.getValue();
Map<Long, MetricNode> metrics = node.metrics();

for (Entry<Long, MetricNode> entry : metrics.entrySet()) {
long time = entry.getKey();
MetricNode metricNode = entry.getValue();
metricNode.setResource(name);
if (maps.get(time) == null) {
maps.put(time, new ArrayList<MetricNode>());
}
List<MetricNode> nodes = maps.get(time);
nodes.add(entry.getValue());
}
aggregate(maps, metrics, name);
}
aggregate(maps, Constants.ENTRY_NODE.metrics(), Constants.TOTAL_IN_RESOURCE_NAME);
if (!maps.isEmpty()) {
for (Entry<Long, List<MetricNode>> entry : maps.entrySet()) {
try {
@@ -66,4 +57,17 @@ public class MetricTimerListener implements Runnable {
}
}

private void aggregate(Map<Long, List<MetricNode>> maps, Map<Long, MetricNode> metrics, String resourceName) {
for (Entry<Long, MetricNode> entry : metrics.entrySet()) {
long time = entry.getKey();
MetricNode metricNode = entry.getValue();
metricNode.setResource(resourceName);
if (maps.get(time) == null) {
maps.put(time, new ArrayList<MetricNode>());
}
List<MetricNode> nodes = maps.get(time);
nodes.add(entry.getValue());
}
}

}

Завантаження…
Відмінити
Зберегти