blob: bf4e4c246613c7e013813ecc31a2898233291386 [file] [log] [blame]
Ray Milkeya34ed042014-07-17 16:19:52 -07001package net.onrc.onos.core.metrics.web;
Ray Milkey26921af2014-06-30 16:27:40 -07002
3
4import com.codahale.metrics.Counter;
5import com.codahale.metrics.Gauge;
6import com.codahale.metrics.Meter;
7import com.codahale.metrics.Timer;
8import com.codahale.metrics.Histogram;
Ray Milkeya34ed042014-07-17 16:19:52 -07009import net.onrc.onos.core.metrics.web.serializers.MetricsObjectSerializer;
Ray Milkey26921af2014-06-30 16:27:40 -070010import org.codehaus.jackson.map.annotate.JsonSerialize;
11
12import java.util.List;
13
14/**
15 * Resource class to hold Metrics information. Timers, Gauges, Counters,
16 * Meters and Historgrams are currently implemented.
17 */
18@JsonSerialize(using = MetricsObjectSerializer.class)
19@SuppressWarnings("rawtypes")
20public class MetricsObjectResource {
21
Ray Milkey40eb9c82014-07-18 10:28:11 -070022 private List<TimerObjectResource> timers;
23 private List<GaugeObjectResource> gauges;
24 private List<CounterObjectResource> counters;
25 private List<MeterObjectResource> meters;
26 private List<HistogramObjectResource> histograms;
27
Ray Milkey26921af2014-06-30 16:27:40 -070028 /**
29 * Base Metric object that all metrics inherit from. Defines common
30 * attributes.
31 */
Ray Milkeya34ed042014-07-17 16:19:52 -070032 public static class BaseMetricObject {
Ray Milkey26921af2014-06-30 16:27:40 -070033 private final String name;
34
35 /**
36 * Constructor for the base object. Sets the name attribute.
37 *
38 * @param newName name of the Metric
39 */
40 protected BaseMetricObject(final String newName) {
41 name = newName;
42 }
43
44 /**
45 * Get the name of the Metric.
46 *
47 * @return metric name
48 */
49 public String getName() {
50 return name;
51 }
52 }
53
54 /**
55 * Metric object that represents a Timer.
56 */
Ray Milkeya34ed042014-07-17 16:19:52 -070057 public static class TimerObjectResource extends BaseMetricObject {
Ray Milkey26921af2014-06-30 16:27:40 -070058 private final Timer timer;
59
60 /**
61 * Construct a new Timer resource object.
62 *
63 * @param newName name to use for the timer
64 * @param newTimer Metrics Timer object
65 */
66 public TimerObjectResource(final String newName,
67 final Timer newTimer) {
68 super(newName);
69 timer = newTimer;
70 }
71
72 /**
73 * Get the Metrics Timer object for this resource.
74 *
75 * @return Metrics Timer object.
76 */
77 public Timer getTimer() {
78 return timer;
79 }
80 }
81
82 /**
83 * Metric object that represents a Gauge.
84 */
Ray Milkeya34ed042014-07-17 16:19:52 -070085 public static class GaugeObjectResource extends BaseMetricObject {
Ray Milkey26921af2014-06-30 16:27:40 -070086 private final Gauge gauge;
87
88 /**
89 * Constructs a new Gauge resource object.
90 *
91 * @param newName name to use for the Gauge object
92 * @param newGauge Metrics Gauge object
93 */
94 public GaugeObjectResource(final String newName,
95 final Gauge newGauge) {
96 super(newName);
97 gauge = newGauge;
98 }
99
100 /**
101 * Gets the Metrics Gauge object for this resource.
102 *
103 * @return Metrics Gauge object.
104 */
105 public Gauge getGauge() {
106 return gauge;
107 }
108 }
109
110 /**
111 * Metric object that represents a Counter.
112 */
Ray Milkeya34ed042014-07-17 16:19:52 -0700113 public static class CounterObjectResource extends BaseMetricObject {
Ray Milkey26921af2014-06-30 16:27:40 -0700114 private final Counter counter;
115
116 /**
117 * Constructs a new Counter resource object.
118 *
119 * @param newName name to use for the Counter object
120 * @param newCounter Metrics Counter object
121 */
122 public CounterObjectResource(final String newName,
123 final Counter newCounter) {
124 super(newName);
125 counter = newCounter;
126 }
127
128 /**
129 * Gets the Metrics Counter object for this resource.
130 *
131 * @return Metrics Counter object.
132 */
133 public Counter getCounter() {
134 return counter;
135 }
136 }
137
138 /**
139 * Metric object that represents a Meter.
140 */
Ray Milkeya34ed042014-07-17 16:19:52 -0700141 public static class MeterObjectResource extends BaseMetricObject {
Ray Milkey26921af2014-06-30 16:27:40 -0700142 private final Meter meter;
143
144 /**
145 * Constructs a new Meter resource object.
146 *
147 * @param newName name to use for the Meter object
148 * @param newMeter Metrics Meter object
149 */
150 public MeterObjectResource(final String newName,
151 final Meter newMeter) {
152 super(newName);
153 meter = newMeter;
154 }
155
156 /**
157 * Gets the Metrics Meter object for this resource.
158 *
159 * @return Metrics Meter object.
160 */
161 public Meter getMeter() {
162 return meter;
163 }
164 }
165
166 /**
167 * Metric objerct that represents a Histogram.
168 */
Ray Milkeya34ed042014-07-17 16:19:52 -0700169 public static class HistogramObjectResource extends BaseMetricObject {
Ray Milkey26921af2014-06-30 16:27:40 -0700170 private final Histogram histogram;
171
172 /**
173 * Constructs a new Histogram resource object.
174 *
175 * @param newName name to use for Histogram object.
176 * @param newHistogram Metrics Histogram object.
177 */
178 public HistogramObjectResource(final String newName,
179 final Histogram newHistogram) {
180 super(newName);
181 histogram = newHistogram;
182 }
183
184 /**
185 * Gets the Metrics Histogram object for this resource.
186 *
187 * @return Metrics Histogram Object
188 */
189 public Histogram getHistogram() {
190 return histogram;
191 }
192 }
193
Ray Milkey26921af2014-06-30 16:27:40 -0700194 /**
195 * Gets the list of Gauge objects.
196 *
197 * @return list of gauges
198 */
199 public List<GaugeObjectResource> getGauges() {
200 return gauges;
201 }
202
203 /**
204 * Defines the list of Gauge objects.
205 *
206 * @param gauges list of gauges
207 */
208 public void setGauges(List<GaugeObjectResource> gauges) {
209 this.gauges = gauges;
210 }
211
212 /**
213 * Gets the list of Timer objects.
214 *
215 * @return list of Timers
216 */
217 public List<TimerObjectResource> getTimers() {
218 return timers;
219 }
220
221 /**
222 * Defines the list of Timer objects.
223 *
224 * @param newTimers list of Timers
225 */
226 public void setTimers(List<TimerObjectResource> newTimers) {
227 timers = newTimers;
228 }
229
230 /**
231 * Gets the list of Counter objects.
232 *
233 * @return list of Counters
234 */
235 public List<CounterObjectResource> getCounters() {
236 return counters;
237 }
238
239 /**
240 * Defines the list of Counter objects.
241 *
242 * @param counters list of Counters
243 */
244 public void setCounters(List<CounterObjectResource> counters) {
245 this.counters = counters;
246 }
247
248 /**
249 * Gets the list of Meter objects.
250 *
251 * @return list of Meters
252 */
253 public List<MeterObjectResource> getMeters() {
254 return meters;
255 }
256
257 /**
258 * Defines the list of Meter objects.
259 *
260 * @param meters list of Meters
261 */
262 public void setMeters(List<MeterObjectResource> meters) {
263 this.meters = meters;
264 }
265
266 /**
267 * Gets the list of Histogram objects.
268 *
269 * @return list of Histograms
270 */
271 public List<HistogramObjectResource> getHistograms() {
272 return histograms;
273 }
274
275 /**
276 * Defines the list of Histogram objects.
277 *
278 * @param histograms list of Histograms.
279 */
280 public void setHistograms(List<HistogramObjectResource> histograms) {
281 this.histograms = histograms;
282 }
283}