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,
58 : name_(strdup(name)),
60 heartbeat_(heartbeat),
63 rpn_expression_(NULL),
66 if (type_ == COMPUTE) {
68 "COMPUTE type for DS %s",
78 : name_(strdup(name)),
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)
172 throw OutOfMemoryException(
"Failed to create DS string for %s", name_);
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_);
401 const 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(),
588 throw OutOfMemoryException(
"Failed to create RRA string");
615 throw NotImplementedException(
"Invalid graph element");
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" :
"")
898 RRDDefinition * rrd_def,
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();