blob: 9e9dfa047a674754905079365e571ae7e8892849 [file] [log] [blame]
pankaj390abbc2014-10-01 17:01:05 -07001package org.onlab.metrics;
2
3import java.util.Map;
4
5import com.codahale.metrics.Counter;
6import com.codahale.metrics.Gauge;
7import com.codahale.metrics.Histogram;
8import com.codahale.metrics.Meter;
9import com.codahale.metrics.Metric;
10import com.codahale.metrics.MetricFilter;
11import com.codahale.metrics.Timer;
12
13/**
14 * Metrics Service to collect metrics.
15 */
Pavlin Radoslavov35592492014-10-21 21:49:58 -070016public interface MetricsService {
pankaj390abbc2014-10-01 17:01:05 -070017
18 /**
19 * Registers a component.
20 *
21 * @param name name of the Component to register
22 * @return MetricsComponent object that can be used to create Metrics.
23 */
24 MetricsComponent registerComponent(String name);
25
26 /**
27 * Creates a Counter metric.
28 *
29 * @param component component the Counter is defined in
30 * @param feature feature the Counter is defined in
31 * @param metricName local name of the metric
32 * @return the created Counter Meteric
33 */
34 Counter createCounter(MetricsComponent component,
35 MetricsFeature feature,
36 String metricName);
37
38 /**
39 * Creates a Histogram metric.
40 *
41 * @param component component the Histogram is defined in
42 * @param feature feature the Histogram is defined in
43 * @param metricName local name of the metric
44 * @return the created Histogram Metric
45 */
46 Histogram createHistogram(MetricsComponent component,
47 MetricsFeature feature,
48 String metricName);
49
50 /**
51 * Creates a Timer metric.
52 *
53 * @param component component the Timer is defined in
54 * @param feature feature the Timer is defined in
55 * @param metricName local name of the metric
56 * @return the created Timer Metric
57 */
58 Timer createTimer(MetricsComponent component,
59 MetricsFeature feature,
60 String metricName);
61
pankaja17630a2014-10-01 18:19:37 -070062 /**
63 * Creates a Meter metric.
64 *
65 * @param component component the Meter is defined in
66 * @param feature feature the Meter is defined in
67 * @param metricName local name of the metric
68 * @return the created Meter Metric
69 */
pankaj3855bcb2014-10-01 18:17:31 -070070 Meter createMeter(MetricsComponent component,
71 MetricsFeature feature,
72 String metricName);
73
pankaj390abbc2014-10-01 17:01:05 -070074 /**
75 * Registers an already created Metric. This is used for situation where a
76 * caller needs to allocate its own Metric, but still register it with the
77 * system.
78 *
79 * @param <T> Metric type
80 * @param component component the Metric is defined in
81 * @param feature feature the Metric is defined in
82 * @param metricName local name of the metric
83 * @param metric Metric to register
84 * @return the registered Metric
85 */
86 <T extends Metric> T registerMetric(
87 MetricsComponent component,
88 MetricsFeature feature,
89 String metricName,
90 T metric);
91
92 /**
Pavlin Radoslavov35592492014-10-21 21:49:58 -070093 * Removes the metric with the given name.
94 *
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 * @return true if the metric existed and was removed, otherwise false
99 */
100 boolean removeMetric(MetricsComponent component,
101 MetricsFeature feature,
102 String metricName);
103
104 /**
pankaj390abbc2014-10-01 17:01:05 -0700105 * Fetches the existing Timers.
106 *
107 * @param filter filter to use to select Timers
108 * @return a map of the Timers that match the filter, with the key as the
109 * name String to the Timer.
110 */
111 Map<String, Timer> getTimers(MetricFilter filter);
112
113 /**
114 * Fetches the existing Gauges.
115 *
116 * @param filter filter to use to select Gauges
117 * @return a map of the Gauges that match the filter, with the key as the
118 * name String to the Gauge.
119 */
120 Map<String, Gauge> getGauges(MetricFilter filter);
121
122 /**
123 * Fetches the existing Counters.
124 *
125 * @param filter filter to use to select Counters
126 * @return a map of the Counters that match the filter, with the key as the
127 * name String to the Counter.
128 */
129 Map<String, Counter> getCounters(MetricFilter filter);
130
131 /**
132 * Fetches the existing Meters.
133 *
134 * @param filter filter to use to select Meters
135 * @return a map of the Meters that match the filter, with the key as the
136 * name String to the Meter.
137 */
138 Map<String, Meter> getMeters(MetricFilter filter);
139
140 /**
141 * Fetches the existing Histograms.
142 *
143 * @param filter filter to use to select Histograms
Pavlin Radoslavov35592492014-10-21 21:49:58 -0700144 * @return a map of the Histograms that match the filter, with the key as
145 * the name String to the Histogram.
pankaj390abbc2014-10-01 17:01:05 -0700146 */
147 Map<String, Histogram> getHistograms(MetricFilter filter);
Pavlin Radoslavov35592492014-10-21 21:49:58 -0700148
pankaj390abbc2014-10-01 17:01:05 -0700149 /**
150 * Removes all Metrics that match a given filter.
151 *
152 * @param filter filter to use to select the Metrics to remove.
153 */
154 void removeMatching(MetricFilter filter);
pankaj390abbc2014-10-01 17:01:05 -0700155}