blob: 54a9d689a3f1bd2356f19beabbad7cab23436c47 [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;
26import com.codahale.metrics.Timer;
27
28/**
29 * Metrics Service to collect metrics.
30 */
Pavlin Radoslavov35592492014-10-21 21:49:58 -070031public interface MetricsService {
pankaj390abbc2014-10-01 17:01:05 -070032
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
pankaja17630a2014-10-01 18:19:37 -070077 /**
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 */
pankaj3855bcb2014-10-01 18:17:31 -070085 Meter createMeter(MetricsComponent component,
86 MetricsFeature feature,
87 String metricName);
88
pankaj390abbc2014-10-01 17:01:05 -070089 /**
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 Radoslavov35592492014-10-21 21:49:58 -0700108 * 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 /**
pankaj390abbc2014-10-01 17:01:05 -0700120 * 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 Radoslavov35592492014-10-21 21:49:58 -0700159 * @return a map of the Histograms that match the filter, with the key as
160 * the name String to the Histogram.
pankaj390abbc2014-10-01 17:01:05 -0700161 */
162 Map<String, Histogram> getHistograms(MetricFilter filter);
Pavlin Radoslavov35592492014-10-21 21:49:58 -0700163
pankaj390abbc2014-10-01 17:01:05 -0700164 /**
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);
pankaj390abbc2014-10-01 17:01:05 -0700170}