Jian Li
Committed by Gerrit Code Review

Notify all metric reporters when new types of system metric added

Change-Id: I307be0cb68bdc7fc3c75212c3fac4390fb9391a9
...@@ -34,7 +34,7 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -34,7 +34,7 @@ import static org.slf4j.LoggerFactory.getLogger;
34 /** 34 /**
35 * Aggregate system metrics. 35 * Aggregate system metrics.
36 */ 36 */
37 -public class SystemMetricsAggregator { 37 +public final class SystemMetricsAggregator {
38 38
39 private final Logger log = getLogger(getClass()); 39 private final Logger log = getLogger(getClass());
40 40
...@@ -42,40 +42,108 @@ public class SystemMetricsAggregator { ...@@ -42,40 +42,108 @@ public class SystemMetricsAggregator {
42 private static final String DEFAULT_METER_SUFFIX = "rate"; 42 private static final String DEFAULT_METER_SUFFIX = "rate";
43 private static final String DISK_RESOURCE_TYPE = "disk"; 43 private static final String DISK_RESOURCE_TYPE = "disk";
44 private static final String NETWORK_RESOURCE_TYPE = "network"; 44 private static final String NETWORK_RESOURCE_TYPE = "network";
45 - private final Map<ControlMetricType, Meter> meterMap = Maps.newHashMap(); 45 + private final Map<ControlMetricType, Meter> systemMap = Maps.newHashMap();
46 - private final Set<ControlMetricType> metricTypeSet = Sets.newHashSet(); 46 + private final Map<String, Map<ControlMetricType, Meter>> diskMap = Maps.newHashMap();
47 + private final Map<String, Map<ControlMetricType, Meter>> networkMap = Maps.newHashMap();
47 48
48 - public SystemMetricsAggregator(MetricsService metricsService, Optional<String> resName, String resType) { 49 + private MetricsService metricsService;
49 - String resourceName = resName.isPresent() ? resName.get() : DEFAULT_RESOURCE_NAME;
50 - MetricsComponent mc = metricsService.registerComponent(resourceName);
51 50
52 - if (resName.isPresent()) { 51 + public static SystemMetricsAggregator getInstance() {
53 - if (DISK_RESOURCE_TYPE.equals(resType)) { 52 + return SingletonHelper.INSTANCE;
53 + }
54 +
55 + /**
56 + * Configures metric services.
57 + *
58 + * @param service metrics service
59 + */
60 + public void setMetricsService(MetricsService service) {
61 +
62 + metricsService = service;
63 + }
64 +
65 + /**
66 + * Increments system metric value.
67 + *
68 + * @param type metric type
69 + * @param value metric value
70 + */
71 + public void increment(ControlMetricType type, long value) {
72 + systemMap.get(type).mark(value);
73 + }
74 +
75 + /**
76 + * Increments disk or network metric value.
77 + *
78 + * @param resourceName resource name
79 + * @param resourceType resource type
80 + * @param type control metric type
81 + * @param value metric value
82 + */
83 + public void increment(String resourceName, String resourceType, ControlMetricType type, long value) {
84 + if (DISK_RESOURCE_TYPE.equals(resourceType) && diskMap.containsKey(resourceName)) {
85 + diskMap.get(resourceName).get(type).mark(value);
86 + }
87 +
88 + if (NETWORK_RESOURCE_TYPE.equals(resourceType) && networkMap.containsKey(resourceName)) {
89 + networkMap.get(resourceName).get(type).mark(value);
90 + }
91 + }
92 +
93 + /**
94 + * Adds a set of new monitoring metric types.
95 + *
96 + * @param optResourceName optional resource name, null denotes system metric
97 + * @param resType resource type
98 + */
99 + public void addMetrics(Optional<String> optResourceName, String resType) {
100 + Set<ControlMetricType> metricTypeSet = Sets.newHashSet();
101 + String resourceName = optResourceName.isPresent() ?
102 + optResourceName.get() : DEFAULT_RESOURCE_NAME;
103 +
104 + MetricsComponent metricsComponent = metricsService.registerComponent(resourceName);
105 +
106 + if (optResourceName.isPresent()) {
107 + if (!diskMap.containsKey(resourceName) && DISK_RESOURCE_TYPE.equals(resType)) {
54 metricTypeSet.addAll(ControlResource.DISK_METRICS); 108 metricTypeSet.addAll(ControlResource.DISK_METRICS);
55 - } else if (NETWORK_RESOURCE_TYPE.equals(resType)) { 109 + diskMap.putIfAbsent(resourceName,
110 + getMeterMap(metricTypeSet, metricsComponent, metricsService));
111 + metricsService.notifyReporters();
112 + } else if (!networkMap.containsKey(resourceName) && NETWORK_RESOURCE_TYPE.equals(resType)) {
56 metricTypeSet.addAll(ControlResource.NETWORK_METRICS); 113 metricTypeSet.addAll(ControlResource.NETWORK_METRICS);
114 + networkMap.putIfAbsent(resourceName,
115 + getMeterMap(metricTypeSet, metricsComponent, metricsService));
116 + metricsService.notifyReporters();
57 } else { 117 } else {
58 - log.warn("Not valid resource type {}", resType); 118 + return;
59 } 119 }
60 } else { 120 } else {
61 - metricTypeSet.addAll(ControlResource.MEMORY_METRICS); 121 + if (systemMap.isEmpty()) {
62 - metricTypeSet.addAll(ControlResource.CPU_METRICS); 122 + metricTypeSet.addAll(ControlResource.MEMORY_METRICS);
123 + metricTypeSet.addAll(ControlResource.CPU_METRICS);
124 +
125 + systemMap.putAll(getMeterMap(metricTypeSet, metricsComponent, metricsService));
126 + metricsService.notifyReporters();
127 + }
63 } 128 }
129 + }
64 130
65 - metricTypeSet.forEach(type -> { 131 + private Map<ControlMetricType, Meter> getMeterMap(Set<ControlMetricType> types,
66 - MetricsFeature metricsFeature = mc.registerFeature(type.toString()); 132 + MetricsComponent component,
67 - Meter meter = metricsService.createMeter(mc, metricsFeature, DEFAULT_METER_SUFFIX); 133 + MetricsService service) {
134 + Map<ControlMetricType, Meter> meterMap = Maps.newHashMap();
135 + types.forEach(type -> {
136 + MetricsFeature metricsFeature = component.registerFeature(type.toString());
137 + Meter meter = service.createMeter(component, metricsFeature, DEFAULT_METER_SUFFIX);
68 meterMap.putIfAbsent(type, meter); 138 meterMap.putIfAbsent(type, meter);
69 }); 139 });
140 + return meterMap;
70 } 141 }
71 142
72 - /** 143 + private SystemMetricsAggregator() {
73 - * Increments metric value. 144 + }
74 - * 145 +
75 - * @param type metric type 146 + private static class SingletonHelper {
76 - * @param value metric value 147 + private static final SystemMetricsAggregator INSTANCE = new SystemMetricsAggregator();
77 - */
78 - public void increment(ControlMetricType type, long value) {
79 - meterMap.get(type).mark(value);
80 } 148 }
81 } 149 }
......
...@@ -63,6 +63,9 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { ...@@ -63,6 +63,9 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource {
63 private static final String INVALID_RESOURCE_NAME = "Invalid resource name"; 63 private static final String INVALID_RESOURCE_NAME = "Invalid resource name";
64 private static final String INVALID_REQUEST = "Invalid request"; 64 private static final String INVALID_REQUEST = "Invalid request";
65 private static final int PERCENT_CONSTANT = 100; 65 private static final int PERCENT_CONSTANT = 100;
66 + private static final String SYSTEM_TYPE = "system";
67 + private static final String DISK_TYPE = "disk";
68 + private static final String NETWORK_TYPE = "network";
66 69
67 private static final Set<String> MEMORY_FIELD_SET = ControlResource.MEMORY_METRICS 70 private static final Set<String> MEMORY_FIELD_SET = ControlResource.MEMORY_METRICS
68 .stream().map(type -> toCamelCase(type.toString(), true)) 71 .stream().map(type -> toCamelCase(type.toString(), true))
...@@ -72,8 +75,7 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { ...@@ -72,8 +75,7 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource {
72 .stream().map(type -> toCamelCase(type.toString(), true)) 75 .stream().map(type -> toCamelCase(type.toString(), true))
73 .collect(Collectors.toSet()); 76 .collect(Collectors.toSet());
74 77
75 - private SystemMetricsAggregator systemAggr = 78 + private SystemMetricsAggregator aggregator = SystemMetricsAggregator.getInstance();
76 - new SystemMetricsAggregator(metricsService, Optional.ofNullable(null), "system");
77 79
78 /** 80 /**
79 * Collects CPU metrics. 81 * Collects CPU metrics.
...@@ -103,30 +105,33 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { ...@@ -103,30 +105,33 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource {
103 long userCpuTime = nullIsIllegal(jsonTree.get("userCpuTime").asLong(), INVALID_REQUEST); 105 long userCpuTime = nullIsIllegal(jsonTree.get("userCpuTime").asLong(), INVALID_REQUEST);
104 long cpuIdleTime = nullIsIllegal(jsonTree.get("cpuIdleTime").asLong(), INVALID_REQUEST); 106 long cpuIdleTime = nullIsIllegal(jsonTree.get("cpuIdleTime").asLong(), INVALID_REQUEST);
105 107
108 + aggregator.setMetricsService(metricsService);
109 + aggregator.addMetrics(Optional.ofNullable(null), SYSTEM_TYPE);
110 +
106 cm = new ControlMetric(ControlMetricType.CPU_LOAD, 111 cm = new ControlMetric(ControlMetricType.CPU_LOAD,
107 new MetricValue.Builder().load(cpuLoad).add()); 112 new MetricValue.Builder().load(cpuLoad).add());
108 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 113 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null));
109 - systemAggr.increment(ControlMetricType.CPU_LOAD, cpuLoad); 114 + aggregator.increment(ControlMetricType.CPU_LOAD, cpuLoad);
110 115
111 cm = new ControlMetric(ControlMetricType.TOTAL_CPU_TIME, 116 cm = new ControlMetric(ControlMetricType.TOTAL_CPU_TIME,
112 new MetricValue.Builder().load(totalCpuTime).add()); 117 new MetricValue.Builder().load(totalCpuTime).add());
113 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 118 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null));
114 - systemAggr.increment(ControlMetricType.TOTAL_CPU_TIME, totalCpuTime); 119 + aggregator.increment(ControlMetricType.TOTAL_CPU_TIME, totalCpuTime);
115 120
116 cm = new ControlMetric(ControlMetricType.SYS_CPU_TIME, 121 cm = new ControlMetric(ControlMetricType.SYS_CPU_TIME,
117 new MetricValue.Builder().load(sysCpuTime).add()); 122 new MetricValue.Builder().load(sysCpuTime).add());
118 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 123 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null));
119 - systemAggr.increment(ControlMetricType.SYS_CPU_TIME, sysCpuTime); 124 + aggregator.increment(ControlMetricType.SYS_CPU_TIME, sysCpuTime);
120 125
121 cm = new ControlMetric(ControlMetricType.USER_CPU_TIME, 126 cm = new ControlMetric(ControlMetricType.USER_CPU_TIME,
122 new MetricValue.Builder().load(userCpuTime).add()); 127 new MetricValue.Builder().load(userCpuTime).add());
123 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 128 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null));
124 - systemAggr.increment(ControlMetricType.USER_CPU_TIME, userCpuTime); 129 + aggregator.increment(ControlMetricType.USER_CPU_TIME, userCpuTime);
125 130
126 cm = new ControlMetric(ControlMetricType.CPU_IDLE_TIME, 131 cm = new ControlMetric(ControlMetricType.CPU_IDLE_TIME,
127 new MetricValue.Builder().load(cpuIdleTime).add()); 132 new MetricValue.Builder().load(cpuIdleTime).add());
128 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 133 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null));
129 - systemAggr.increment(ControlMetricType.CPU_IDLE_TIME, cpuIdleTime); 134 + aggregator.increment(ControlMetricType.CPU_IDLE_TIME, cpuIdleTime);
130 135
131 } catch (IOException e) { 136 } catch (IOException e) {
132 throw new IllegalArgumentException(e.getMessage()); 137 throw new IllegalArgumentException(e.getMessage());
...@@ -161,25 +166,28 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { ...@@ -161,25 +166,28 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource {
161 long memUsedRatio = memTotal == 0L ? 0L : (memUsed * PERCENT_CONSTANT) / memTotal; 166 long memUsedRatio = memTotal == 0L ? 0L : (memUsed * PERCENT_CONSTANT) / memTotal;
162 long memFreeRatio = memTotal == 0L ? 0L : (memFree * PERCENT_CONSTANT) / memTotal; 167 long memFreeRatio = memTotal == 0L ? 0L : (memFree * PERCENT_CONSTANT) / memTotal;
163 168
169 + aggregator.setMetricsService(metricsService);
170 + aggregator.addMetrics(Optional.ofNullable(null), SYSTEM_TYPE);
171 +
164 cm = new ControlMetric(ControlMetricType.MEMORY_USED_RATIO, 172 cm = new ControlMetric(ControlMetricType.MEMORY_USED_RATIO,
165 new MetricValue.Builder().load(memUsedRatio).add()); 173 new MetricValue.Builder().load(memUsedRatio).add());
166 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 174 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null));
167 - systemAggr.increment(ControlMetricType.MEMORY_USED_RATIO, memUsedRatio); 175 + aggregator.increment(ControlMetricType.MEMORY_USED_RATIO, memUsedRatio);
168 176
169 cm = new ControlMetric(ControlMetricType.MEMORY_FREE_RATIO, 177 cm = new ControlMetric(ControlMetricType.MEMORY_FREE_RATIO,
170 new MetricValue.Builder().load(memFreeRatio).add()); 178 new MetricValue.Builder().load(memFreeRatio).add());
171 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 179 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null));
172 - systemAggr.increment(ControlMetricType.MEMORY_FREE_RATIO, memFreeRatio); 180 + aggregator.increment(ControlMetricType.MEMORY_FREE_RATIO, memFreeRatio);
173 181
174 cm = new ControlMetric(ControlMetricType.MEMORY_USED, 182 cm = new ControlMetric(ControlMetricType.MEMORY_USED,
175 new MetricValue.Builder().load(memUsed).add()); 183 new MetricValue.Builder().load(memUsed).add());
176 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 184 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null));
177 - systemAggr.increment(ControlMetricType.MEMORY_USED, memUsed); 185 + aggregator.increment(ControlMetricType.MEMORY_USED, memUsed);
178 186
179 cm = new ControlMetric(ControlMetricType.MEMORY_FREE, 187 cm = new ControlMetric(ControlMetricType.MEMORY_FREE,
180 new MetricValue.Builder().load(memFree).add()); 188 new MetricValue.Builder().load(memFree).add());
181 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null)); 189 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, Optional.ofNullable(null));
182 - systemAggr.increment(ControlMetricType.MEMORY_FREE, memFree); 190 + aggregator.increment(ControlMetricType.MEMORY_FREE, memFree);
183 191
184 } catch (IOException e) { 192 } catch (IOException e) {
185 throw new IllegalArgumentException(e.getMessage()); 193 throw new IllegalArgumentException(e.getMessage());
...@@ -204,14 +212,15 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { ...@@ -204,14 +212,15 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource {
204 try { 212 try {
205 ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); 213 ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
206 ArrayNode diskRes = 214 ArrayNode diskRes =
207 - jsonTree.get("disks") == null ? mapper().createArrayNode() : (ArrayNode) jsonTree.get("disks"); 215 + jsonTree.get("disks") == null ?
216 + mapper().createArrayNode() : (ArrayNode) jsonTree.get("disks");
208 217
209 for (JsonNode node : diskRes) { 218 for (JsonNode node : diskRes) {
210 JsonNode resourceName = node.get("resourceName"); 219 JsonNode resourceName = node.get("resourceName");
211 nullIsIllegal(resourceName, INVALID_RESOURCE_NAME); 220 nullIsIllegal(resourceName, INVALID_RESOURCE_NAME);
212 221
213 - SystemMetricsAggregator diskAggr = new SystemMetricsAggregator(metricsService, 222 + aggregator.setMetricsService(metricsService);
214 - Optional.of(resourceName.asText()), "disk"); 223 + aggregator.addMetrics(Optional.of(resourceName.asText()), DISK_TYPE);
215 224
216 long readBytes = nullIsIllegal(node.get("readBytes").asLong(), INVALID_REQUEST); 225 long readBytes = nullIsIllegal(node.get("readBytes").asLong(), INVALID_REQUEST);
217 long writeBytes = nullIsIllegal(node.get("writeBytes").asLong(), INVALID_REQUEST); 226 long writeBytes = nullIsIllegal(node.get("writeBytes").asLong(), INVALID_REQUEST);
...@@ -219,12 +228,13 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { ...@@ -219,12 +228,13 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource {
219 cm = new ControlMetric(ControlMetricType.DISK_READ_BYTES, 228 cm = new ControlMetric(ControlMetricType.DISK_READ_BYTES,
220 new MetricValue.Builder().load(readBytes).add()); 229 new MetricValue.Builder().load(readBytes).add());
221 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText()); 230 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText());
222 - diskAggr.increment(ControlMetricType.DISK_READ_BYTES, readBytes); 231 + aggregator.increment(resourceName.asText(), DISK_TYPE,
223 - 232 + ControlMetricType.DISK_READ_BYTES, readBytes);
224 cm = new ControlMetric(ControlMetricType.DISK_WRITE_BYTES, 233 cm = new ControlMetric(ControlMetricType.DISK_WRITE_BYTES,
225 new MetricValue.Builder().load(writeBytes).add()); 234 new MetricValue.Builder().load(writeBytes).add());
226 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText()); 235 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText());
227 - diskAggr.increment(ControlMetricType.DISK_WRITE_BYTES, writeBytes); 236 + aggregator.increment(resourceName.asText(), DISK_TYPE,
237 + ControlMetricType.DISK_WRITE_BYTES, writeBytes);
228 } 238 }
229 } catch (IOException e) { 239 } catch (IOException e) {
230 throw new IllegalArgumentException(e.getMessage()); 240 throw new IllegalArgumentException(e.getMessage());
...@@ -256,8 +266,8 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { ...@@ -256,8 +266,8 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource {
256 JsonNode resourceName = node.get("resourceName"); 266 JsonNode resourceName = node.get("resourceName");
257 nullIsIllegal(resourceName, INVALID_RESOURCE_NAME); 267 nullIsIllegal(resourceName, INVALID_RESOURCE_NAME);
258 268
259 - SystemMetricsAggregator networkAggr = new SystemMetricsAggregator(metricsService, 269 + aggregator.setMetricsService(metricsService);
260 - Optional.of(resourceName.asText()), "network"); 270 + aggregator.addMetrics(Optional.of(resourceName.asText()), NETWORK_TYPE);
261 271
262 long inBytes = nullIsIllegal(node.get("incomingBytes").asLong(), INVALID_REQUEST); 272 long inBytes = nullIsIllegal(node.get("incomingBytes").asLong(), INVALID_REQUEST);
263 long outBytes = nullIsIllegal(node.get("outgoingBytes").asLong(), INVALID_REQUEST); 273 long outBytes = nullIsIllegal(node.get("outgoingBytes").asLong(), INVALID_REQUEST);
...@@ -267,22 +277,26 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { ...@@ -267,22 +277,26 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource {
267 cm = new ControlMetric(ControlMetricType.NW_INCOMING_BYTES, 277 cm = new ControlMetric(ControlMetricType.NW_INCOMING_BYTES,
268 new MetricValue.Builder().load(inBytes).add()); 278 new MetricValue.Builder().load(inBytes).add());
269 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText()); 279 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText());
270 - networkAggr.increment(ControlMetricType.NW_INCOMING_BYTES, inBytes); 280 + aggregator.increment(resourceName.asText(), NETWORK_TYPE,
281 + ControlMetricType.NW_INCOMING_BYTES, inBytes);
271 282
272 cm = new ControlMetric(ControlMetricType.NW_OUTGOING_BYTES, 283 cm = new ControlMetric(ControlMetricType.NW_OUTGOING_BYTES,
273 new MetricValue.Builder().load(outBytes).add()); 284 new MetricValue.Builder().load(outBytes).add());
274 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText()); 285 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText());
275 - networkAggr.increment(ControlMetricType.NW_OUTGOING_BYTES, outBytes); 286 + aggregator.increment(resourceName.asText(), NETWORK_TYPE,
287 + ControlMetricType.NW_OUTGOING_BYTES, outBytes);
276 288
277 cm = new ControlMetric(ControlMetricType.NW_INCOMING_PACKETS, 289 cm = new ControlMetric(ControlMetricType.NW_INCOMING_PACKETS,
278 new MetricValue.Builder().load(inPackets).add()); 290 new MetricValue.Builder().load(inPackets).add());
279 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText()); 291 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText());
280 - networkAggr.increment(ControlMetricType.NW_INCOMING_PACKETS, inPackets); 292 + aggregator.increment(resourceName.asText(), NETWORK_TYPE,
293 + ControlMetricType.NW_INCOMING_PACKETS, inPackets);
281 294
282 cm = new ControlMetric(ControlMetricType.NW_OUTGOING_PACKETS, 295 cm = new ControlMetric(ControlMetricType.NW_OUTGOING_PACKETS,
283 new MetricValue.Builder().load(outPackets).add()); 296 new MetricValue.Builder().load(outPackets).add());
284 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText()); 297 monitorService.updateMetric(cm, UPDATE_INTERVAL_IN_MINUTE, resourceName.asText());
285 - networkAggr.increment(ControlMetricType.NW_OUTGOING_PACKETS, outPackets); 298 + aggregator.increment(resourceName.asText(), NETWORK_TYPE,
299 + ControlMetricType.NW_OUTGOING_PACKETS, outPackets);
286 } 300 }
287 } catch (IOException e) { 301 } catch (IOException e) {
288 throw new IllegalArgumentException(e.getMessage()); 302 throw new IllegalArgumentException(e.getMessage());
......
...@@ -36,7 +36,6 @@ import org.onlab.rest.BaseResource; ...@@ -36,7 +36,6 @@ import org.onlab.rest.BaseResource;
36 import org.onosproject.cpman.ControlPlaneMonitorService; 36 import org.onosproject.cpman.ControlPlaneMonitorService;
37 import org.onosproject.cpman.SystemInfo; 37 import org.onosproject.cpman.SystemInfo;
38 import org.onosproject.cpman.impl.SystemInfoFactory; 38 import org.onosproject.cpman.impl.SystemInfoFactory;
39 -import org.onosproject.cpman.impl.SystemMetricsAggregator;
40 import org.onosproject.net.DeviceId; 39 import org.onosproject.net.DeviceId;
41 import org.onosproject.rest.resources.ResourceTest; 40 import org.onosproject.rest.resources.ResourceTest;
42 41
...@@ -51,7 +50,6 @@ import java.util.Map; ...@@ -51,7 +50,6 @@ import java.util.Map;
51 import java.util.Optional; 50 import java.util.Optional;
52 51
53 import static org.easymock.EasyMock.anyInt; 52 import static org.easymock.EasyMock.anyInt;
54 -import static org.easymock.EasyMock.anyLong;
55 import static org.easymock.EasyMock.anyObject; 53 import static org.easymock.EasyMock.anyObject;
56 import static org.easymock.EasyMock.anyString; 54 import static org.easymock.EasyMock.anyString;
57 import static org.easymock.EasyMock.createMock; 55 import static org.easymock.EasyMock.createMock;
...@@ -69,9 +67,6 @@ public class ControlMetricsCollectorResourceTest extends ResourceTest { ...@@ -69,9 +67,6 @@ public class ControlMetricsCollectorResourceTest extends ResourceTest {
69 final ControlPlaneMonitorService mockControlPlaneMonitorService = 67 final ControlPlaneMonitorService mockControlPlaneMonitorService =
70 createMock(ControlPlaneMonitorService.class); 68 createMock(ControlPlaneMonitorService.class);
71 final MetricsService mockMetricsService = new MockMetricsService(); 69 final MetricsService mockMetricsService = new MockMetricsService();
72 - final MetricsComponent mockMetricsComponent = createMock(MetricsComponent.class);
73 - final SystemMetricsAggregator mockAggregator = createMock(SystemMetricsAggregator.class);
74 -
75 70
76 private static final String PREFIX = "collector"; 71 private static final String PREFIX = "collector";
77 72
...@@ -104,10 +99,6 @@ public class ControlMetricsCollectorResourceTest extends ResourceTest { ...@@ -104,10 +99,6 @@ public class ControlMetricsCollectorResourceTest extends ResourceTest {
104 expectLastCall().times(5); 99 expectLastCall().times(5);
105 replay(mockControlPlaneMonitorService); 100 replay(mockControlPlaneMonitorService);
106 101
107 - mockAggregator.increment(anyObject(), anyLong());
108 - expectLastCall();
109 - replay(mockAggregator);
110 -
111 basePostTest("cpu-metrics-post.json", PREFIX + "/cpu_metrics"); 102 basePostTest("cpu-metrics-post.json", PREFIX + "/cpu_metrics");
112 } 103 }
113 104
......