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
Showing
10 changed files
with
290 additions
and
40 deletions
| ... | @@ -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 | } | ... | ... |
This diff is collapsed. Click to expand it.
| 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}. | ... | ... |
-
Please register or login to post a comment