Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
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; |
| 26 | import com.codahale.metrics.Timer; |
| 27 | |
| 28 | /** |
| 29 | * Metrics Service to collect metrics. |
| 30 | */ |
Pavlin Radoslavov | 3559249 | 2014-10-21 21:49:58 -0700 | [diff] [blame] | 31 | public interface MetricsService { |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * Registers a component. |
| 35 | * |
| 36 | * @param name name of the Component to register |
| 37 | * @return MetricsComponent object that can be used to create Metrics. |
| 38 | */ |
| 39 | MetricsComponent registerComponent(String name); |
| 40 | |
| 41 | /** |
| 42 | * Creates a Counter metric. |
| 43 | * |
| 44 | * @param component component the Counter is defined in |
| 45 | * @param feature feature the Counter is defined in |
| 46 | * @param metricName local name of the metric |
| 47 | * @return the created Counter Meteric |
| 48 | */ |
| 49 | Counter createCounter(MetricsComponent component, |
| 50 | MetricsFeature feature, |
| 51 | String metricName); |
| 52 | |
| 53 | /** |
| 54 | * Creates a Histogram metric. |
| 55 | * |
| 56 | * @param component component the Histogram is defined in |
| 57 | * @param feature feature the Histogram is defined in |
| 58 | * @param metricName local name of the metric |
| 59 | * @return the created Histogram Metric |
| 60 | */ |
| 61 | Histogram createHistogram(MetricsComponent component, |
| 62 | MetricsFeature feature, |
| 63 | String metricName); |
| 64 | |
| 65 | /** |
| 66 | * Creates a Timer metric. |
| 67 | * |
| 68 | * @param component component the Timer is defined in |
| 69 | * @param feature feature the Timer is defined in |
| 70 | * @param metricName local name of the metric |
| 71 | * @return the created Timer Metric |
| 72 | */ |
| 73 | Timer createTimer(MetricsComponent component, |
| 74 | MetricsFeature feature, |
| 75 | String metricName); |
| 76 | |
pankaj | a17630a | 2014-10-01 18:19:37 -0700 | [diff] [blame] | 77 | /** |
| 78 | * Creates a Meter metric. |
| 79 | * |
| 80 | * @param component component the Meter is defined in |
| 81 | * @param feature feature the Meter is defined in |
| 82 | * @param metricName local name of the metric |
| 83 | * @return the created Meter Metric |
| 84 | */ |
pankaj | 3855bcb | 2014-10-01 18:17:31 -0700 | [diff] [blame] | 85 | Meter createMeter(MetricsComponent component, |
| 86 | MetricsFeature feature, |
| 87 | String metricName); |
| 88 | |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 89 | /** |
| 90 | * Registers an already created Metric. This is used for situation where a |
| 91 | * caller needs to allocate its own Metric, but still register it with the |
| 92 | * system. |
| 93 | * |
| 94 | * @param <T> Metric type |
| 95 | * @param component component the Metric is defined in |
| 96 | * @param feature feature the Metric is defined in |
| 97 | * @param metricName local name of the metric |
| 98 | * @param metric Metric to register |
| 99 | * @return the registered Metric |
| 100 | */ |
| 101 | <T extends Metric> T registerMetric( |
| 102 | MetricsComponent component, |
| 103 | MetricsFeature feature, |
| 104 | String metricName, |
| 105 | T metric); |
| 106 | |
| 107 | /** |
Pavlin Radoslavov | 3559249 | 2014-10-21 21:49:58 -0700 | [diff] [blame] | 108 | * Removes the metric with the given name. |
| 109 | * |
| 110 | * @param component component the Metric is defined in |
| 111 | * @param feature feature the Metric is defined in |
| 112 | * @param metricName local name of the metric |
| 113 | * @return true if the metric existed and was removed, otherwise false |
| 114 | */ |
| 115 | boolean removeMetric(MetricsComponent component, |
| 116 | MetricsFeature feature, |
| 117 | String metricName); |
| 118 | |
| 119 | /** |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 120 | * Fetches the existing Timers. |
| 121 | * |
| 122 | * @param filter filter to use to select Timers |
| 123 | * @return a map of the Timers that match the filter, with the key as the |
| 124 | * name String to the Timer. |
| 125 | */ |
| 126 | Map<String, Timer> getTimers(MetricFilter filter); |
| 127 | |
| 128 | /** |
| 129 | * Fetches the existing Gauges. |
| 130 | * |
| 131 | * @param filter filter to use to select Gauges |
| 132 | * @return a map of the Gauges that match the filter, with the key as the |
| 133 | * name String to the Gauge. |
| 134 | */ |
| 135 | Map<String, Gauge> getGauges(MetricFilter filter); |
| 136 | |
| 137 | /** |
| 138 | * Fetches the existing Counters. |
| 139 | * |
| 140 | * @param filter filter to use to select Counters |
| 141 | * @return a map of the Counters that match the filter, with the key as the |
| 142 | * name String to the Counter. |
| 143 | */ |
| 144 | Map<String, Counter> getCounters(MetricFilter filter); |
| 145 | |
| 146 | /** |
| 147 | * Fetches the existing Meters. |
| 148 | * |
| 149 | * @param filter filter to use to select Meters |
| 150 | * @return a map of the Meters that match the filter, with the key as the |
| 151 | * name String to the Meter. |
| 152 | */ |
| 153 | Map<String, Meter> getMeters(MetricFilter filter); |
| 154 | |
| 155 | /** |
| 156 | * Fetches the existing Histograms. |
| 157 | * |
| 158 | * @param filter filter to use to select Histograms |
Pavlin Radoslavov | 3559249 | 2014-10-21 21:49:58 -0700 | [diff] [blame] | 159 | * @return a map of the Histograms that match the filter, with the key as |
| 160 | * the name String to the Histogram. |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 161 | */ |
| 162 | Map<String, Histogram> getHistograms(MetricFilter filter); |
Pavlin Radoslavov | 3559249 | 2014-10-21 21:49:58 -0700 | [diff] [blame] | 163 | |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 164 | /** |
| 165 | * Removes all Metrics that match a given filter. |
| 166 | * |
| 167 | * @param filter filter to use to select the Metrics to remove. |
| 168 | */ |
| 169 | void removeMatching(MetricFilter filter); |
pankaj | 390abbc | 2014-10-01 17:01:05 -0700 | [diff] [blame] | 170 | } |