1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.objectledge.statistics;
29
30 import java.math.BigDecimal;
31
32 import org.jcontainer.dna.Configuration;
33 import org.jcontainer.dna.ConfigurationException;
34
35 /***
36 * Describes a data source used for statistics computation, modeled after Munin tool.
37 *
38 * @author <a href="mailto:rafal@caltha.pl">Rafal Krzewski</a>
39 * @version $Id: DataSource.java,v 1.7 2005/05/16 09:51:55 rafal Exp $
40 */
41 public class DataSource
42 {
43 private final String name;
44
45 private final String label;
46
47 private final String cdef;
48
49 private final Type type;
50
51 private final Graph graph;
52
53 private final Number min;
54
55 private final Number max;
56
57 private final Number minWarning;
58
59 private final Number maxWarning;
60
61 private final Number minCritical;
62
63 private final Number maxCritical;
64
65 /***
66 * Creates new ValueDescription instance.
67 *
68 * @param name the name of the data source.
69 * @param label the data source label.
70 * @param cdef the data transformation RPN expression.
71 * @param type the data source type.
72 * @param graph the graph type for the data source.
73 * @param min minimal cutoff value (lesser values will be discarded), null to disable.
74 * @param max maximal cutoff value (greater values will be discarded), null to disable.
75 * @param minWarning the minimal warning value, null to disable.
76 * @param maxWarning the maximal warning value, null to disable.
77 * @param minCritical the minimal critical warning value, null to disable.
78 * @param maxCritical the maximal critical warning value, null to disable.
79 */
80 public DataSource(String name, String label, String cdef, Type type, Graph graph,
81 Number min, Number max, Number minWarning, Number maxWarning,
82 Number minCritical, Number maxCritical)
83 {
84 this.name = name;
85 this.label = label;
86 this.cdef = cdef;
87 this.type = type;
88 this.graph = graph;
89 this.min = min;
90 this.max = max;
91 this.minWarning = minWarning;
92 this.maxWarning = maxWarning;
93 this.minCritical = minCritical;
94 this.maxCritical = maxCritical;
95 }
96
97 /***
98 * Creates new DataSource instance.
99 * @param name the name of the data source.
100 * @param label the data source label.
101 * @param type the data source type.
102 * @param graph the graph type for the data source.
103 */
104 public DataSource(String name, String label, Type type, Graph graph)
105 {
106 this(name, label, null, type, graph, null, null, null, null, null, null);
107 }
108
109 /***
110 * Creates new DataSource instance.
111 *
112 * @param config DNA configuration object.
113 * @throws ConfigurationException if the configuraiton object contains invalid data.
114 */
115 public DataSource(Configuration config)
116 throws ConfigurationException
117 {
118 this(
119 config.getChild("name").getValue(),
120 config.getChild("label").getValue(null),
121 config.getChild("cdef").getValue(null),
122 getType(config.getChild("type").getValue(null)),
123 getGraph(config.getChild("graph").getValue(null)),
124 getNumber(config.getChild("min").getValue(null)),
125 getNumber(config.getChild("max").getValue(null)),
126 getNumber(config.getChild("minWarning").getValue(null)),
127 getNumber(config.getChild("maxWarning").getValue(null)),
128 getNumber(config.getChild("minCritical").getValue(null)),
129 getNumber(config.getChild("maxCritical").getValue(null))
130 );
131 }
132
133 /***
134 * Creates new DataSource instance.
135 *
136 * @param base base data source configuraiton.
137 * @param override overriding data source configuration.
138 */
139 public DataSource(DataSource base, DataSource override)
140 {
141 this(
142 base.getName(),
143 override.getLabel() != null ? override.getLabel() : base.getLabel(),
144 override.getCdef() != null ? override.getCdef() : base.getCdef(),
145 override.getType() != null ? override.getType() : base.getType(),
146 override.getGraph() != null ? override.getGraph() : base.getGraph(),
147 override.getMin() != null ? override.getMin() : base.getMin(),
148 override.getMax() != null ? override.getMax() : base.getMax(),
149 override.getMinWarning() != null ? override.getMinWarning() : base.getMinWarning(),
150 override.getMaxWarning() != null ? override.getMaxWarning() : base.getMaxWarning(),
151 override.getMinCritical() != null ? override.getMinCritical() : base.getMinCritical(),
152 override.getMaxCritical() != null ? override.getMaxCritical() : base.getMaxCritical()
153 );
154 }
155
156 /***
157 * Returns the name.
158 *
159 * @return the name.
160 */
161 public String getName()
162 {
163 return name;
164 }
165
166 /***
167 * Returns the label.
168 *
169 * @return the label.
170 */
171 public String getLabel()
172 {
173 return label;
174 }
175
176 /***
177 * Returns the cdef.
178 *
179 * @return the cdef.
180 */
181 public String getCdef()
182 {
183 return cdef;
184 }
185
186 /***
187 * Returns the type.
188 *
189 * @return the type.
190 */
191 public Type getType()
192 {
193 return type;
194 }
195
196 /***
197 * Returns the graph.
198 *
199 * @return the graph.
200 */
201 public Graph getGraph()
202 {
203 return graph;
204 }
205
206 /***
207 * Returns the min.
208 *
209 * @return the min.
210 */
211 public Number getMin()
212 {
213 return min;
214 }
215
216 /***
217 * Returns the max.
218 *
219 * @return the max.
220 */
221 public Number getMax()
222 {
223 return max;
224 }
225
226 /***
227 * Returns the minWarning.
228 *
229 * @return the minWarning.
230 */
231 public Number getMinWarning()
232 {
233 return minWarning;
234 }
235
236 /***
237 * Returns the maxWarning.
238 *
239 * @return the maxWarning.
240 */
241 public Number getMaxWarning()
242 {
243 return maxWarning;
244 }
245
246 /***
247 * Returns the minCritical.
248 *
249 * @return the minCritical.
250 */
251 public Number getMinCritical()
252 {
253 return minCritical;
254 }
255
256 /***
257 * Returns the maxCritical.
258 *
259 * @return the maxCritical.
260 */
261 public Number getMaxCritical()
262 {
263 return maxCritical;
264 }
265
266 private static Type getType(String type)
267 {
268 if(type == null)
269 {
270 return null;
271 }
272 else
273 {
274 return Type.valueOf(type);
275 }
276 }
277
278 private static Graph getGraph(String graph)
279 {
280 if(graph == null)
281 {
282 return null;
283 }
284 else
285 {
286 return Graph.valueOf(graph);
287 }
288 }
289
290 private static Number getNumber(String number)
291 {
292 if(number == null)
293 {
294 return null;
295 }
296 else
297 {
298 return new BigDecimal(number);
299 }
300 }
301
302 /***
303 * Types of data sources modeled after RRDTool.
304 */
305 public enum Type
306 {
307 /*** A nondecreasing conter value, suitable for computing rate over time. */
308 COUNTER,
309
310 /*** A a floating value, suitable for computing average over time. */
311 GAUGE,
312
313 /*** Like COUNTER, but value is reset to 0 after each read. */
314 ABSOLUTE,
315
316 /*** Like COUNTER, but may increase and decrease - thus no wraparound protection
317 * is available.*/
318 DERIVE
319 }
320
321 /***
322 * Graph types modeled after RRDTool.
323 */
324 public enum Graph
325 {
326 /*** Hidden graph. */
327 HIDDEN,
328
329 /*** Line graph 1. */
330 LINE1,
331
332 /*** Line graph 2. */
333 LINE2,
334
335 /*** Line graph 3. */
336 LINE3,
337
338 /*** Area graph. */
339 AREA
340 }
341 }