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 <vector>
28 #include <ctime>
29 
30 namespace fawkes {
31 #if 0 /* just to make Emacs auto-indent happy */
32 }
33 #endif
34 
35 class RRDManager;
36 
38 {
39  public:
40  /** Data source type. */
41  typedef enum {
42  GAUGE, /**< Gauge value. */
43  COUNTER, /**< Counter value. */
44  DERIVE, /**< Derived value. */
45  ABSOLUTE, /**< Absolute value. */
46  COMPUTE /**< Computed value. */
47  } Type;
48 
49  static const float UNKNOWN;
50 
51  RRDDataSource(const char *name, Type type, unsigned int heartbeat = 30,
52  float min = 0, float max = UNKNOWN);
53  RRDDataSource(const char *name, const char *rpn_expression);
54  RRDDataSource(const RRDDataSource &other);
56  RRDDataSource & operator=(const RRDDataSource &other);
57 
58 
59  const char * to_string() const;
60 
61  /** Get name. @return name */
62  const char * get_name() const { return __name; };
63  /** Get type. @return type */
64  Type get_type() const { return __type; };
65  /** Get heartbeat. @return heartbeat */
66  unsigned int get_heartbeat() const { return __heartbeat; };
67  /** Get minimum. @return minimum */
68  float get_min() const { return __min; };
69  /** Get maximum. @return maximum */
70  float get_max() const { return __max; };
71  /** Get RPN expression. @return RPN expression */
72  const char * get_rpn_expression() const { return __rpn_expression; };
73 
74 
75  private:
76  char *__name;
77  Type __type;
78  unsigned int __heartbeat;
79  float __min;
80  float __max;
81  char *__rpn_expression;
82 
83  mutable char * __string;
84 };
85 
87 {
88  public:
89  /** Consolidation function type. */
90  typedef enum {
91  AVERAGE, /**< Averaging consolidation function. */
92  MIN, /**< Minimum consolidation function. */
93  MAX, /**< Maximum consolidation function. */
94  LAST /**< Last value consolidation function. */
96 
97  RRDArchive(ConsolidationFunction cf,
98  float xff, unsigned int steps, unsigned int rows);
99  RRDArchive(const RRDArchive &rra);
100  ~RRDArchive();
101 
102  const char * to_string() const;
103  static const char * cf_to_string(ConsolidationFunction cf);
104 
105  RRDArchive & operator=(const RRDArchive &rra);
106 
107  /** Get consolidation function type. @return consolidation function type */
108  ConsolidationFunction get_cf() const { return __cf; }
109  /** Get xfiles factor. @return xfiles factor */
110  float get_xff() const { return __xff; }
111  /** Get number of steps. @return number of steps */
112  unsigned int get_steps() const { return __steps; }
113  /** Get number of rows. @return number of rows */
114  unsigned int get_rows() const { return __rows; }
115 
116  private:
117  ConsolidationFunction __cf;
118  float __xff;
119  unsigned int __steps;
120  unsigned int __rows;
121 
122  mutable char *__string;
123 };
124 
126 {
127  public:
128  RRDDefinition(const char *name,
129  std::vector<RRDDataSource> &ds,
130  unsigned int step_sec = 10, bool recreate = false);
131 
132  RRDDefinition(const char *name,
133  std::vector<RRDDataSource> &ds,
134  std::vector<RRDArchive> &rra,
135  unsigned int step_sec = 10, bool recreate = false);
136  RRDDefinition(const RRDDefinition &other);
137  ~RRDDefinition();
138  RRDDefinition & operator=(const RRDDefinition &other);
139 
140  size_t find_ds_index(const char *ds_name) const;
141  void set_filename(const char *filename);
142  static const std::vector<RRDArchive> get_default_rra();
143 
144  /** Get name. @return name */
145  const char * get_name() const { return __name; }
146  /** Get step size in sec. @return step size */
147  unsigned int get_step_sec() const { return __step_sec; }
148  /** Check recreation flag.
149  * @return true if files should be overwritte, false otherwise */
150  bool get_recreate() const { return __recreate; }
151  /** Get data sources. * @return data sources */
152  const std::vector<RRDDataSource> & get_ds() const { return __ds; }
153  /** Get specific data source.
154  * @param i index of data source
155  * @return data source */
156  const RRDDataSource & get_ds(size_t i) const { return __ds[i]; }
157  /** Get RRD archives. @return RRD archive */
158  const std::vector<RRDArchive> & get_rra() const { return __rra; }
159  /** Get file name. @return file name */
160  const char * get_filename() const { return __filename; }
161 
162  void set_rrd_manager(RRDManager *rrd_manager);
163 
164  private:
165  char *__name;
166  unsigned int __step_sec;
167  bool __recreate;
168  std::vector<RRDDataSource> __ds;
169  std::vector<RRDArchive> __rra;
170  char *__filename;
171 
172  RRDManager *__rrd_manager;
173 };
174 
176 {
177  public:
179  const RRDDefinition *rrd_def, const char *ds_name = NULL);
180  RRDGraphDataDefinition(const char *name, const char *rpn_expression);
184 
185  const char * to_string() const;
186 
187  /** Get name. @return name */
188  const char * get_name() const { return __name; };
189  /** Get RRD definition. @return RRD definition */
190  const RRDDefinition * get_rrd_def() const { return __rrd_def; };
191  /** Get data source name. @return data source name */
192  const char * get_ds_name() const { return __ds_name; };
193  /** Get RPN expression. @return RPN expression */
194  const char * get_rpn_expression() const { return __rpn_expression; };
195  /** Get consolidation function type. @return consolidation function type */
196  RRDArchive::ConsolidationFunction get_cf() const { return __cf; };
197 
198  private:
199  char *__name;
200  const RRDDefinition *__rrd_def;
201  char *__ds_name;
202  char *__rpn_expression;
204 
205  mutable char *__string;
206 };
207 
209 {
210  public:
211  virtual ~RRDGraphElement() {}
212  virtual RRDGraphElement * clone() const = 0;
213  virtual const char * to_string() const;
214 };
215 
216 
218 {
219  public:
220  RRDGraphGPrint(const char *def_name, RRDArchive::ConsolidationFunction cf,
221  const char *format);
222  RRDGraphGPrint(const RRDGraphGPrint &other);
223  virtual ~RRDGraphGPrint();
224 
226 
227  virtual RRDGraphElement * clone() const { return new RRDGraphGPrint(*this); }
228 
229  virtual const char * to_string() const;
230 
231  /** Get definition name. @return definition name */
232  const char * get_def_name() const { return __def_name; }
233  /** Get consolidation function type. @return consolidation function type */
234  RRDArchive::ConsolidationFunction get_cf() const { return __cf; }
235  /** Get format string. @return format string */
236  const char * get_format() const { return __format; }
237 
238  private:
239  char *__def_name;
241  char *__format;
242 
243  mutable char *__string;
244 };
245 
247 {
248  public:
249  RRDGraphLine(const char *def_name, float width, const char *color,
250  const char *legend, bool stacked = false);
251  RRDGraphLine(const RRDGraphLine &other);
252  virtual ~RRDGraphLine();
253 
254  virtual RRDGraphElement * clone() const { return new RRDGraphLine(*this); }
255 
256  RRDGraphLine & operator=(const RRDGraphLine &g);
257 
258  virtual const char * to_string() const;
259 
260  /** Get definition name. @return definition name */
261  const char * get_def_name() const { return __def_name; }
262  /** Get line width. @return line width */
263  float get_width() const { return __width; }
264  /** Get color string. @return color string */
265  const char * get_color() const { return __color; }
266  /** Get legend label. @return legend label */
267  const char * get_legend() const { return __legend; }
268  /** Get stacked flag. @return true if line should be stacked, false otherwise. */
269  bool get_stacked() const { return __stacked; }
270 
271  private:
272  char *__def_name;
273  float __width;
274  char *__color;
275  char *__legend;
276  bool __stacked;
277 
278  mutable char *__string;
279 };
280 
282 {
283  public:
284  RRDGraphArea(const char *def_name, const char *color,
285  const char *legend, bool stacked = false);
286  RRDGraphArea(const RRDGraphArea &other);
287  virtual ~RRDGraphArea();
288 
289  virtual RRDGraphElement * clone() const { return new RRDGraphArea(*this); }
290 
291  RRDGraphArea & operator=(const RRDGraphArea &g);
292 
293  virtual const char * to_string() const;
294 
295  /** Get definition name. @return definition name */
296  const char * get_def_name() const { return __def_name; }
297  /** Get color string. @return color string */
298  const char * get_color() const { return __color; }
299  /** Get legend label. @return legend label */
300  const char * get_legend() const { return __legend; }
301  /** Get stacked flag. @return true if line should be stacked, false otherwise. */
302  bool get_stacked() const { return __stacked; }
303 
304  private:
305  char *__def_name;
306  char *__color;
307  char *__legend;
308  bool __stacked;
309 
310  mutable char *__string;
311 };
312 
314 {
315  public:
316  RRDGraphDefinition(const char *name, RRDDefinition *rrd_def,
317  const char *title, const char *vertical_label,
318  std::vector<RRDGraphDataDefinition> &def,
319  std::vector<RRDGraphElement *> &elements,
320  time_t start = -600, time_t end = -10, unsigned int step = 10,
321  unsigned int update_interval = 10, bool slope_mode = false);
324 
325  void set_filename(const char *filename);
326  const char ** get_argv(size_t &argc) const;
327 
328 
329  /** Get graph definition name. @return graph definition name */
330  const char * get_name() const { return __name; }
331  /** Get RRD definition. @return RRD definition */
332  const RRDDefinition * get_rrd_def() const { return __rrd_def; }
333  /** Get start time. @return start time */
334  time_t get_start() const { return __start; }
335  /** Get end time. @return end time */
336  time_t get_end() const { return __end; }
337  /** Get step size. @return step size */
338  unsigned int get_step() const { return __step; }
339  /** Get title. @return tile */
340  const char * get_title() const { return __title; }
341  /** Get vertical label. @return vertical label */
342  const char * get_vertical_label() const { return __vertical_label; }
343  /** Get update interval. @return update interval */
344  const unsigned int get_update_interval() const { return __update_interval; }
345  /** Get slope moe. @return slope mode */
346  const bool get_slope_mode() const { return __slope_mode; }
347  /** Get definitions. @return definitions */
348  const std::vector<RRDGraphDataDefinition> & get_defs() const { return __defs; }
349  /** Get graph elements. @return graph elements */
350  const std::vector<RRDGraphElement *> & get_elements() const
351  { return __elements; }
352  /** Get line width. @return line width. */
353  unsigned int get_width() const { return __width; }
354  /** Get fonts. @return fonts */
355  const std::vector<const char *> get_fonts() const { return __fonts; }
356  /** Get filename. @return filename */
357  const char * get_filename() const { return __filename; }
358 
359  private:
360  char *__name;
361  const RRDDefinition *__rrd_def;
362  const time_t __start;
363  const time_t __end;
364  unsigned int __step;
365  char *__title;
366  char *__vertical_label;
367  const unsigned int __update_interval;
368  const bool __slope_mode;
369  std::vector<RRDGraphDataDefinition> __defs;
370  std::vector<RRDGraphElement *> __elements;
371  unsigned int __width;
372  char *__width_s;
373  char *__start_s;
374  char *__end_s;
375  char *__step_s;
376  std::vector<const char *> __fonts;
377  char *__filename;
378  mutable size_t __argc;
379  mutable const char **__argv;
380 };
381 
382 } // end namespace fawkes
383 
384 #endif
static const float UNKNOWN
Use for unknown min or max values.
RRDArchive::ConsolidationFunction get_cf() const
Get consolidation function type.
const char * get_title() const
Get title.
virtual RRDGraphElement * clone() const
Clone this element.
const char * get_name() const
Get name.
unsigned int get_width() const
Get line width.
const std::vector< const char * > get_fonts() const
Get fonts.
Interface for a RRD connection creator.
Definition: rrd_manager.h:40
Type get_type() const
Get type.
Type
Data source type.
const char * get_name() const
Get graph definition name.
Print graph area.
Fawkes library namespace.
unsigned int get_steps() const
Get number of steps.
const char * to_string() const
Get string reprensetation.
float get_width() const
Get line width.
const char * get_filename() const
Get filename.
unsigned int get_step() const
Get step size.
Maximum consolidation function.
float get_min() const
Get minimum.
const RRDDefinition * get_rrd_def() const
Get RRD definition.
RRDDataSource(const char *name, Type type, unsigned int heartbeat=30, float min=0, float max=UNKNOWN)
Constructor for regular data source.
const char * get_def_name() const
Get definition name.
float get_xff() const
Get xfiles factor.
const unsigned int get_update_interval() const
Get update interval.
const std::vector< RRDDataSource > & get_ds() const
Get data sources.
const char * get_ds_name() const
Get data source name.
const char * get_legend() const
Get legend label.
RRD Archive description.
unsigned int get_rows() const
Get number of rows.
time_t get_end() const
Get end time.
unsigned int get_heartbeat() const
Get heartbeat.
const char * get_color() const
Get color string.
ConsolidationFunction
Consolidation function type.
const char * get_rpn_expression() const
Get RPN expression.
unsigned int get_step_sec() const
Get step size in sec.
bool get_stacked() const
Get stacked flag.
const bool get_slope_mode() const
Get slope moe.
const char * get_rpn_expression() const
Get RPN expression.
Print graph line.
const std::vector< RRDGraphElement * > & get_elements() const
Get graph elements.
float get_max() const
Get maximum.
const char * get_legend() const
Get legend label.
Represent data definition in graph arguments.
const char * get_def_name() const
Get definition name.
const std::vector< RRDGraphDataDefinition > & get_defs() const
Get definitions.
Class representing a graph definition.
const std::vector< RRDArchive > & get_rra() const
Get RRD archives.
RRDDataSource & operator=(const RRDDataSource &other)
Assignment operator.
Class to represent a RRD data source.
const RRDDataSource & get_ds(size_t i) const
Get specific data source.
virtual RRDGraphElement * clone() const
Clone this element.
time_t get_start() const
Get start time.
const char * get_vertical_label() const
Get vertical label.
const RRDDefinition * get_rrd_def() const
Get RRD definition.
bool get_stacked() const
Get stacked flag.
const char * get_name() const
Get name.
const char * get_def_name() const
Get definition name.
const char * get_name() const
Get name.
const char * get_filename() const
Get file name.
Interface for graph elements.
virtual RRDGraphElement * clone() const
Clone this element.
ConsolidationFunction get_cf() const
Get consolidation function type.
RRDArchive::ConsolidationFunction get_cf() const
Get consolidation function type.
const char * get_format() const
Get format string.
Print string inside graph.
~RRDDataSource()
Destructor.
Minimum consolidation function.
const char * get_color() const
Get color string.
bool get_recreate() const
Check recreation flag.
Averaging consolidation function.