Fawkes API Fawkes Development Version
rrd_descriptions.h
1
2/***************************************************************************
3 * rrd_descriptions.h - Fawkes RRD descriptions
4 *
5 * Created: Sat Dec 18 02:19:03 2010
6 * Copyright 2006-2011 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#ifndef _PLUGINS_RRD_ASPECT_RRD_DESCRIPTIONS_H_
25#define _PLUGINS_RRD_ASPECT_RRD_DESCRIPTIONS_H_
26
27#include <ctime>
28#include <vector>
29
30namespace fawkes {
31
32class RRDManager;
33
35{
36public:
37 /** Data source type. */
38 typedef enum {
39 GAUGE, /**< Gauge value. */
40 COUNTER, /**< Counter value. */
41 DERIVE, /**< Derived value. */
42 ABSOLUTE, /**< Absolute value. */
43 COMPUTE /**< Computed value. */
45
46 static const float UNKNOWN;
47
48 RRDDataSource(const char * name,
49 Type type,
50 unsigned int heartbeat = 30,
51 float min = 0,
52 float max = UNKNOWN);
53 RRDDataSource(const char *name, const char *rpn_expression);
54 RRDDataSource(const RRDDataSource &other);
57
58 const char *to_string() const;
59
60 /** Get name. @return name */
61 const char *
62 get_name() const
63 {
64 return name_;
65 };
66 /** Get type. @return type */
67 Type
68 get_type() const
69 {
70 return type_;
71 };
72 /** Get heartbeat. @return heartbeat */
73 unsigned int
75 {
76 return heartbeat_;
77 };
78 /** Get minimum. @return minimum */
79 float
80 get_min() const
81 {
82 return min_;
83 };
84 /** Get maximum. @return maximum */
85 float
86 get_max() const
87 {
88 return max_;
89 };
90 /** Get RPN expression. @return RPN expression */
91 const char *
93 {
94 return rpn_expression_;
95 };
96
97private:
98 char * name_;
99 Type type_;
100 unsigned int heartbeat_;
101 float min_;
102 float max_;
103 char * rpn_expression_;
104
105 mutable char *string_;
106};
107
109{
110public:
111 /** Consolidation function type. */
112 typedef enum {
113 AVERAGE, /**< Averaging consolidation function. */
114 MIN, /**< Minimum consolidation function. */
115 MAX, /**< Maximum consolidation function. */
116 LAST /**< Last value consolidation function. */
118
119 RRDArchive(ConsolidationFunction cf, float xff, unsigned int steps, unsigned int rows);
120 RRDArchive(const RRDArchive &rra);
121 ~RRDArchive();
122
123 const char * to_string() const;
124 static const char *cf_to_string(ConsolidationFunction cf);
125
126 RRDArchive &operator=(const RRDArchive &rra);
127
128 /** Get consolidation function type. @return consolidation function type */
130 get_cf() const
131 {
132 return cf_;
133 }
134 /** Get xfiles factor. @return xfiles factor */
135 float
136 get_xff() const
137 {
138 return xff_;
139 }
140 /** Get number of steps. @return number of steps */
141 unsigned int
142 get_steps() const
143 {
144 return steps_;
145 }
146 /** Get number of rows. @return number of rows */
147 unsigned int
148 get_rows() const
149 {
150 return rows_;
151 }
152
153private:
155 float xff_;
156 unsigned int steps_;
157 unsigned int rows_;
158
159 mutable char *string_;
160};
161
163{
164public:
165 RRDDefinition(const char * name,
166 std::vector<RRDDataSource> &ds,
167 unsigned int step_sec = 10,
168 bool recreate = false);
169
170 RRDDefinition(const char * name,
171 std::vector<RRDDataSource> &ds,
172 std::vector<RRDArchive> & rra,
173 unsigned int step_sec = 10,
174 bool recreate = false);
175 RRDDefinition(const RRDDefinition &other);
178
179 size_t find_ds_index(const char *ds_name) const;
180 void set_filename(const char *filename);
181 static const std::vector<RRDArchive> get_default_rra();
182
183 /** Get name. @return name */
184 const char *
185 get_name() const
186 {
187 return name_;
188 }
189 /** Get step size in sec. @return step size */
190 unsigned int
192 {
193 return step_sec_;
194 }
195 /** Check recreation flag.
196 * @return true if files should be overwritte, false otherwise */
197 bool
199 {
200 return recreate_;
201 }
202 /** Get data sources. * @return data sources */
203 const std::vector<RRDDataSource> &
204 get_ds() const
205 {
206 return ds_;
207 }
208 /** Get specific data source.
209 * @param i index of data source
210 * @return data source */
211 const RRDDataSource &
212 get_ds(size_t i) const
213 {
214 return ds_[i];
215 }
216 /** Get RRD archives. @return RRD archive */
217 const std::vector<RRDArchive> &
218 get_rra() const
219 {
220 return rra_;
221 }
222 /** Get file name. @return file name */
223 const char *
225 {
226 return filename_;
227 }
228
229 void set_rrd_manager(RRDManager *rrd_manager);
230
231private:
232 char * name_;
233 unsigned int step_sec_;
234 bool recreate_;
235 std::vector<RRDDataSource> ds_;
236 std::vector<RRDArchive> rra_;
237 char * filename_;
238
239 RRDManager *rrd_manager_;
240};
241
243{
244public:
245 RRDGraphDataDefinition(const char * name,
247 const RRDDefinition * rrd_def,
248 const char * ds_name = NULL);
249 RRDGraphDataDefinition(const char *name, const char *rpn_expression);
253
254 const char *to_string() const;
255
256 /** Get name. @return name */
257 const char *
258 get_name() const
259 {
260 return name_;
261 };
262 /** Get RRD definition. @return RRD definition */
263 const RRDDefinition *
265 {
266 return rrd_def_;
267 };
268 /** Get data source name. @return data source name */
269 const char *
271 {
272 return ds_name_;
273 };
274 /** Get RPN expression. @return RPN expression */
275 const char *
277 {
278 return rpn_expression_;
279 };
280 /** Get consolidation function type. @return consolidation function type */
282 get_cf() const
283 {
284 return cf_;
285 };
286
287private:
288 char * name_;
289 const RRDDefinition * rrd_def_;
290 char * ds_name_;
291 char * rpn_expression_;
293
294 mutable char *string_;
295};
296
298{
299public:
300 virtual ~RRDGraphElement()
301 {
302 }
303 virtual RRDGraphElement *clone() const = 0;
304 virtual const char * to_string() const;
305};
306
308{
309public:
310 RRDGraphGPrint(const char *def_name, RRDArchive::ConsolidationFunction cf, const char *format);
311 RRDGraphGPrint(const RRDGraphGPrint &other);
312 virtual ~RRDGraphGPrint();
313
315
316 virtual RRDGraphElement *
317 clone() const
318 {
319 return new RRDGraphGPrint(*this);
320 }
321
322 virtual const char *to_string() const;
323
324 /** Get definition name. @return definition name */
325 const char *
327 {
328 return def_name_;
329 }
330 /** Get consolidation function type. @return consolidation function type */
332 get_cf() const
333 {
334 return cf_;
335 }
336 /** Get format string. @return format string */
337 const char *
339 {
340 return format_;
341 }
342
343private:
344 char * def_name_;
346 char * format_;
347
348 mutable char *string_;
349};
350
352{
353public:
354 RRDGraphLine(const char *def_name,
355 float width,
356 const char *color,
357 const char *legend,
358 bool stacked = false);
359 RRDGraphLine(const RRDGraphLine &other);
360 virtual ~RRDGraphLine();
361
362 virtual RRDGraphElement *
363 clone() const
364 {
365 return new RRDGraphLine(*this);
366 }
367
369
370 virtual const char *to_string() const;
371
372 /** Get definition name. @return definition name */
373 const char *
375 {
376 return def_name_;
377 }
378 /** Get line width. @return line width */
379 float
380 get_width() const
381 {
382 return width_;
383 }
384 /** Get color string. @return color string */
385 const char *
386 get_color() const
387 {
388 return color_;
389 }
390 /** Get legend label. @return legend label */
391 const char *
393 {
394 return legend_;
395 }
396 /** Get stacked flag. @return true if line should be stacked, false otherwise. */
397 bool
399 {
400 return stacked_;
401 }
402
403private:
404 char *def_name_;
405 float width_;
406 char *color_;
407 char *legend_;
408 bool stacked_;
409
410 mutable char *string_;
411};
412
414{
415public:
416 RRDGraphArea(const char *def_name, const char *color, const char *legend, bool stacked = false);
417 RRDGraphArea(const RRDGraphArea &other);
418 virtual ~RRDGraphArea();
419
420 virtual RRDGraphElement *
421 clone() const
422 {
423 return new RRDGraphArea(*this);
424 }
425
427
428 virtual const char *to_string() const;
429
430 /** Get definition name. @return definition name */
431 const char *
433 {
434 return def_name_;
435 }
436 /** Get color string. @return color string */
437 const char *
438 get_color() const
439 {
440 return color_;
441 }
442 /** Get legend label. @return legend label */
443 const char *
445 {
446 return legend_;
447 }
448 /** Get stacked flag. @return true if line should be stacked, false otherwise. */
449 bool
451 {
452 return stacked_;
453 }
454
455private:
456 char *def_name_;
457 char *color_;
458 char *legend_;
459 bool stacked_;
460
461 mutable char *string_;
462};
463
465{
466public:
467 RRDGraphDefinition(const char * name,
468 RRDDefinition * rrd_def,
469 const char * title,
470 const char * vertical_label,
471 std::vector<RRDGraphDataDefinition> &def,
472 std::vector<RRDGraphElement *> & elements,
473 time_t start = -600,
474 time_t end = -10,
475 unsigned int step = 10,
476 unsigned int update_interval = 10,
477 bool slope_mode = false);
480
481 void set_filename(const char *filename);
482 const char **get_argv(size_t &argc) const;
483
484 /** Get graph definition name. @return graph definition name */
485 const char *
486 get_name() const
487 {
488 return name_;
489 }
490 /** Get RRD definition. @return RRD definition */
491 const RRDDefinition *
493 {
494 return rrd_def_;
495 }
496 /** Get start time. @return start time */
497 time_t
498 get_start() const
499 {
500 return start_;
501 }
502 /** Get end time. @return end time */
503 time_t
504 get_end() const
505 {
506 return end_;
507 }
508 /** Get step size. @return step size */
509 unsigned int
510 get_step() const
511 {
512 return step_;
513 }
514 /** Get title. @return tile */
515 const char *
516 get_title() const
517 {
518 return title_;
519 }
520 /** Get vertical label. @return vertical label */
521 const char *
523 {
524 return vertical_label_;
525 }
526 /** Get update interval. @return update interval */
527 unsigned int
529 {
530 return update_interval_;
531 }
532 /** Get slope moe. @return slope mode */
533 bool
535 {
536 return slope_mode_;
537 }
538 /** Get definitions. @return definitions */
539 const std::vector<RRDGraphDataDefinition> &
540 get_defs() const
541 {
542 return defs_;
543 }
544 /** Get graph elements. @return graph elements */
545 const std::vector<RRDGraphElement *> &
547 {
548 return elements_;
549 }
550 /** Get line width. @return line width. */
551 unsigned int
552 get_width() const
553 {
554 return width_;
555 }
556 /** Get fonts. @return fonts */
557 const std::vector<const char *>
558 get_fonts() const
559 {
560 return fonts_;
561 }
562 /** Get filename. @return filename */
563 const char *
565 {
566 return filename_;
567 }
568
569private:
570 char * name_;
571 const RRDDefinition * rrd_def_;
572 const time_t start_;
573 const time_t end_;
574 unsigned int step_;
575 char * title_;
576 char * vertical_label_;
577 const unsigned int update_interval_;
578 const bool slope_mode_;
579 std::vector<RRDGraphDataDefinition> defs_;
580 std::vector<RRDGraphElement *> elements_;
581 unsigned int width_;
582 char * width_s_;
583 char * start_s_;
584 char * end_s_;
585 char * step_s_;
586 std::vector<const char *> fonts_;
587 char * filename_;
588 mutable size_t argc_;
589 mutable const char ** argv_;
590};
591
592} // end namespace fawkes
593
594#endif
RRD Archive description.
RRDArchive(ConsolidationFunction cf, float xff, unsigned int steps, unsigned int rows)
Constructor.
float get_xff() const
Get xfiles factor.
const char * to_string() const
Get string representation.
ConsolidationFunction get_cf() const
Get consolidation function type.
unsigned int get_steps() const
Get number of steps.
unsigned int get_rows() const
Get number of rows.
ConsolidationFunction
Consolidation function type.
@ MAX
Maximum consolidation function.
@ MIN
Minimum consolidation function.
@ LAST
Last value consolidation function.
@ AVERAGE
Averaging consolidation function.
static const char * cf_to_string(ConsolidationFunction cf)
Convert consolidation function type to string.
RRDArchive & operator=(const RRDArchive &rra)
Assignment operator.
Class to represent a RRD data source.
const char * get_rpn_expression() const
Get RPN expression.
unsigned int get_heartbeat() const
Get heartbeat.
const char * get_name() const
Get name.
Type
Data source type.
@ DERIVE
Derived value.
@ COMPUTE
Computed value.
@ ABSOLUTE
Absolute value.
@ COUNTER
Counter value.
const char * to_string() const
Get string reprensetation.
float get_max() const
Get maximum.
Type get_type() const
Get type.
RRDDataSource & operator=(const RRDDataSource &other)
Assignment operator.
static const float UNKNOWN
Use for unknown min or max values.
RRDDataSource(const char *name, Type type, unsigned int heartbeat=30, float min=0, float max=UNKNOWN)
Constructor for regular data source.
float get_min() const
Get minimum.
void set_rrd_manager(RRDManager *rrd_manager)
Set RRD manager.
const RRDDataSource & get_ds(size_t i) const
Get specific data source.
const char * get_filename() const
Get file name.
void set_filename(const char *filename)
Set filename.
RRDDefinition(const char *name, std::vector< RRDDataSource > &ds, unsigned int step_sec=10, bool recreate=false)
Constructor with default RRAs.
const std::vector< RRDArchive > & get_rra() const
Get RRD archives.
RRDDefinition & operator=(const RRDDefinition &other)
Assignment operator.
const char * get_name() const
Get name.
size_t find_ds_index(const char *ds_name) const
Find data source index.
static const std::vector< RRDArchive > get_default_rra()
Get default RRAs.
bool get_recreate() const
Check recreation flag.
unsigned int get_step_sec() const
Get step size in sec.
const std::vector< RRDDataSource > & get_ds() const
Get data sources.
Print graph area.
const char * get_color() const
Get color string.
virtual const char * to_string() const
Create string representation.
const char * get_legend() const
Get legend label.
const char * get_def_name() const
Get definition name.
RRDGraphArea(const char *def_name, const char *color, const char *legend, bool stacked=false)
Constructor.
virtual ~RRDGraphArea()
Destructor.
bool get_stacked() const
Get stacked flag.
virtual RRDGraphElement * clone() const
Clone this element.
RRDGraphArea & operator=(const RRDGraphArea &g)
Assignment operator.
Represent data definition in graph arguments.
RRDGraphDataDefinition(const char *name, RRDArchive::ConsolidationFunction cf, const RRDDefinition *rrd_def, const char *ds_name=NULL)
DEF constructor.
RRDArchive::ConsolidationFunction get_cf() const
Get consolidation function type.
const char * get_ds_name() const
Get data source name.
RRDGraphDataDefinition & operator=(const RRDGraphDataDefinition &rra)
Assignment operator.
const char * get_rpn_expression() const
Get RPN expression.
const char * to_string() const
Create string representation.
const char * get_name() const
Get name.
const RRDDefinition * get_rrd_def() const
Get RRD definition.
Class representing a graph definition.
unsigned int get_update_interval() const
Get update interval.
RRDGraphDefinition(const char *name, RRDDefinition *rrd_def, const char *title, const char *vertical_label, std::vector< RRDGraphDataDefinition > &def, std::vector< RRDGraphElement * > &elements, time_t start=-600, time_t end=-10, unsigned int step=10, unsigned int update_interval=10, bool slope_mode=false)
Constructor.
time_t get_end() const
Get end time.
const char * get_name() const
Get graph definition name.
const char ** get_argv(size_t &argc) const
Get argument array and size.
unsigned int get_step() const
Get step size.
const char * get_vertical_label() const
Get vertical label.
unsigned int get_width() const
Get line width.
time_t get_start() const
Get start time.
const std::vector< RRDGraphElement * > & get_elements() const
Get graph elements.
bool get_slope_mode() const
Get slope moe.
const char * get_filename() const
Get filename.
void set_filename(const char *filename)
Set filename.
const char * get_title() const
Get title.
const std::vector< RRDGraphDataDefinition > & get_defs() const
Get definitions.
const RRDDefinition * get_rrd_def() const
Get RRD definition.
const std::vector< const char * > get_fonts() const
Get fonts.
Interface for graph elements.
virtual const char * to_string() const
Create string representation.
virtual RRDGraphElement * clone() const =0
Clone this element.
Print string inside graph.
RRDGraphGPrint & operator=(const RRDGraphGPrint &g)
Assignment operator.
RRDGraphGPrint(const char *def_name, RRDArchive::ConsolidationFunction cf, const char *format)
Constructor.
virtual ~RRDGraphGPrint()
Destructor.
virtual RRDGraphElement * clone() const
Clone this element.
virtual const char * to_string() const
Create string representation.
const char * get_def_name() const
Get definition name.
RRDArchive::ConsolidationFunction get_cf() const
Get consolidation function type.
const char * get_format() const
Get format string.
Print graph line.
virtual const char * to_string() const
Create string representation.
virtual RRDGraphElement * clone() const
Clone this element.
float get_width() const
Get line width.
RRDGraphLine & operator=(const RRDGraphLine &g)
Assignment operator.
const char * get_color() const
Get color string.
const char * get_legend() const
Get legend label.
virtual ~RRDGraphLine()
Destructor.
bool get_stacked() const
Get stacked flag.
RRDGraphLine(const char *def_name, float width, const char *color, const char *legend, bool stacked=false)
Constructor.
const char * get_def_name() const
Get definition name.
Interface for a RRD connection creator.
Definition: rrd_manager.h:37
Fawkes library namespace.