Jian Li
Committed by Gerrit Code Review

Augment metrics model to monitor more # of control metrics

Existing implementation only monitors OpenFlow messages.
This commit augments the metrics model in a way to monitor more
number of control metrics including
- CPU Load, total CPU time, sys CPU time, user CPU time, etc.
- Used memory percentage, free memory percentage
- Disk read/write bytes
- Network incoming/outgoing bytes/packets

Change-Id: I9e8eee163c3033132eb202f3c75bad246c87f133
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
34 <onos.app.name>org.onosproject.cpman</onos.app.name> 34 <onos.app.name>org.onosproject.cpman</onos.app.name>
35 <onos.app.category>default</onos.app.category> 35 <onos.app.category>default</onos.app.category>
36 <onos.app.url>http://onosproject.org</onos.app.url> 36 <onos.app.url>http://onosproject.org</onos.app.url>
37 - <onos.app.readme>Control plane management application. 37 + <onos.app.readme>Control plane management application.</onos.app.readme>
38 - </onos.app.readme>
39 </properties> 38 </properties>
40 39
41 <dependencies> 40 <dependencies>
......
1 /* 1 /*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015-2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -20,27 +20,78 @@ package org.onosproject.cpman; ...@@ -20,27 +20,78 @@ package org.onosproject.cpman;
20 */ 20 */
21 public enum ControlMetricType { 21 public enum ControlMetricType {
22 22
23 - /** Mapped to PACKET-IN message of OpenFlow. */ 23 + /* Mapped to PACKET-IN message of OpenFlow. */
24 INBOUND_PACKET, 24 INBOUND_PACKET,
25 25
26 - /** Mapped to PACKET-OUT message of OpenFlow. */ 26 + /* Mapped to PACKET-OUT message of OpenFlow. */
27 OUTBOUND_PACKET, 27 OUTBOUND_PACKET,
28 28
29 - /** Mapped to FLOW-MOD message of OpenFlow. */ 29 + /* Mapped to FLOW-MOD message of OpenFlow. */
30 FLOW_MOD_PACKET, 30 FLOW_MOD_PACKET,
31 31
32 - /** Mapped to FLOW-REMOVED message of OpenFlow. */ 32 + /* Mapped to FLOW-REMOVED message of OpenFlow. */
33 FLOW_REMOVED_PACKET, 33 FLOW_REMOVED_PACKET,
34 34
35 - /** Mapped to STATS-REQUEST message of OpenFlow. */ 35 + /* Mapped to STATS-REQUEST message of OpenFlow. */
36 REQUEST_PACKET, 36 REQUEST_PACKET,
37 37
38 - /** Mapped to STATS-REPLY message of OpenFlow. */ 38 + /* Mapped to STATS-REPLY message of OpenFlow. */
39 REPLY_PACKET, 39 REPLY_PACKET,
40 40
41 - /** Cpu Utilization. */ 41 + /* Number of CPU cores. */
42 - CPU_INFO, 42 + NUM_OF_CORES,
43 43
44 - /** Memory Utilization. */ 44 + /* Number of CPUs. **/
45 - MEMORY_INFO 45 + NUM_OF_CPUS,
46 +
47 + /* CPU Speed. **/
48 + CPU_SPEED,
49 +
50 + /* CPU Load. **/
51 + CPU_LOAD,
52 +
53 + /* Total Amount of CPU Up Time. **/
54 + TOTAL_CPU_TIME,
55 +
56 + /* System CPU Up Time. **/
57 + SYS_CPU_TIME,
58 +
59 + /* User CPU Up Time. **/
60 + USER_CPU_TIME,
61 +
62 + /* CPU Idle Time. **/
63 + CPU_IDLE_TIME,
64 +
65 + /* Percentage of Used Memory Amount. */
66 + MEMORY_USED_PERCENTAGE,
67 +
68 + /* Percentage of Free Memory Amount. **/
69 + MEMORY_FREE_PERCENTAGE,
70 +
71 + /* Used Memory Amount. **/
72 + MEMORY_USED,
73 +
74 + /* Free Memory Amount. **/
75 + MEMORY_FREE,
76 +
77 + /* Total Amount of Memory. **/
78 + MEMORY_TOTAL,
79 +
80 + /* Disk Read Bytes. **/
81 + DISK_READ_BYTES,
82 +
83 + /* Disk Write Bytes. **/
84 + DISK_WRITE_BYTES,
85 +
86 + /* Network Incoming Bytes. **/
87 + NW_INCOMING_BYTES,
88 +
89 + /* Network Outgoing Bytes. **/
90 + NW_OUTGOING_BYTES,
91 +
92 + /* Network Incoming Packets. **/
93 + NW_INCOMING_PACKETS,
94 +
95 + /* Network Outgoing Packets. **/
96 + NW_OUTGOING_PACKETS
46 } 97 }
......
1 /* 1 /*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015-2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -15,11 +15,13 @@ ...@@ -15,11 +15,13 @@
15 */ 15 */
16 package org.onosproject.cpman; 16 package org.onosproject.cpman;
17 17
18 +import com.google.common.collect.ImmutableMap;
19 +import com.google.common.collect.ImmutableSet;
20 +import com.google.common.collect.Sets;
18 import org.onlab.metrics.MetricsService; 21 import org.onlab.metrics.MetricsService;
19 import org.onosproject.net.DeviceId; 22 import org.onosproject.net.DeviceId;
20 import org.onosproject.net.device.DeviceService; 23 import org.onosproject.net.device.DeviceService;
21 24
22 -import java.util.HashSet;
23 import java.util.Map; 25 import java.util.Map;
24 import java.util.Optional; 26 import java.util.Optional;
25 import java.util.Set; 27 import java.util.Set;
...@@ -34,16 +36,35 @@ public final class ControlMetricsFactory { ...@@ -34,16 +36,35 @@ public final class ControlMetricsFactory {
34 private MetricsService metricsService; 36 private MetricsService metricsService;
35 private boolean enableMonitor = false; 37 private boolean enableMonitor = false;
36 38
39 + // define a ControlMetricsSystemSpec
40 + private ControlMetricsSystemSpec cmss;
41 +
37 // define a set of MetricsAggregators 42 // define a set of MetricsAggregators
38 - private MetricsAggregator cpuInfoMetric; 43 + private MetricsAggregator cpuLoad;
39 - private MetricsAggregator memoryInfoMetric; 44 + private MetricsAggregator totalCpuTime;
40 - private Map<DeviceId, MetricsAggregator> inboundPacketMetrics; 45 + private MetricsAggregator sysCpuTime;
41 - private Map<DeviceId, MetricsAggregator> outboundPacketMetrics; 46 + private MetricsAggregator userCpuTime;
42 - private Map<DeviceId, MetricsAggregator> flowmodPacketMetrics; 47 + private MetricsAggregator cpuIdleTime;
43 - private Map<DeviceId, MetricsAggregator> flowrmvPacketMetrics; 48 + private MetricsAggregator memoryUsed;
44 - private Map<DeviceId, MetricsAggregator> requestPacketMetrics; 49 + private MetricsAggregator memoryFree;
45 - private Map<DeviceId, MetricsAggregator> replyPacketMetrics; 50 + private MetricsAggregator memoryUsedPercentage;
46 - private Set<DeviceId> deviceIds = new HashSet<>(); 51 + private MetricsAggregator memoryFreePercentage;
52 + private Map<String, MetricsAggregator> diskReadBytes;
53 + private Map<String, MetricsAggregator> diskWriteBytes;
54 + private Map<String, MetricsAggregator> nwIncomingBytes;
55 + private Map<String, MetricsAggregator> nwOutgoingBytes;
56 + private Map<String, MetricsAggregator> nwIncomingPackets;
57 + private Map<String, MetricsAggregator> nwOutgoingPackets;
58 +
59 + private Map<DeviceId, MetricsAggregator> inboundPacket;
60 + private Map<DeviceId, MetricsAggregator> outboundPacket;
61 + private Map<DeviceId, MetricsAggregator> flowmodPacket;
62 + private Map<DeviceId, MetricsAggregator> flowrmvPacket;
63 + private Map<DeviceId, MetricsAggregator> requestPacket;
64 + private Map<DeviceId, MetricsAggregator> replyPacket;
65 + private Set<DeviceId> deviceIds = Sets.newConcurrentHashSet();
66 + private Set<String> diskPartitions = Sets.newConcurrentHashSet();
67 + private Set<String> nwInterfaces = Sets.newConcurrentHashSet();
47 68
48 private ControlMetricsFactory(MetricsService metricsService, DeviceService deviceService) { 69 private ControlMetricsFactory(MetricsService metricsService, DeviceService deviceService) {
49 this.metricsService = metricsService; 70 this.metricsService = metricsService;
...@@ -51,7 +72,7 @@ public final class ControlMetricsFactory { ...@@ -51,7 +72,7 @@ public final class ControlMetricsFactory {
51 72
52 deviceService.getDevices().forEach(d->deviceIds.add(d.id())); 73 deviceService.getDevices().forEach(d->deviceIds.add(d.id()));
53 74
54 - addAllDeviceMetrics(deviceIds); 75 + addAllControlMessageMetrics(deviceIds);
55 } 76 }
56 77
57 public static ControlMetricsFactory getInstance(MetricsService metricsService, 78 public static ControlMetricsFactory getInstance(MetricsService metricsService,
...@@ -67,11 +88,22 @@ public final class ControlMetricsFactory { ...@@ -67,11 +88,22 @@ public final class ControlMetricsFactory {
67 } 88 }
68 89
69 /** 90 /**
91 + * Sets system specification.
92 + *
93 + * @param cmss ControlMetricsSystemSpec object
94 + */
95 + public void setSystemSpec(ControlMetricsSystemSpec cmss) {
96 + if (this.cmss == null) {
97 + this.cmss = cmss;
98 + }
99 + }
100 +
101 + /**
70 * Adds control metrics of a new device. 102 * Adds control metrics of a new device.
71 * 103 *
72 * @param deviceId {@link org.onosproject.net.DeviceId} 104 * @param deviceId {@link org.onosproject.net.DeviceId}
73 */ 105 */
74 - public void addMetricsByDeviceId(DeviceId deviceId) { 106 + public void addControlMessageMetricsByDeviceId(DeviceId deviceId) {
75 MetricsAggregator inbound = new MetricsAggregator(metricsService, 107 MetricsAggregator inbound = new MetricsAggregator(metricsService,
76 ControlMetricType.INBOUND_PACKET, Optional.of(deviceId)); 108 ControlMetricType.INBOUND_PACKET, Optional.of(deviceId));
77 MetricsAggregator outbound = new MetricsAggregator(metricsService, 109 MetricsAggregator outbound = new MetricsAggregator(metricsService,
...@@ -85,34 +117,123 @@ public final class ControlMetricsFactory { ...@@ -85,34 +117,123 @@ public final class ControlMetricsFactory {
85 MetricsAggregator reply = new MetricsAggregator(metricsService, 117 MetricsAggregator reply = new MetricsAggregator(metricsService,
86 ControlMetricType.REPLY_PACKET, Optional.of(deviceId)); 118 ControlMetricType.REPLY_PACKET, Optional.of(deviceId));
87 119
88 - inboundPacketMetrics.putIfAbsent(deviceId, inbound); 120 + inboundPacket.putIfAbsent(deviceId, inbound);
89 - outboundPacketMetrics.putIfAbsent(deviceId, outbound); 121 + outboundPacket.putIfAbsent(deviceId, outbound);
90 - flowmodPacketMetrics.putIfAbsent(deviceId, flowmod); 122 + flowmodPacket.putIfAbsent(deviceId, flowmod);
91 - flowrmvPacketMetrics.putIfAbsent(deviceId, flowrmv); 123 + flowrmvPacket.putIfAbsent(deviceId, flowrmv);
92 - requestPacketMetrics.putIfAbsent(deviceId, request); 124 + requestPacket.putIfAbsent(deviceId, request);
93 - replyPacketMetrics.putIfAbsent(deviceId, reply); 125 + replyPacket.putIfAbsent(deviceId, reply);
94 126
95 deviceIds.add(deviceId); 127 deviceIds.add(deviceId);
96 } 128 }
97 129
98 /** 130 /**
131 + * Adds control metrics of a disk.
132 + *
133 + * @param partitionName disk partition name
134 + */
135 + public void addDiskMetricsByPartition(String partitionName) {
136 + MetricsAggregator readBytes = new MetricsAggregator(metricsService,
137 + ControlMetricType.DISK_READ_BYTES, partitionName);
138 + MetricsAggregator writeBytes = new MetricsAggregator(metricsService,
139 + ControlMetricType.DISK_WRITE_BYTES, partitionName);
140 +
141 + diskReadBytes.putIfAbsent(partitionName, readBytes);
142 + diskWriteBytes.putIfAbsent(partitionName, writeBytes);
143 +
144 + diskPartitions.add(partitionName);
145 + }
146 +
147 + /**
148 + * Adds control metrics of a ethernet interface.
149 + *
150 + * @param interfaceName network interface name
151 + */
152 + public void addNetworkMetricsByInterface(String interfaceName) {
153 + MetricsAggregator incomingBytes = new MetricsAggregator(metricsService,
154 + ControlMetricType.NW_INCOMING_BYTES, interfaceName);
155 + MetricsAggregator outgoingBytes = new MetricsAggregator(metricsService,
156 + ControlMetricType.NW_OUTGOING_BYTES, interfaceName);
157 + MetricsAggregator incomingPackets = new MetricsAggregator(metricsService,
158 + ControlMetricType.NW_INCOMING_PACKETS, interfaceName);
159 + MetricsAggregator outgoingPackets = new MetricsAggregator(metricsService,
160 + ControlMetricType.NW_OUTGOING_PACKETS, interfaceName);
161 +
162 + nwIncomingBytes.putIfAbsent(interfaceName, incomingBytes);
163 + nwOutgoingBytes.putIfAbsent(interfaceName, outgoingBytes);
164 + nwIncomingPackets.putIfAbsent(interfaceName, incomingPackets);
165 + nwOutgoingPackets.putIfAbsent(interfaceName, outgoingPackets);
166 +
167 + nwInterfaces.add(interfaceName);
168 + }
169 +
170 + /**
99 * Removes control metrics of an existing device. 171 * Removes control metrics of an existing device.
100 * 172 *
101 * @param deviceId {@link org.onosproject.net.DeviceId} 173 * @param deviceId {@link org.onosproject.net.DeviceId}
102 */ 174 */
103 - public void removeMetricsByDeviceId(DeviceId deviceId) { 175 + public void removeControlMessageMetricsByDeviceId(DeviceId deviceId) {
104 - inboundPacketMetrics.remove(deviceId); 176 + inboundPacket.remove(deviceId);
105 - outboundPacketMetrics.remove(deviceId); 177 + outboundPacket.remove(deviceId);
106 - flowmodPacketMetrics.remove(deviceId); 178 + flowmodPacket.remove(deviceId);
107 - flowrmvPacketMetrics.remove(deviceId); 179 + flowrmvPacket.remove(deviceId);
108 - requestPacketMetrics.remove(deviceId); 180 + requestPacket.remove(deviceId);
109 - replyPacketMetrics.remove(deviceId); 181 + replyPacket.remove(deviceId);
110 182
111 deviceIds.remove(deviceId); 183 deviceIds.remove(deviceId);
112 } 184 }
113 185
186 + /**
187 + * Removes control metrics of a disk.
188 + *
189 + * @param partitionName disk partition name
190 + */
191 + public void removeDiskMetricsByResourceName(String partitionName) {
192 + diskReadBytes.remove(partitionName);
193 + diskWriteBytes.remove(partitionName);
194 +
195 + diskPartitions.remove(partitionName);
196 + }
197 +
198 + /**
199 + * Removes control metrics of a network interface.
200 + *
201 + * @param interfaceName network interface name
202 + */
203 + public void removeNetworkInterfacesByResourceName(String interfaceName) {
204 + nwIncomingBytes.remove(interfaceName);
205 + nwOutgoingBytes.remove(interfaceName);
206 + nwIncomingPackets.remove(interfaceName);
207 + nwOutgoingPackets.remove(interfaceName);
208 +
209 + nwInterfaces.remove(interfaceName);
210 + }
211 +
212 + /**
213 + * Returns all device ids.
214 + *
215 + * @return a collection of device id
216 + */
114 public Set<DeviceId> getDeviceIds() { 217 public Set<DeviceId> getDeviceIds() {
115 - return this.deviceIds; 218 + return ImmutableSet.copyOf(this.deviceIds);
219 + }
220 +
221 + /**
222 + * Returns all disk partition names.
223 + *
224 + * @return a collection of disk partition.
225 + */
226 + public Set<String> getDiskPartitions() {
227 + return ImmutableSet.copyOf(this.diskPartitions);
228 + }
229 +
230 + /**
231 + * Returns all network interface names.
232 + *
233 + * @return a collection of network interface.
234 + */
235 + public Set<String> getNetworkInterfaces() {
236 + return ImmutableSet.copyOf(this.nwInterfaces);
116 } 237 }
117 238
118 /** 239 /**
...@@ -120,8 +241,8 @@ public final class ControlMetricsFactory { ...@@ -120,8 +241,8 @@ public final class ControlMetricsFactory {
120 * 241 *
121 * @param deviceIds a set of deviceIds 242 * @param deviceIds a set of deviceIds
122 */ 243 */
123 - public void addAllDeviceMetrics(Set<DeviceId> deviceIds) { 244 + public void addAllControlMessageMetrics(Set<DeviceId> deviceIds) {
124 - deviceIds.forEach(v -> addMetricsByDeviceId(v)); 245 + deviceIds.forEach(v -> addControlMessageMetricsByDeviceId(v));
125 } 246 }
126 247
127 /** 248 /**
...@@ -151,87 +272,160 @@ public final class ControlMetricsFactory { ...@@ -151,87 +272,160 @@ public final class ControlMetricsFactory {
151 * Registers new control metrics. 272 * Registers new control metrics.
152 */ 273 */
153 protected void registerMetrics() { 274 protected void registerMetrics() {
154 - cpuInfoMetric = new MetricsAggregator(metricsService, 275 + /* CPU */
155 - ControlMetricType.CPU_INFO, Optional.ofNullable(null)); 276 + cpuLoad = new MetricsAggregator(metricsService, ControlMetricType.CPU_LOAD);
156 - memoryInfoMetric = new MetricsAggregator(metricsService, 277 + totalCpuTime = new MetricsAggregator(metricsService, ControlMetricType.TOTAL_CPU_TIME);
157 - ControlMetricType.MEMORY_INFO, Optional.ofNullable(null)); 278 + sysCpuTime = new MetricsAggregator(metricsService, ControlMetricType.SYS_CPU_TIME);
158 - 279 + userCpuTime = new MetricsAggregator(metricsService, ControlMetricType.USER_CPU_TIME);
159 - inboundPacketMetrics = new ConcurrentHashMap<>(); 280 + cpuIdleTime = new MetricsAggregator(metricsService, ControlMetricType.CPU_IDLE_TIME);
160 - outboundPacketMetrics = new ConcurrentHashMap<>(); 281 +
161 - flowmodPacketMetrics = new ConcurrentHashMap<>(); 282 + /* Memory */
162 - flowrmvPacketMetrics = new ConcurrentHashMap<>(); 283 + memoryFree = new MetricsAggregator(metricsService, ControlMetricType.MEMORY_FREE);
163 - requestPacketMetrics = new ConcurrentHashMap<>(); 284 + memoryUsed = new MetricsAggregator(metricsService, ControlMetricType.MEMORY_USED);
164 - replyPacketMetrics = new ConcurrentHashMap<>(); 285 + memoryFreePercentage = new MetricsAggregator(metricsService,
286 + ControlMetricType.MEMORY_FREE_PERCENTAGE);
287 + memoryUsedPercentage = new MetricsAggregator(metricsService,
288 + ControlMetricType.MEMORY_USED_PERCENTAGE);
289 +
290 + /* Disk I/O */
291 + diskReadBytes = new ConcurrentHashMap<>();
292 + diskWriteBytes = new ConcurrentHashMap<>();
293 +
294 + /* Network I/O */
295 + nwIncomingBytes = new ConcurrentHashMap<>();
296 + nwOutgoingBytes = new ConcurrentHashMap<>();
297 + nwIncomingPackets = new ConcurrentHashMap<>();
298 + nwOutgoingPackets = new ConcurrentHashMap<>();
299 +
300 + /* OpenFlow Messages */
301 + inboundPacket = new ConcurrentHashMap<>();
302 + outboundPacket = new ConcurrentHashMap<>();
303 + flowmodPacket = new ConcurrentHashMap<>();
304 + flowrmvPacket = new ConcurrentHashMap<>();
305 + requestPacket = new ConcurrentHashMap<>();
306 + replyPacket = new ConcurrentHashMap<>();
165 } 307 }
166 308
167 /** 309 /**
168 * Unregisters all control metrics. 310 * Unregisters all control metrics.
169 */ 311 */
170 protected void unregisterMetrics() { 312 protected void unregisterMetrics() {
171 - cpuInfoMetric.removeMetrics(); 313 + /* Disk I/O */
172 - memoryInfoMetric.removeMetrics(); 314 + diskReadBytes.clear();
315 + diskWriteBytes.clear();
316 +
317 + /* Network I/O */
318 + nwIncomingBytes.clear();
319 + nwOutgoingBytes.clear();
320 + nwIncomingPackets.clear();
321 + nwOutgoingPackets.clear();
322 +
323 + /* OpenFlow Message */
324 + inboundPacket.clear();
325 + outboundPacket.clear();
326 + flowmodPacket.clear();
327 + flowrmvPacket.clear();
328 + requestPacket.clear();
329 + replyPacket.clear();
330 + }
331 +
332 + public MetricsAggregator cpuLoadMetric() {
333 + return cpuLoad;
334 + }
335 +
336 + public MetricsAggregator totalCpuTimeMetric() {
337 + return totalCpuTime;
338 + }
339 +
340 + public MetricsAggregator sysCpuTimeMetric() {
341 + return sysCpuTime;
342 + }
343 +
344 + public MetricsAggregator userCpuTime() {
345 + return userCpuTime;
346 + }
347 +
348 + public MetricsAggregator cpuIdleTime() {
349 + return cpuIdleTime;
350 + }
351 +
352 + public MetricsAggregator memoryFreePercentage() {
353 + return memoryFreePercentage;
354 + }
355 +
356 + public MetricsAggregator memoryUsedPercentage() {
357 + return memoryUsedPercentage;
358 + }
359 +
360 + public MetricsAggregator diskReadBytes(String partitionName) {
361 + return diskReadBytes.get(partitionName);
362 + }
363 +
364 + public MetricsAggregator diskWriteBytes(String partitionName) {
365 + return diskWriteBytes.get(partitionName);
366 + }
367 +
368 + public MetricsAggregator nwIncomingBytes(String interfaceName) {
369 + return nwIncomingBytes.get(interfaceName);
370 + }
173 371
174 - inboundPacketMetrics.clear(); 372 + public MetricsAggregator nwOutgoingBytes(String interfaceName) {
175 - outboundPacketMetrics.clear(); 373 + return nwOutgoingBytes.get(interfaceName);
176 - flowmodPacketMetrics.clear();
177 - flowrmvPacketMetrics.clear();
178 - requestPacketMetrics.clear();
179 - replyPacketMetrics.clear();
180 } 374 }
181 375
182 - public MetricsAggregator cpuInfoMetric() { 376 + public MetricsAggregator nwIncomingPackets(String interfaceName) {
183 - return cpuInfoMetric; 377 + return nwIncomingPackets.get(interfaceName);
184 } 378 }
185 379
186 - public MetricsAggregator memoryInfoMetric() { 380 + public MetricsAggregator nwOutgoingPackets(String interfaceName) {
187 - return memoryInfoMetric; 381 + return nwOutgoingPackets.get(interfaceName);
188 } 382 }
189 383
190 - public Map<DeviceId, MetricsAggregator> inboundPacketMetrics() { 384 + public Map<DeviceId, MetricsAggregator> inboundPacket() {
191 - return inboundPacketMetrics; 385 + return ImmutableMap.copyOf(inboundPacket);
192 } 386 }
193 387
194 - public Map<DeviceId, MetricsAggregator> outboundPacketMetrics() { 388 + public Map<DeviceId, MetricsAggregator> outboundPacket() {
195 - return outboundPacketMetrics; 389 + return ImmutableMap.copyOf(outboundPacket);
196 } 390 }
197 391
198 - public Map<DeviceId, MetricsAggregator> flowmodPacketMetrics() { 392 + public Map<DeviceId, MetricsAggregator> flowmodPacket() {
199 - return flowmodPacketMetrics; 393 + return ImmutableMap.copyOf(flowmodPacket);
200 } 394 }
201 395
202 - public Map<DeviceId, MetricsAggregator> flowrmvPacketMetrics() { 396 + public Map<DeviceId, MetricsAggregator> flowrmvPacket() {
203 - return flowrmvPacketMetrics; 397 + return ImmutableMap.copyOf(flowrmvPacket);
204 } 398 }
205 399
206 - public Map<DeviceId, MetricsAggregator> requestPacketMetrics() { 400 + public Map<DeviceId, MetricsAggregator> requestPacket() {
207 - return requestPacketMetrics; 401 + return ImmutableMap.copyOf(requestPacket);
208 } 402 }
209 403
210 - public Map<DeviceId, MetricsAggregator> replyPacketMetrics() { 404 + public Map<DeviceId, MetricsAggregator> replyPacket() {
211 - return replyPacketMetrics; 405 + return ImmutableMap.copyOf(replyPacket);
212 } 406 }
213 407
214 - public MetricsAggregator inboundPacketMetrics(DeviceId deviceId) { 408 + public MetricsAggregator inboundPacket(DeviceId deviceId) {
215 - return inboundPacketMetrics.get(deviceId); 409 + return inboundPacket.get(deviceId);
216 } 410 }
217 411
218 - public MetricsAggregator outboundPacketMetrics(DeviceId deviceId) { 412 + public MetricsAggregator outboundPacket(DeviceId deviceId) {
219 - return outboundPacketMetrics.get(deviceId); 413 + return outboundPacket.get(deviceId);
220 } 414 }
221 415
222 - public MetricsAggregator flowmodPacketMetrics(DeviceId deviceId) { 416 + public MetricsAggregator flowmodPacket(DeviceId deviceId) {
223 - return flowmodPacketMetrics.get(deviceId); 417 + return flowmodPacket.get(deviceId);
224 } 418 }
225 419
226 - public MetricsAggregator flowrmvPacketMetrics(DeviceId deviceId) { 420 + public MetricsAggregator flowrmvPacket(DeviceId deviceId) {
227 - return flowrmvPacketMetrics.get(deviceId); 421 + return flowrmvPacket.get(deviceId);
228 } 422 }
229 423
230 - public MetricsAggregator requestPacketMetrics(DeviceId deviceId) { 424 + public MetricsAggregator requestPacket(DeviceId deviceId) {
231 - return requestPacketMetrics.get(deviceId); 425 + return requestPacket.get(deviceId);
232 } 426 }
233 427
234 - public MetricsAggregator replyPacketMetrics(DeviceId deviceId) { 428 + public MetricsAggregator replyPacket(DeviceId deviceId) {
235 - return replyPacketMetrics.get(deviceId); 429 + return replyPacket.get(deviceId);
236 } 430 }
237 } 431 }
...\ No newline at end of file ...\ No newline at end of file
......
1 /* 1 /*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015-2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -31,4 +31,12 @@ public interface ControlMetricsObserver { ...@@ -31,4 +31,12 @@ public interface ControlMetricsObserver {
31 * @param deviceId device id {@link org.onosproject.net.DeviceId} 31 * @param deviceId device id {@link org.onosproject.net.DeviceId}
32 */ 32 */
33 void feedMetrics(MetricsAggregator metricsAggregator, Optional<DeviceId> deviceId); 33 void feedMetrics(MetricsAggregator metricsAggregator, Optional<DeviceId> deviceId);
34 +
35 + /**
36 + * Feeds the extracted value from MetricAggregator to back-end storage.
37 + *
38 + * @param metricsAggregator metric aggregator
39 + * @param resourceName resource name
40 + */
41 + void feedMetrics(MetricsAggregator metricsAggregator, String resourceName);
34 } 42 }
......
1 +/*
2 + * Copyright 2016 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.cpman;
17 +
18 +/**
19 + * Control metrics class for storing system specification.
20 + */
21 +public final class ControlMetricsSystemSpec {
22 + private int numOfCores;
23 + private int numOfCpus;
24 + private int cpuSpeed; // in MHz
25 + private long totalMemory; // in bytes
26 +
27 + private ControlMetricsSystemSpec(int numOfCores, int numOfCpus,
28 + int cpuSpeed, long totalMemory) {
29 + this.numOfCores = numOfCores;
30 + this.numOfCpus = numOfCpus;
31 + this.cpuSpeed = cpuSpeed;
32 + this.totalMemory = totalMemory;
33 + }
34 +
35 + /**
36 + * Returns number of CPU cores.
37 + *
38 + * @return number of CPU cores
39 + */
40 + public int numOfCores() {
41 + return this.numOfCores;
42 + }
43 +
44 + /**
45 + * Returns number of CPUs.
46 + *
47 + * @return number of CPUs
48 + */
49 + public int numOfCpus() {
50 + return this.numOfCpus;
51 + }
52 +
53 + /**
54 + * Returns CPU speed in MHz.
55 + *
56 + * @return CPU speed
57 + */
58 + public int cpuSpeed() {
59 + return this.cpuSpeed;
60 + }
61 +
62 + /**
63 + * Returns the total amount of memory.
64 + *
65 + * @return memory size
66 + */
67 + public long totalMemory() {
68 + return this.totalMemory;
69 + }
70 +
71 + /**
72 + * ControlMetricsSystemSpec builder class.
73 + */
74 + public static final class Builder {
75 + private int numOfCores;
76 + private int numOfCpus;
77 + private int cpuSpeed; // in MHz
78 + private long totalMemory; // in bytes
79 +
80 + /**
81 + * Sets number of CPU cores.
82 + *
83 + * @param numOfCores number of CPU cores
84 + * @return Builder object
85 + */
86 + public Builder numOfCores(int numOfCores) {
87 + this.numOfCores = numOfCores;
88 + return this;
89 + }
90 +
91 + /**
92 + * Sets number of CPUs.
93 + * @param numOfCpus number of CPUs
94 + * @return Builder object
95 + */
96 + public Builder numOfCpus(int numOfCpus) {
97 + this.numOfCpus = numOfCpus;
98 + return this;
99 + }
100 +
101 + /**
102 + * Sets CPU speed.
103 + *
104 + * @param cpuSpeed CPU speed
105 + * @return Builder object
106 + */
107 + public Builder cpuSpeed(int cpuSpeed) {
108 + this.cpuSpeed = cpuSpeed;
109 + return this;
110 + }
111 +
112 + /**
113 + * Sets total amount of memory.
114 + *
115 + * @param totalMemory memory size
116 + * @return Builder object
117 + */
118 + public Builder totalMemory(long totalMemory) {
119 + this.totalMemory = totalMemory;
120 + return this;
121 + }
122 +
123 + /**
124 + * Builds a ControlMetricsSystemSpec object.
125 + *
126 + * @return ControlMetricsSystemSpec object
127 + */
128 + public ControlMetricsSystemSpec build() {
129 + return new ControlMetricsSystemSpec(numOfCores, numOfCpus, cpuSpeed, totalMemory);
130 + }
131 + }
132 +}
1 /* 1 /*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015-2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -95,18 +95,18 @@ public class ControlPlaneManager { ...@@ -95,18 +95,18 @@ public class ControlPlaneManager {
95 if (cmf.isMonitor()) { 95 if (cmf.isMonitor()) {
96 controlMetricsObservers.forEach(observer -> { 96 controlMetricsObservers.forEach(observer -> {
97 97
98 - // try to feed the CPU and memory stats 98 + // only OpenFlow messages are spontaneously monitored with
99 - observer.feedMetrics(cmf.cpuInfoMetric(), Optional.ofNullable(null)); 99 + // 1 minute period. Other system metrics will be pushed from
100 - observer.feedMetrics(cmf.memoryInfoMetric(), Optional.ofNullable(null)); 100 + // external monitoring agent through REST API
101 101
102 - // try to feed the control message stats 102 + // feed the control message stats
103 cmf.getDeviceIds().forEach(v -> { 103 cmf.getDeviceIds().forEach(v -> {
104 - observer.feedMetrics(cmf.inboundPacketMetrics(v), Optional.of(v)); 104 + observer.feedMetrics(cmf.inboundPacket(v), Optional.of(v));
105 - observer.feedMetrics(cmf.outboundPacketMetrics(v), Optional.of(v)); 105 + observer.feedMetrics(cmf.outboundPacket(v), Optional.of(v));
106 - observer.feedMetrics(cmf.flowmodPacketMetrics(v), Optional.of(v)); 106 + observer.feedMetrics(cmf.flowmodPacket(v), Optional.of(v));
107 - observer.feedMetrics(cmf.flowrmvPacketMetrics(v), Optional.of(v)); 107 + observer.feedMetrics(cmf.flowrmvPacket(v), Optional.of(v));
108 - observer.feedMetrics(cmf.requestPacketMetrics(v), Optional.of(v)); 108 + observer.feedMetrics(cmf.requestPacket(v), Optional.of(v));
109 - observer.feedMetrics(cmf.replyPacketMetrics(v), Optional.of(v)); 109 + observer.feedMetrics(cmf.replyPacket(v), Optional.of(v));
110 }); 110 });
111 }); 111 });
112 } 112 }
......
1 /* 1 /*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015-2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -57,6 +57,12 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService { ...@@ -57,6 +57,12 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService {
57 } 57 }
58 58
59 @Override 59 @Override
60 + public void updateMetric(ControlMetric controlMetric, int updateInterval,
61 + String resourceName) {
62 +
63 + }
64 +
65 + @Override
60 public ControlLoad getLoad(NodeId nodeId, ControlMetricType type, 66 public ControlLoad getLoad(NodeId nodeId, ControlMetricType type,
61 Optional<DeviceId> deviceId) { 67 Optional<DeviceId> deviceId) {
62 return null; 68 return null;
......
1 /* 1 /*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015-2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -36,6 +36,15 @@ public interface ControlPlaneMonitorService { ...@@ -36,6 +36,15 @@ public interface ControlPlaneMonitorService {
36 void updateMetric(ControlMetric controlMetric, int updateInterval, Optional<DeviceId> deviceId); 36 void updateMetric(ControlMetric controlMetric, int updateInterval, Optional<DeviceId> deviceId);
37 37
38 /** 38 /**
39 + * Adds a new control metric value with a certain update interval.
40 + *
41 + * @param controlMetric control plane metric (e.g., disk and network metrics)
42 + * @param updateInterval value update interval (time unit will be in minute)
43 + * @param resourceName resource name
44 + */
45 + void updateMetric(ControlMetric controlMetric, int updateInterval, String resourceName);
46 +
47 + /**
39 * Obtains the control plane load of a specific device. 48 * Obtains the control plane load of a specific device.
40 * 49 *
41 * @param nodeId node id {@link org.onosproject.cluster.NodeId} 50 * @param nodeId node id {@link org.onosproject.cluster.NodeId}
......
1 /* 1 /*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015-2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -32,7 +32,14 @@ public class DefaultControlMetricsObserver implements ControlMetricsObserver { ...@@ -32,7 +32,14 @@ public class DefaultControlMetricsObserver implements ControlMetricsObserver {
32 @Override 32 @Override
33 public void feedMetrics(MetricsAggregator ma, Optional<DeviceId> deviceId) { 33 public void feedMetrics(MetricsAggregator ma, Optional<DeviceId> deviceId) {
34 MetricValue mv = new MetricValue((long) ma.getRate(), (long) ma.getLoad(), (long) ma.getCount()); 34 MetricValue mv = new MetricValue((long) ma.getRate(), (long) ma.getLoad(), (long) ma.getCount());
35 - ControlMetric cpm = new ControlMetric(ma.getMetricsType(), mv); 35 + ControlMetric cm = new ControlMetric(ma.getMetricsType(), mv);
36 - controlPlaneMonitorService.updateMetric(cpm, 1, deviceId); 36 + controlPlaneMonitorService.updateMetric(cm, 1, deviceId);
37 + }
38 +
39 + @Override
40 + public void feedMetrics(MetricsAggregator ma, String resourceName) {
41 + MetricValue mv = new MetricValue((long) ma.getRate(), (long) ma.getLoad(), (long) ma.getCount());
42 + ControlMetric cm = new ControlMetric(ma.getMetricsType(), mv);
43 + controlPlaneMonitorService.updateMetric(cm, 1, resourceName);
37 } 44 }
38 } 45 }
...\ No newline at end of file ...\ No newline at end of file
......
1 /* 1 /*
2 - * Copyright 2015 Open Networking Laboratory 2 + * Copyright 2015-2016 Open Networking Laboratory
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.cpman; 16 package org.onosproject.cpman;
17 17
18 import com.codahale.metrics.Meter; 18 import com.codahale.metrics.Meter;
19 +import org.apache.commons.lang3.StringUtils;
19 import org.onlab.metrics.MetricsComponent; 20 import org.onlab.metrics.MetricsComponent;
20 import org.onlab.metrics.MetricsFeature; 21 import org.onlab.metrics.MetricsFeature;
21 import org.onlab.metrics.MetricsService; 22 import org.onlab.metrics.MetricsService;
...@@ -49,13 +50,58 @@ public class MetricsAggregator { ...@@ -49,13 +50,58 @@ public class MetricsAggregator {
49 * @param type Control metric type 50 * @param type Control metric type
50 * @param deviceId DeviceId 51 * @param deviceId DeviceId
51 */ 52 */
52 - MetricsAggregator(MetricsService metricsService, ControlMetricType type, Optional<DeviceId> deviceId) { 53 + MetricsAggregator(MetricsService metricsService, ControlMetricType type,
54 + Optional<DeviceId> deviceId) {
55 + init(metricsService, type, deviceId, null);
56 + }
57 +
58 + /**
59 + * Constructs a new MetricAggregator for aggregating a metric.
60 + * Instantiates the metrics service
61 + * Initializes all the general metrics for that object
62 + *
63 + * @param metricsService MetricsService reference
64 + * @param type Control metric type
65 + * @param resourceName resource name (e.g., ethernet interface name)
66 + */
67 + MetricsAggregator(MetricsService metricsService, ControlMetricType type,
68 + String resourceName) {
69 + init(metricsService, type, Optional.ofNullable(null), resourceName);
70 +
71 + }
72 +
73 + /**
74 + * Constructs a new MetricAggregator for aggregating a metric.
75 + * Instantiates the metrics service
76 + * Initializes all the general metrics for that object
77 + *
78 + * @param metricsService MetricsService reference
79 + * @param type Control metric type
80 + */
81 + MetricsAggregator(MetricsService metricsService, ControlMetricType type) {
82 + init(metricsService, type, Optional.ofNullable(null), null);
83 + }
84 +
85 + /**
86 + * Base method of the constructor of this class.
87 + *
88 + * @param metricsService MetricsService reference
89 + * @param type Control metric type
90 + * @param deviceId DeviceId
91 + * @param resourceName resource name
92 + */
93 + private void init(MetricsService metricsService, ControlMetricType type,
94 + Optional<DeviceId> deviceId, String resourceName) {
53 String primitiveName = type.toString(); 95 String primitiveName = type.toString();
54 String objName = "all"; 96 String objName = "all";
55 if (deviceId.isPresent()) { 97 if (deviceId.isPresent()) {
56 objName = deviceId.toString(); 98 objName = deviceId.toString();
57 } 99 }
58 100
101 + if (StringUtils.isNotEmpty(resourceName)) {
102 + objName = resourceName;
103 + }
104 +
59 checkNotNull(primitiveName, "Component name cannot be null"); 105 checkNotNull(primitiveName, "Component name cannot be null");
60 checkNotNull(objName, "Feature name cannot be null"); 106 checkNotNull(objName, "Feature name cannot be null");
61 107
...@@ -74,14 +120,6 @@ public class MetricsAggregator { ...@@ -74,14 +120,6 @@ public class MetricsAggregator {
74 } 120 }
75 121
76 /** 122 /**
77 - * Removes both rate and count metrics.
78 - */
79 - protected void removeMetrics() {
80 - metricsService.removeMetric(metricsComponent, metricsFeature, RATE_NAME);
81 - metricsService.removeMetric(metricsComponent, metricsFeature, COUNT_NAME);
82 - }
83 -
84 - /**
85 * Increments the meter rate by {@code n}, and the meter counter by 1. 123 * Increments the meter rate by {@code n}, and the meter counter by 1.
86 * 124 *
87 * @param n Increment the meter rate by {@code n}. 125 * @param n Increment the meter rate by {@code n}.
......