blob: 7688da649635b9a0ee5c1201fde7837a93ef64e4 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska24c849c2014-10-27 09:53:05 -070015 */
pankaj390abbc2014-10-01 17:01:05 -070016package org.onlab.metrics;
17
18import java.util.Map;
19
20import com.codahale.metrics.Counter;
21import com.codahale.metrics.Gauge;
22import com.codahale.metrics.Histogram;
23import com.codahale.metrics.Meter;
24import com.codahale.metrics.Metric;
25import com.codahale.metrics.MetricFilter;
Jian Li7261c7b2016-03-05 00:04:55 -080026import com.codahale.metrics.MetricRegistry;
pankaj390abbc2014-10-01 17:01:05 -070027import com.codahale.metrics.Timer;
28
29/**
30 * Metrics Service to collect metrics.
31 */
Pavlin Radoslavov35592492014-10-21 21:49:58 -070032public interface MetricsService {
pankaj390abbc2014-10-01 17:01:05 -070033
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 Li7261c7b2016-03-05 00:04:55 -080043 * Fetches existing metric registry.
44 *
45 * @return metric registry
46 */
47 MetricRegistry getMetricRegistry();
48
49 /**
pankaj390abbc2014-10-01 17:01:05 -070050 * 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
pankaja17630a2014-10-01 18:19:37 -070085 /**
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 */
pankaj3855bcb2014-10-01 18:17:31 -070093 Meter createMeter(MetricsComponent component,
94 MetricsFeature feature,
95 String metricName);
96
pankaj390abbc2014-10-01 17:01:05 -070097 /**
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 /**
Pavlin Radoslavov35592492014-10-21 21:49:58 -0700116 * Removes the metric with the given name.
117 *
118 * @param component component the Metric is defined in
119 * @param feature feature the Metric is defined in
120 * @param metricName local name of the metric
121 * @return true if the metric existed and was removed, otherwise false
122 */
123 boolean removeMetric(MetricsComponent component,
124 MetricsFeature feature,
125 String metricName);
126
127 /**
pankaj390abbc2014-10-01 17:01:05 -0700128 * Fetches the existing Timers.
129 *
130 * @param filter filter to use to select Timers
131 * @return a map of the Timers that match the filter, with the key as the
132 * name String to the Timer.
133 */
134 Map<String, Timer> getTimers(MetricFilter filter);
135
136 /**
137 * Fetches the existing Gauges.
138 *
139 * @param filter filter to use to select Gauges
140 * @return a map of the Gauges that match the filter, with the key as the
141 * name String to the Gauge.
142 */
143 Map<String, Gauge> getGauges(MetricFilter filter);
144
145 /**
146 * Fetches the existing Counters.
147 *
148 * @param filter filter to use to select Counters
149 * @return a map of the Counters that match the filter, with the key as the
150 * name String to the Counter.
151 */
152 Map<String, Counter> getCounters(MetricFilter filter);
153
154 /**
155 * Fetches the existing Meters.
156 *
157 * @param filter filter to use to select Meters
158 * @return a map of the Meters that match the filter, with the key as the
159 * name String to the Meter.
160 */
161 Map<String, Meter> getMeters(MetricFilter filter);
162
163 /**
164 * Fetches the existing Histograms.
165 *
166 * @param filter filter to use to select Histograms
Pavlin Radoslavov35592492014-10-21 21:49:58 -0700167 * @return a map of the Histograms that match the filter, with the key as
168 * the name String to the Histogram.
pankaj390abbc2014-10-01 17:01:05 -0700169 */
170 Map<String, Histogram> getHistograms(MetricFilter filter);
Pavlin Radoslavov35592492014-10-21 21:49:58 -0700171
pankaj390abbc2014-10-01 17:01:05 -0700172 /**
Flavio Castro4b519412015-07-24 12:57:59 -0700173 * Fetches the existing metrics.
174 *
175 * @return a map of the Metrics, with the key as
176 * the name String to the Histogram.
177 */
178 Map<String, Metric> getMetrics();
179
180 /**
pankaj390abbc2014-10-01 17:01:05 -0700181 * Removes all Metrics that match a given filter.
182 *
183 * @param filter filter to use to select the Metrics to remove.
184 */
185 void removeMatching(MetricFilter filter);
pankaj390abbc2014-10-01 17:01:05 -0700186}