Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 15 | */ |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 16 | package org.onlab.metrics; |
| 17 | |
| 18 | import java.util.Map; |
| 19 | |
| 20 | import com.codahale.metrics.Counter; |
| 21 | import com.codahale.metrics.Gauge; |
| 22 | import com.codahale.metrics.Histogram; |
| 23 | import com.codahale.metrics.Meter; |
| 24 | import com.codahale.metrics.Metric; |
| 25 | import com.codahale.metrics.MetricFilter; |
Jian Li | 7261c7b | 2016-03-05 00:04:55 -0800 | [diff] [blame] | 26 | import com.codahale.metrics.MetricRegistry; |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 27 | import com.codahale.metrics.Timer; |
| 28 | |
| 29 | /** |
| 30 | * Metrics Service to collect metrics. |
| 31 | */ |
Pavlin Radoslavov | 3559249 | 2014-10-21 21:49:58 -0700 | [diff] [blame] | 32 | public interface MetricsService { |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Registers a component. |
| 36 | * |
| 37 | * @param name name of the Component to register |
| 38 | * @return MetricsComponent object that can be used to create Metrics. |
| 39 | */ |
| 40 | MetricsComponent registerComponent(String name); |
| 41 | |
| 42 | /** |
Jian Li | 7261c7b | 2016-03-05 00:04:55 -0800 | [diff] [blame] | 43 | * Fetches existing metric registry. |
| 44 | * |
| 45 | * @return metric registry |
| 46 | */ |
| 47 | MetricRegistry getMetricRegistry(); |
| 48 | |
| 49 | /** |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 50 | * Creates a Counter metric. |
| 51 | * |
| 52 | * @param component component the Counter is defined in |
| 53 | * @param feature feature the Counter is defined in |
| 54 | * @param metricName local name of the metric |
| 55 | * @return the created Counter Meteric |
| 56 | */ |
| 57 | Counter createCounter(MetricsComponent component, |
| 58 | MetricsFeature feature, |
| 59 | String metricName); |
| 60 | |
| 61 | /** |
| 62 | * Creates a Histogram metric. |
| 63 | * |
| 64 | * @param component component the Histogram is defined in |
| 65 | * @param feature feature the Histogram is defined in |
| 66 | * @param metricName local name of the metric |
| 67 | * @return the created Histogram Metric |
| 68 | */ |
| 69 | Histogram createHistogram(MetricsComponent component, |
| 70 | MetricsFeature feature, |
| 71 | String metricName); |
| 72 | |
| 73 | /** |
| 74 | * Creates a Timer metric. |
| 75 | * |
| 76 | * @param component component the Timer is defined in |
| 77 | * @param feature feature the Timer is defined in |
| 78 | * @param metricName local name of the metric |
| 79 | * @return the created Timer Metric |
| 80 | */ |
| 81 | Timer createTimer(MetricsComponent component, |
| 82 | MetricsFeature feature, |
| 83 | String metricName); |
| 84 | |
pankaj | a17630a | 2014-10-01 18:19:37 -0700 | [diff] [blame] | 85 | /** |
| 86 | * Creates a Meter metric. |
| 87 | * |
| 88 | * @param component component the Meter is defined in |
| 89 | * @param feature feature the Meter is defined in |
| 90 | * @param metricName local name of the metric |
| 91 | * @return the created Meter Metric |
| 92 | */ |
pankaj | 3855bcb | 2014-10-01 18:17:31 -0700 | [diff] [blame] | 93 | Meter createMeter(MetricsComponent component, |
| 94 | MetricsFeature feature, |
| 95 | String metricName); |
| 96 | |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 97 | /** |
| 98 | * Registers an already created Metric. This is used for situation where a |
| 99 | * caller needs to allocate its own Metric, but still register it with the |
| 100 | * system. |
| 101 | * |
| 102 | * @param <T> Metric type |
| 103 | * @param component component the Metric is defined in |
| 104 | * @param feature feature the Metric is defined in |
| 105 | * @param metricName local name of the metric |
| 106 | * @param metric Metric to register |
| 107 | * @return the registered Metric |
| 108 | */ |
| 109 | <T extends Metric> T registerMetric( |
| 110 | MetricsComponent component, |
| 111 | MetricsFeature feature, |
| 112 | String metricName, |
| 113 | T metric); |
| 114 | |
| 115 | /** |
Jian Li | 55cbd5c | 2016-04-06 09:50:20 -0700 | [diff] [blame] | 116 | * Registers a reporter to receive any changes on metric registry. |
| 117 | * |
| 118 | * @param reporter metric reporter |
| 119 | */ |
| 120 | void registerReporter(MetricsReporter reporter); |
| 121 | |
| 122 | /** |
| 123 | * Unregisters the given metric reporter. |
| 124 | * |
| 125 | * @param reporter metric reporter |
| 126 | */ |
| 127 | void unregisterReporter(MetricsReporter reporter); |
| 128 | |
| 129 | /** |
| 130 | * Notifies the changes on metric registry to all registered reporters. |
| 131 | */ |
| 132 | void notifyReporters(); |
| 133 | |
| 134 | /** |
Pavlin Radoslavov | 3559249 | 2014-10-21 21:49:58 -0700 | [diff] [blame] | 135 | * Removes the metric with the given name. |
| 136 | * |
| 137 | * @param component component the Metric is defined in |
| 138 | * @param feature feature the Metric is defined in |
| 139 | * @param metricName local name of the metric |
| 140 | * @return true if the metric existed and was removed, otherwise false |
| 141 | */ |
| 142 | boolean removeMetric(MetricsComponent component, |
| 143 | MetricsFeature feature, |
| 144 | String metricName); |
| 145 | |
| 146 | /** |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 147 | * Fetches the existing Timers. |
| 148 | * |
| 149 | * @param filter filter to use to select Timers |
| 150 | * @return a map of the Timers that match the filter, with the key as the |
| 151 | * name String to the Timer. |
| 152 | */ |
| 153 | Map<String, Timer> getTimers(MetricFilter filter); |
| 154 | |
| 155 | /** |
| 156 | * Fetches the existing Gauges. |
| 157 | * |
| 158 | * @param filter filter to use to select Gauges |
| 159 | * @return a map of the Gauges that match the filter, with the key as the |
| 160 | * name String to the Gauge. |
| 161 | */ |
| 162 | Map<String, Gauge> getGauges(MetricFilter filter); |
| 163 | |
| 164 | /** |
| 165 | * Fetches the existing Counters. |
| 166 | * |
| 167 | * @param filter filter to use to select Counters |
| 168 | * @return a map of the Counters that match the filter, with the key as the |
| 169 | * name String to the Counter. |
| 170 | */ |
| 171 | Map<String, Counter> getCounters(MetricFilter filter); |
| 172 | |
| 173 | /** |
| 174 | * Fetches the existing Meters. |
| 175 | * |
| 176 | * @param filter filter to use to select Meters |
| 177 | * @return a map of the Meters that match the filter, with the key as the |
| 178 | * name String to the Meter. |
| 179 | */ |
| 180 | Map<String, Meter> getMeters(MetricFilter filter); |
| 181 | |
| 182 | /** |
| 183 | * Fetches the existing Histograms. |
| 184 | * |
| 185 | * @param filter filter to use to select Histograms |
Pavlin Radoslavov | 3559249 | 2014-10-21 21:49:58 -0700 | [diff] [blame] | 186 | * @return a map of the Histograms that match the filter, with the key as |
| 187 | * the name String to the Histogram. |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 188 | */ |
| 189 | Map<String, Histogram> getHistograms(MetricFilter filter); |
Pavlin Radoslavov | 3559249 | 2014-10-21 21:49:58 -0700 | [diff] [blame] | 190 | |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 191 | /** |
Flavio Castro | 4b51941 | 2015-07-24 12:57:59 -0700 | [diff] [blame] | 192 | * Fetches the existing metrics. |
| 193 | * |
| 194 | * @return a map of the Metrics, with the key as |
| 195 | * the name String to the Histogram. |
| 196 | */ |
| 197 | Map<String, Metric> getMetrics(); |
| 198 | |
| 199 | /** |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 200 | * Removes all Metrics that match a given filter. |
| 201 | * |
| 202 | * @param filter filter to use to select the Metrics to remove. |
| 203 | */ |
| 204 | void removeMatching(MetricFilter filter); |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 205 | } |