blob: efb0213a0650a07d3b0f30436f7effa22d90280a [file] [log] [blame]
Ray Milkey26921af2014-06-30 16:27:40 -07001package net.onrc.onos.core.metrics;
2
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;
9import org.codehaus.jackson.map.annotate.JsonSerialize;
10
11import java.util.List;
12
13/**
14 * Resource class to hold Metrics information. Timers, Gauges, Counters,
15 * Meters and Historgrams are currently implemented.
16 */
17@JsonSerialize(using = MetricsObjectSerializer.class)
18@SuppressWarnings("rawtypes")
19public class MetricsObjectResource {
20
21 /**
22 * Base Metric object that all metrics inherit from. Defines common
23 * attributes.
24 */
25 static class BaseMetricObject {
26 private final String name;
27
28 /**
29 * Constructor for the base object. Sets the name attribute.
30 *
31 * @param newName name of the Metric
32 */
33 protected BaseMetricObject(final String newName) {
34 name = newName;
35 }
36
37 /**
38 * Get the name of the Metric.
39 *
40 * @return metric name
41 */
42 public String getName() {
43 return name;
44 }
45 }
46
47 /**
48 * Metric object that represents a Timer.
49 */
50 static class TimerObjectResource extends BaseMetricObject {
51 private final Timer timer;
52
53 /**
54 * Construct a new Timer resource object.
55 *
56 * @param newName name to use for the timer
57 * @param newTimer Metrics Timer object
58 */
59 public TimerObjectResource(final String newName,
60 final Timer newTimer) {
61 super(newName);
62 timer = newTimer;
63 }
64
65 /**
66 * Get the Metrics Timer object for this resource.
67 *
68 * @return Metrics Timer object.
69 */
70 public Timer getTimer() {
71 return timer;
72 }
73 }
74
75 /**
76 * Metric object that represents a Gauge.
77 */
78 static class GaugeObjectResource extends BaseMetricObject {
79 private final Gauge gauge;
80
81 /**
82 * Constructs a new Gauge resource object.
83 *
84 * @param newName name to use for the Gauge object
85 * @param newGauge Metrics Gauge object
86 */
87 public GaugeObjectResource(final String newName,
88 final Gauge newGauge) {
89 super(newName);
90 gauge = newGauge;
91 }
92
93 /**
94 * Gets the Metrics Gauge object for this resource.
95 *
96 * @return Metrics Gauge object.
97 */
98 public Gauge getGauge() {
99 return gauge;
100 }
101 }
102
103 /**
104 * Metric object that represents a Counter.
105 */
106 static class CounterObjectResource extends BaseMetricObject {
107 private final Counter counter;
108
109 /**
110 * Constructs a new Counter resource object.
111 *
112 * @param newName name to use for the Counter object
113 * @param newCounter Metrics Counter object
114 */
115 public CounterObjectResource(final String newName,
116 final Counter newCounter) {
117 super(newName);
118 counter = newCounter;
119 }
120
121 /**
122 * Gets the Metrics Counter object for this resource.
123 *
124 * @return Metrics Counter object.
125 */
126 public Counter getCounter() {
127 return counter;
128 }
129 }
130
131 /**
132 * Metric object that represents a Meter.
133 */
134 static class MeterObjectResource extends BaseMetricObject {
135 private final Meter meter;
136
137 /**
138 * Constructs a new Meter resource object.
139 *
140 * @param newName name to use for the Meter object
141 * @param newMeter Metrics Meter object
142 */
143 public MeterObjectResource(final String newName,
144 final Meter newMeter) {
145 super(newName);
146 meter = newMeter;
147 }
148
149 /**
150 * Gets the Metrics Meter object for this resource.
151 *
152 * @return Metrics Meter object.
153 */
154 public Meter getMeter() {
155 return meter;
156 }
157 }
158
159 /**
160 * Metric objerct that represents a Histogram.
161 */
162 static class HistogramObjectResource extends BaseMetricObject {
163 private final Histogram histogram;
164
165 /**
166 * Constructs a new Histogram resource object.
167 *
168 * @param newName name to use for Histogram object.
169 * @param newHistogram Metrics Histogram object.
170 */
171 public HistogramObjectResource(final String newName,
172 final Histogram newHistogram) {
173 super(newName);
174 histogram = newHistogram;
175 }
176
177 /**
178 * Gets the Metrics Histogram object for this resource.
179 *
180 * @return Metrics Histogram Object
181 */
182 public Histogram getHistogram() {
183 return histogram;
184 }
185 }
186
187
188 private List<TimerObjectResource> timers;
189 private List<GaugeObjectResource> gauges;
190 private List<CounterObjectResource> counters;
191 private List<MeterObjectResource> meters;
192 private List<HistogramObjectResource> histograms;
193
194 /**
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}