blob: d2e8723105413db4bd8638b09bc5bd8a72f29458 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
pankaj390abbc2014-10-01 17:01:05 -070019package org.onlab.metrics;
20
21import java.util.Map;
22
23import com.codahale.metrics.Counter;
24import com.codahale.metrics.Gauge;
25import com.codahale.metrics.Histogram;
26import com.codahale.metrics.Meter;
27import com.codahale.metrics.Metric;
28import com.codahale.metrics.MetricFilter;
29import com.codahale.metrics.Timer;
30
31/**
32 * Metrics Service to collect metrics.
33 */
Pavlin Radoslavov35592492014-10-21 21:49:58 -070034public interface MetricsService {
pankaj390abbc2014-10-01 17:01:05 -070035
36 /**
37 * Registers a component.
38 *
39 * @param name name of the Component to register
40 * @return MetricsComponent object that can be used to create Metrics.
41 */
42 MetricsComponent registerComponent(String name);
43
44 /**
45 * Creates a Counter metric.
46 *
47 * @param component component the Counter is defined in
48 * @param feature feature the Counter is defined in
49 * @param metricName local name of the metric
50 * @return the created Counter Meteric
51 */
52 Counter createCounter(MetricsComponent component,
53 MetricsFeature feature,
54 String metricName);
55
56 /**
57 * Creates a Histogram metric.
58 *
59 * @param component component the Histogram is defined in
60 * @param feature feature the Histogram is defined in
61 * @param metricName local name of the metric
62 * @return the created Histogram Metric
63 */
64 Histogram createHistogram(MetricsComponent component,
65 MetricsFeature feature,
66 String metricName);
67
68 /**
69 * Creates a Timer metric.
70 *
71 * @param component component the Timer is defined in
72 * @param feature feature the Timer is defined in
73 * @param metricName local name of the metric
74 * @return the created Timer Metric
75 */
76 Timer createTimer(MetricsComponent component,
77 MetricsFeature feature,
78 String metricName);
79
pankaja17630a2014-10-01 18:19:37 -070080 /**
81 * Creates a Meter metric.
82 *
83 * @param component component the Meter is defined in
84 * @param feature feature the Meter is defined in
85 * @param metricName local name of the metric
86 * @return the created Meter Metric
87 */
pankaj3855bcb2014-10-01 18:17:31 -070088 Meter createMeter(MetricsComponent component,
89 MetricsFeature feature,
90 String metricName);
91
pankaj390abbc2014-10-01 17:01:05 -070092 /**
93 * Registers an already created Metric. This is used for situation where a
94 * caller needs to allocate its own Metric, but still register it with the
95 * system.
96 *
97 * @param <T> Metric type
98 * @param component component the Metric is defined in
99 * @param feature feature the Metric is defined in
100 * @param metricName local name of the metric
101 * @param metric Metric to register
102 * @return the registered Metric
103 */
104 <T extends Metric> T registerMetric(
105 MetricsComponent component,
106 MetricsFeature feature,
107 String metricName,
108 T metric);
109
110 /**
Pavlin Radoslavov35592492014-10-21 21:49:58 -0700111 * Removes the metric with the given name.
112 *
113 * @param component component the Metric is defined in
114 * @param feature feature the Metric is defined in
115 * @param metricName local name of the metric
116 * @return true if the metric existed and was removed, otherwise false
117 */
118 boolean removeMetric(MetricsComponent component,
119 MetricsFeature feature,
120 String metricName);
121
122 /**
pankaj390abbc2014-10-01 17:01:05 -0700123 * Fetches the existing Timers.
124 *
125 * @param filter filter to use to select Timers
126 * @return a map of the Timers that match the filter, with the key as the
127 * name String to the Timer.
128 */
129 Map<String, Timer> getTimers(MetricFilter filter);
130
131 /**
132 * Fetches the existing Gauges.
133 *
134 * @param filter filter to use to select Gauges
135 * @return a map of the Gauges that match the filter, with the key as the
136 * name String to the Gauge.
137 */
138 Map<String, Gauge> getGauges(MetricFilter filter);
139
140 /**
141 * Fetches the existing Counters.
142 *
143 * @param filter filter to use to select Counters
144 * @return a map of the Counters that match the filter, with the key as the
145 * name String to the Counter.
146 */
147 Map<String, Counter> getCounters(MetricFilter filter);
148
149 /**
150 * Fetches the existing Meters.
151 *
152 * @param filter filter to use to select Meters
153 * @return a map of the Meters that match the filter, with the key as the
154 * name String to the Meter.
155 */
156 Map<String, Meter> getMeters(MetricFilter filter);
157
158 /**
159 * Fetches the existing Histograms.
160 *
161 * @param filter filter to use to select Histograms
Pavlin Radoslavov35592492014-10-21 21:49:58 -0700162 * @return a map of the Histograms that match the filter, with the key as
163 * the name String to the Histogram.
pankaj390abbc2014-10-01 17:01:05 -0700164 */
165 Map<String, Histogram> getHistograms(MetricFilter filter);
Pavlin Radoslavov35592492014-10-21 21:49:58 -0700166
pankaj390abbc2014-10-01 17:01:05 -0700167 /**
168 * Removes all Metrics that match a given filter.
169 *
170 * @param filter filter to use to select the Metrics to remove.
171 */
172 void removeMatching(MetricFilter filter);
pankaj390abbc2014-10-01 17:01:05 -0700173}