24#include <core/exceptions/software.h>
25#include <core/exceptions/system.h>
26#include <plugins/rrd/aspect/rrd_descriptions.h>
27#include <plugins/rrd/aspect/rrd_manager.h>
28#include <utils/misc/string_conversions.h>
55 unsigned int heartbeat,
60 heartbeat_(heartbeat),
63 rpn_expression_(NULL),
68 "COMPUTE type for DS %s",
83 rpn_expression_(strdup(rpn_expression)),
92: name_(strdup(other.name_)),
94 heartbeat_(other.heartbeat_),
97 rpn_expression_(other.rpn_expression_ ? strdup(other.rpn_expression_) : 0),
110 free(rpn_expression_);
125 free(rpn_expression_);
127 rpn_expression_ = NULL;
128 name_ = strdup(other.name_);
130 heartbeat_ = other.heartbeat_;
133 if (other.rpn_expression_)
134 rpn_expression_ = strdup(other.rpn_expression_);
147 if (asprintf(&string_,
"DS:%s:COMPUTE:%s", name_, rpn_expression_) == -1) {
151 const char *type_string;
153 case COUNTER: type_string =
"COUNTER";
break;
154 case DERIVE: type_string =
"DERIVE";
break;
155 case ABSOLUTE: type_string =
"ABSOLUTE";
break;
156 default: type_string =
"GAUGE";
break;
163 snprintf(min_s, 32,
"%f", min_);
168 snprintf(max_s, 32,
"%f", max_);
170 if (asprintf(&string_,
"DS:%s:%s:%u:%s:%s", name_, type_string, heartbeat_, min_s, max_s)
197: cf_(cf), xff_(xff), steps_(steps), rows_(rows), string_(NULL)
205: cf_(rra.cf_), xff_(rra.xff_), steps_(rra.steps_), rows_(rra.rows_), string_(NULL)
240 const char *cf_string;
242 case MIN: cf_string =
"MIN";
break;
243 case MAX: cf_string =
"MAX";
break;
244 case LAST: cf_string =
"LAST";
break;
245 default: cf_string =
"AVERAGE";
break;
247 if (asprintf(&string_,
"RRA:%s:%f:%u:%u", cf_string, xff_, steps_, rows_) == -1) {
266 default:
return "AVERAGE";
break;
289 std::vector<RRDDataSource> &ds,
290 unsigned int step_sec,
292: name_(strdup(name)),
296 rra_(get_default_rra()),
312 std::vector<RRDDataSource> &ds,
313 std::vector<RRDArchive> & rra,
314 unsigned int step_sec,
316: name_(strdup(name)),
330: name_(strdup(other.name_)),
331 step_sec_(other.step_sec_),
332 recreate_(other.recreate_),
335 filename_(other.filename_ ? strdup(other.filename_) : 0),
355 name_ = strdup(other.name_);
356 step_sec_ = other.step_sec_;
357 recreate_ = other.recreate_;
361 filename_ = strdup(other.filename_);
401const std::vector<RRDArchive>
404 std::vector<RRDArchive> rv;
434 for (
size_t i = 0; i < ds_.size(); ++i) {
435 if (strcmp(ds_[i].
get_name(), ds_name) == 0)
439 throw Exception(
"Data source name %s not found", ds_name);
452 throw Exception(
"Graph definition %s: filename has already been set!", name_);
454 filename_ = strdup(filename);
467 throw Exception(
"RRD definition %s: RRD manager has already been set", name_);
469 rrd_manager_ = rrd_manager;
488 const char * ds_name)
489: name_(strdup(name)),
491 ds_name_(ds_name ? strdup(ds_name) : strdup(name)),
492 rpn_expression_(NULL),
503: name_(strdup(name)),
506 rpn_expression_(strdup(rpn_expression)),
516: name_(strdup(other.name_)),
517 rrd_def_(other.rrd_def_),
518 ds_name_(other.ds_name_ ? strdup(other.ds_name_) : NULL),
519 rpn_expression_(other.rpn_expression_ ? strdup(other.rpn_expression_) : 0),
533 free(rpn_expression_);
552 free(rpn_expression_);
555 rpn_expression_ = NULL;
556 name_ = strdup(other.name_);
557 rrd_def_ = other.rrd_def_;
559 ds_name_ = strdup(other.ds_name_);
560 if (other.rpn_expression_)
561 rpn_expression_ = other.rpn_expression_;
574 if (rpn_expression_) {
575 if (asprintf(&string_,
"CDEF:%s=%s", name_, rpn_expression_) == -1) {
581 if (asprintf(&string_,
585 rrd_def_->
get_ds(ds_index).get_name(),
631: def_name_(strdup(def_name)), cf_(cf), format_(strdup(format)), string_(NULL)
639: def_name_(strdup(other.def_name_)), cf_(other.cf_), format_(strdup(other.format_)), string_(NULL)
669 def_name_ = strdup(g.def_name_);
671 format_ = strdup(g.format_);
706: def_name_(strdup(def_name)),
708 color_(strdup(color)),
709 legend_(strdup(legend)),
719: def_name_(strdup(other.def_name_)),
720 width_(other.width_),
721 color_(strdup(other.color_)),
722 legend_(strdup(other.legend_)),
723 stacked_(other.stacked_),
758 def_name_ = strdup(g.def_name_);
760 color_ = strdup(g.color_);
761 legend_ = strdup(g.legend_);
762 stacked_ = g.stacked_;
771 if (asprintf(&string_,
777 stacked_ ?
":STACK" :
"")
801: def_name_(strdup(def_name)),
802 color_(strdup(color)),
803 legend_(strdup(legend)),
813: def_name_(strdup(other.def_name_)),
814 color_(strdup(other.color_)),
815 legend_(strdup(other.legend_)),
816 stacked_(other.stacked_),
851 def_name_ = strdup(g.def_name_);
852 color_ = strdup(g.color_);
853 legend_ = strdup(g.legend_);
854 stacked_ = g.stacked_;
863 if (asprintf(&string_,
"AREA:%s#%s:%s%s", def_name_, color_, legend_, stacked_ ?
":STACK" :
"")
900 const char * vertical_label,
901 std::vector<RRDGraphDataDefinition> &def,
902 std::vector<RRDGraphElement *> & elements,
906 unsigned int update_interval,
908: name_(strdup(name)),
913 title_(strdup(title)),
914 vertical_label_(strdup(vertical_label)),
915 update_interval_(update_interval),
916 slope_mode_(slope_mode),
923 fonts_.push_back(
"LEGEND:10:");
924 fonts_.push_back(
"UNIT:8:");
925 fonts_.push_back(
"TITLE:12:");
926 fonts_.push_back(
"AXIS:8:");
938: name_(strdup(other.name_)),
939 rrd_def_(other.rrd_def_),
940 start_(other.start_),
943 title_(strdup(other.title_)),
944 vertical_label_(strdup(other.vertical_label_)),
945 update_interval_(other.update_interval_),
946 slope_mode_(other.slope_mode_),
948 width_(other.width_),
949 fonts_(other.fonts_),
950 filename_(strdup(other.filename_))
952 std::vector<RRDGraphElement *>::const_iterator i;
953 for (i = other.elements_.begin(); i != other.elements_.end(); ++i) {
954 elements_.push_back((*i)->clone());
977 free(vertical_label_);
984 std::vector<RRDGraphElement *>::iterator i;
985 for (i = elements_.begin(); i != elements_.end(); ++i) {
1000 throw Exception(
"Graph definition for RRD %s: filename has already been set!",
1003 filename_ = strdup(filename);
1014 if (argv_ == NULL) {
1017 argc_ = 16 + fonts_.size() * 2 + defs_.size() + elements_.size();
1018 argv_ = (
const char **)malloc(argc_ *
sizeof(
char *));
1020 argv_[i++] =
"graph";
1021 argv_[i++] = filename_;
1022 argv_[i++] =
"--disable-rrdtool-tag";
1023 argv_[i++] =
"--width";
1024 argv_[i++] = width_s_;
1025 argv_[i++] =
"--start";
1026 argv_[i++] = start_s_;
1027 argv_[i++] =
"--end";
1028 argv_[i++] = end_s_;
1029 argv_[i++] =
"--step";
1030 argv_[i++] = step_s_;
1031 argv_[i++] =
"--title";
1032 argv_[i++] = title_;
1033 argv_[i++] =
"--vertical-label";
1035 if (strcmp(vertical_label_,
"") == 0) {
1038 argv_[i++] = vertical_label_;
1042 argv_[i++] =
"--slope-mode";
1044 std::vector<const char *>::const_iterator f;
1045 for (f = fonts_.begin(); f != fonts_.end(); ++f) {
1046 argv_[i++] =
"--font";
1050 std::vector<RRDGraphDataDefinition>::const_iterator d;
1051 for (d = defs_.begin(); d != defs_.end(); ++d) {
1052 argv_[i++] = d->to_string();
1055 std::vector<RRDGraphElement *>::const_iterator e;
1056 for (e = elements_.begin(); e != elements_.end(); ++e) {
1057 argv_[i++] = (*e)->to_string();
Base class for exceptions in Fawkes.
Expected parameter is missing.
Called method has not been implemented.
System ran out of memory and desired operation could not be fulfilled.
RRDArchive(ConsolidationFunction cf, float xff, unsigned int steps, unsigned int rows)
Constructor.
const char * to_string() const
Get string representation.
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.
~RRDDataSource()
Destructor.
@ ABSOLUTE
Absolute value.
const char * to_string() const
Get string reprensetation.
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.
void set_rrd_manager(RRDManager *rrd_manager)
Set RRD manager.
const char * get_filename() const
Get file name.
void set_filename(const char *filename)
Set filename.
~RRDDefinition()
Destructor.
RRDDefinition(const char *name, std::vector< RRDDataSource > &ds, unsigned int step_sec=10, bool recreate=false)
Constructor with default RRAs.
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.
const std::vector< RRDDataSource > & get_ds() const
Get data sources.
virtual const char * to_string() const
Create string representation.
RRDGraphArea(const char *def_name, const char *color, const char *legend, bool stacked=false)
Constructor.
virtual ~RRDGraphArea()
Destructor.
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.
RRDGraphDataDefinition & operator=(const RRDGraphDataDefinition &rra)
Assignment operator.
const char * to_string() const
Create string representation.
~RRDGraphDataDefinition()
Destructor.
Class representing a graph definition.
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.
const char ** get_argv(size_t &argc) const
Get argument array and size.
~RRDGraphDefinition()
Destructor.
void set_filename(const char *filename)
Set filename.
virtual const char * to_string() const
Create string representation.
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 const char * to_string() const
Create string representation.
virtual const char * to_string() const
Create string representation.
RRDGraphLine & operator=(const RRDGraphLine &g)
Assignment operator.
virtual ~RRDGraphLine()
Destructor.
RRDGraphLine(const char *def_name, float width, const char *color, const char *legend, bool stacked=false)
Constructor.
Interface for a RRD connection creator.
virtual void remove_rrd(RRDDefinition *rrd_def)=0
Remove RRD.
static std::string to_string(unsigned int i)
Convert unsigned int value to a string.
Fawkes library namespace.