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>
This commit is contained in:
parent
4073053b3a
commit
341b6426f0
|
|
@ -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());
|
||||
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue