Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * rrd_descriptions.h - Fawkes RRD descriptions 00004 * 00005 * Created: Sat Dec 18 02:19:03 2010 00006 * Copyright 2006-2011 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #ifndef __PLUGINS_RRD_ASPECT_RRD_DESCRIPTIONS_H_ 00025 #define __PLUGINS_RRD_ASPECT_RRD_DESCRIPTIONS_H_ 00026 00027 #include <vector> 00028 #include <ctime> 00029 00030 namespace fawkes { 00031 #if 0 /* just to make Emacs auto-indent happy */ 00032 } 00033 #endif 00034 00035 class RRDManager; 00036 00037 class RRDDataSource 00038 { 00039 public: 00040 /** Data source type. */ 00041 typedef enum { 00042 GAUGE, /**< Gauge value. */ 00043 COUNTER, /**< Counter value. */ 00044 DERIVE, /**< Derived value. */ 00045 ABSOLUTE, /**< Absolute value. */ 00046 COMPUTE /**< Computed value. */ 00047 } Type; 00048 00049 static const float UNKNOWN; 00050 00051 RRDDataSource(const char *name, Type type, unsigned int heartbeat = 30, 00052 float min = 0, float max = UNKNOWN); 00053 RRDDataSource(const char *name, const char *rpn_expression); 00054 RRDDataSource(const RRDDataSource &other); 00055 ~RRDDataSource(); 00056 RRDDataSource & operator=(const RRDDataSource &other); 00057 00058 00059 const char * to_string() const; 00060 00061 /** Get name. @return name */ 00062 const char * get_name() const { return __name; }; 00063 /** Get type. @return type */ 00064 Type get_type() const { return __type; }; 00065 /** Get heartbeat. @return heartbeat */ 00066 unsigned int get_heartbeat() const { return __heartbeat; }; 00067 /** Get minimum. @return minimum */ 00068 float get_min() const { return __min; }; 00069 /** Get maximum. @return maximum */ 00070 float get_max() const { return __max; }; 00071 /** Get RPN expression. @return RPN expression */ 00072 const char * get_rpn_expression() const { return __rpn_expression; }; 00073 00074 00075 private: 00076 char *__name; 00077 Type __type; 00078 unsigned int __heartbeat; 00079 float __min; 00080 float __max; 00081 char *__rpn_expression; 00082 00083 mutable char * __string; 00084 }; 00085 00086 class RRDArchive 00087 { 00088 public: 00089 /** Consolidation function type. */ 00090 typedef enum { 00091 AVERAGE, /**< Averaging consolidation function. */ 00092 MIN, /**< Minimum consolidation function. */ 00093 MAX, /**< Maximum consolidation function. */ 00094 LAST /**< Last value consolidation function. */ 00095 } ConsolidationFunction; 00096 00097 RRDArchive(ConsolidationFunction cf, 00098 float xff, unsigned int steps, unsigned int rows); 00099 RRDArchive(const RRDArchive &rra); 00100 ~RRDArchive(); 00101 00102 const char * to_string() const; 00103 static const char * cf_to_string(ConsolidationFunction cf); 00104 00105 RRDArchive & operator=(const RRDArchive &rra); 00106 00107 /** Get consolidation function type. @return consolidation function type */ 00108 ConsolidationFunction get_cf() const { return __cf; } 00109 /** Get xfiles factor. @return xfiles factor */ 00110 float get_xff() const { return __xff; } 00111 /** Get number of steps. @return number of steps */ 00112 unsigned int get_steps() const { return __steps; } 00113 /** Get number of rows. @return number of rows */ 00114 unsigned int get_rows() const { return __rows; } 00115 00116 private: 00117 ConsolidationFunction __cf; 00118 float __xff; 00119 unsigned int __steps; 00120 unsigned int __rows; 00121 00122 mutable char *__string; 00123 }; 00124 00125 class RRDDefinition 00126 { 00127 public: 00128 RRDDefinition(const char *name, 00129 std::vector<RRDDataSource> &ds, 00130 unsigned int step_sec = 10, bool recreate = false); 00131 00132 RRDDefinition(const char *name, 00133 std::vector<RRDDataSource> &ds, 00134 std::vector<RRDArchive> &rra, 00135 unsigned int step_sec = 10, bool recreate = false); 00136 RRDDefinition(const RRDDefinition &other); 00137 ~RRDDefinition(); 00138 RRDDefinition & operator=(const RRDDefinition &other); 00139 00140 size_t find_ds_index(const char *ds_name) const; 00141 void set_filename(const char *filename); 00142 static const std::vector<RRDArchive> get_default_rra(); 00143 00144 /** Get name. @return name */ 00145 const char * get_name() const { return __name; } 00146 /** Get step size in sec. @return step size */ 00147 unsigned int get_step_sec() const { return __step_sec; } 00148 /** Check recreation flag. 00149 * @return true if files should be overwritte, false otherwise */ 00150 bool get_recreate() const { return __recreate; } 00151 /** Get data sources. * @return data sources */ 00152 const std::vector<RRDDataSource> & get_ds() const { return __ds; } 00153 /** Get specific data source. 00154 * @param i index of data source 00155 * @return data source */ 00156 const RRDDataSource & get_ds(size_t i) const { return __ds[i]; } 00157 /** Get RRD archives. @return RRD archive */ 00158 const std::vector<RRDArchive> & get_rra() const { return __rra; } 00159 /** Get file name. @return file name */ 00160 const char * get_filename() const { return __filename; } 00161 00162 void set_rrd_manager(RRDManager *rrd_manager); 00163 00164 private: 00165 char *__name; 00166 unsigned int __step_sec; 00167 bool __recreate; 00168 std::vector<RRDDataSource> __ds; 00169 std::vector<RRDArchive> __rra; 00170 char *__filename; 00171 00172 RRDManager *__rrd_manager; 00173 }; 00174 00175 class RRDGraphDataDefinition 00176 { 00177 public: 00178 RRDGraphDataDefinition(const char *name, RRDArchive::ConsolidationFunction cf, 00179 const RRDDefinition *rrd_def, const char *ds_name = NULL); 00180 RRDGraphDataDefinition(const char *name, const char *rpn_expression); 00181 RRDGraphDataDefinition(const RRDGraphDataDefinition &other); 00182 ~RRDGraphDataDefinition(); 00183 RRDGraphDataDefinition & operator=(const RRDGraphDataDefinition &rra); 00184 00185 const char * to_string() const; 00186 00187 /** Get name. @return name */ 00188 const char * get_name() const { return __name; }; 00189 /** Get RRD definition. @return RRD definition */ 00190 const RRDDefinition * get_rrd_def() const { return __rrd_def; }; 00191 /** Get data source name. @return data source name */ 00192 const char * get_ds_name() const { return __ds_name; }; 00193 /** Get RPN expression. @return RPN expression */ 00194 const char * get_rpn_expression() const { return __rpn_expression; }; 00195 /** Get consolidation function type. @return consolidation function type */ 00196 RRDArchive::ConsolidationFunction get_cf() const { return __cf; }; 00197 00198 private: 00199 char *__name; 00200 const RRDDefinition *__rrd_def; 00201 char *__ds_name; 00202 char *__rpn_expression; 00203 RRDArchive::ConsolidationFunction __cf; 00204 00205 mutable char *__string; 00206 }; 00207 00208 class RRDGraphElement 00209 { 00210 public: 00211 virtual ~RRDGraphElement() {} 00212 virtual RRDGraphElement * clone() const = 0; 00213 virtual const char * to_string() const; 00214 }; 00215 00216 00217 class RRDGraphGPrint : public RRDGraphElement 00218 { 00219 public: 00220 RRDGraphGPrint(const char *def_name, RRDArchive::ConsolidationFunction cf, 00221 const char *format); 00222 RRDGraphGPrint(const RRDGraphGPrint &other); 00223 virtual ~RRDGraphGPrint(); 00224 00225 RRDGraphGPrint & operator=(const RRDGraphGPrint &g); 00226 00227 virtual RRDGraphElement * clone() const { return new RRDGraphGPrint(*this); } 00228 00229 virtual const char * to_string() const; 00230 00231 /** Get definition name. @return definition name */ 00232 const char * get_def_name() const { return __def_name; } 00233 /** Get consolidation function type. @return consolidation function type */ 00234 RRDArchive::ConsolidationFunction get_cf() const { return __cf; } 00235 /** Get format string. @return format string */ 00236 const char * get_format() const { return __format; } 00237 00238 private: 00239 char *__def_name; 00240 RRDArchive::ConsolidationFunction __cf; 00241 char *__format; 00242 00243 mutable char *__string; 00244 }; 00245 00246 class RRDGraphLine : public RRDGraphElement 00247 { 00248 public: 00249 RRDGraphLine(const char *def_name, float width, const char *color, 00250 const char *legend, bool stacked = false); 00251 RRDGraphLine(const RRDGraphLine &other); 00252 virtual ~RRDGraphLine(); 00253 00254 virtual RRDGraphElement * clone() const { return new RRDGraphLine(*this); } 00255 00256 RRDGraphLine & operator=(const RRDGraphLine &g); 00257 00258 virtual const char * to_string() const; 00259 00260 /** Get definition name. @return definition name */ 00261 const char * get_def_name() const { return __def_name; } 00262 /** Get line width. @return line width */ 00263 float get_width() const { return __width; } 00264 /** Get color string. @return color string */ 00265 const char * get_color() const { return __color; } 00266 /** Get legend label. @return legend label */ 00267 const char * get_legend() const { return __legend; } 00268 /** Get stacked flag. @return true if line should be stacked, false otherwise. */ 00269 bool get_stacked() const { return __stacked; } 00270 00271 private: 00272 char *__def_name; 00273 float __width; 00274 char *__color; 00275 char *__legend; 00276 bool __stacked; 00277 00278 mutable char *__string; 00279 }; 00280 00281 class RRDGraphArea : public RRDGraphElement 00282 { 00283 public: 00284 RRDGraphArea(const char *def_name, const char *color, 00285 const char *legend, bool stacked = false); 00286 RRDGraphArea(const RRDGraphArea &other); 00287 virtual ~RRDGraphArea(); 00288 00289 virtual RRDGraphElement * clone() const { return new RRDGraphArea(*this); } 00290 00291 RRDGraphArea & operator=(const RRDGraphArea &g); 00292 00293 virtual const char * to_string() const; 00294 00295 /** Get definition name. @return definition name */ 00296 const char * get_def_name() const { return __def_name; } 00297 /** Get color string. @return color string */ 00298 const char * get_color() const { return __color; } 00299 /** Get legend label. @return legend label */ 00300 const char * get_legend() const { return __legend; } 00301 /** Get stacked flag. @return true if line should be stacked, false otherwise. */ 00302 bool get_stacked() const { return __stacked; } 00303 00304 private: 00305 char *__def_name; 00306 char *__color; 00307 char *__legend; 00308 bool __stacked; 00309 00310 mutable char *__string; 00311 }; 00312 00313 class RRDGraphDefinition 00314 { 00315 public: 00316 RRDGraphDefinition(const char *name, RRDDefinition *rrd_def, 00317 const char *title, const char *vertical_label, 00318 std::vector<RRDGraphDataDefinition> &def, 00319 std::vector<RRDGraphElement *> &elements, 00320 time_t start = -600, time_t end = -10, unsigned int step = 10, 00321 unsigned int update_interval = 10, bool slope_mode = false); 00322 RRDGraphDefinition(const RRDGraphDefinition &other); 00323 ~RRDGraphDefinition(); 00324 00325 void set_filename(const char *filename); 00326 const char ** get_argv(size_t &argc) const; 00327 00328 00329 /** Get graph definition name. @return graph definition name */ 00330 const char * get_name() const { return __name; } 00331 /** Get RRD definition. @return RRD definition */ 00332 const RRDDefinition * get_rrd_def() const { return __rrd_def; } 00333 /** Get start time. @return start time */ 00334 time_t get_start() const { return __start; } 00335 /** Get end time. @return end time */ 00336 time_t get_end() const { return __end; } 00337 /** Get step size. @return step size */ 00338 unsigned int get_step() const { return __step; } 00339 /** Get title. @return tile */ 00340 const char * get_title() const { return __title; } 00341 /** Get vertical label. @return vertical label */ 00342 const char * get_vertical_label() const { return __vertical_label; } 00343 /** Get update interval. @return update interval */ 00344 const unsigned int get_update_interval() const { return __update_interval; } 00345 /** Get slope moe. @return slope mode */ 00346 const bool get_slope_mode() const { return __slope_mode; } 00347 /** Get definitions. @return definitions */ 00348 const std::vector<RRDGraphDataDefinition> & get_defs() const { return __defs; } 00349 /** Get graph elements. @return graph elements */ 00350 const std::vector<RRDGraphElement *> & get_elements() const 00351 { return __elements; } 00352 /** Get line width. @return line width. */ 00353 unsigned int get_width() const { return __width; } 00354 /** Get fonts. @return fonts */ 00355 const std::vector<const char *> get_fonts() const { return __fonts; } 00356 /** Get filename. @return filename */ 00357 const char * get_filename() const { return __filename; } 00358 00359 private: 00360 char *__name; 00361 const RRDDefinition *__rrd_def; 00362 const time_t __start; 00363 const time_t __end; 00364 unsigned int __step; 00365 char *__title; 00366 char *__vertical_label; 00367 const unsigned int __update_interval; 00368 const bool __slope_mode; 00369 std::vector<RRDGraphDataDefinition> __defs; 00370 std::vector<RRDGraphElement *> __elements; 00371 unsigned int __width; 00372 char *__width_s; 00373 char *__start_s; 00374 char *__end_s; 00375 char *__step_s; 00376 std::vector<const char *> __fonts; 00377 char *__filename; 00378 mutable size_t __argc; 00379 mutable const char **__argv; 00380 }; 00381 00382 } // end namespace fawkes 00383 00384 #endif