23 #include "rrd_thread.h" 25 #include <core/exceptions/system.h> 26 #include <core/threading/scoped_rwlock.h> 27 #include <utils/misc/string_conversions.h> 28 #include <utils/system/file.h> 64 __cfg_graph_interval = 30.;
66 __cfg_graph_interval =
config->
get_float(
"/plugins/rrd/graph_interval");
94 std::vector<fawkes::RRDGraphDefinition *>::iterator g;
95 for (g = __graphs.begin(); g != __graphs.end(); ++g) {
97 const char **argv = (*g)->get_argv(argc);
105 rrd_info_t *i = rrd_graph_v(argc, (
char **)argv);
107 throw Exception(
"Creating graph %s (for RRD %s) failed: %s",
108 (*g)->get_name(), (*g)->get_rrd_def()->get_name(),
120 if (asprintf(&filename,
"%s/%s.rrd",
".", rrd_def->
get_name()) == -1) {
128 std::string size_s = StringConversions::to_string(rrd_def->
get_step_sec());
132 size_t rrd_argc = 6 + rrd_def->
get_ds().size() + rrd_def->
get_rra().size();
133 const char *rrd_argv[rrd_argc];
135 rrd_argv[i++] =
"create";
137 rrd_argv[i++] =
"--step";
138 rrd_argv[i++] = size_s.c_str();
139 rrd_argv[i++] =
"--start";
142 std::vector<RRDDataSource>::const_iterator d;
143 for (d = rrd_def->
get_ds().begin();
144 d != rrd_def->
get_ds().end() && i < rrd_argc;
147 rrd_argv[i++] = d->to_string();
150 std::vector<RRDArchive>::const_iterator a;
151 for (a = rrd_def->
get_rra().begin();
152 a != rrd_def->
get_rra().end() && i < rrd_argc;
155 rrd_argv[i++] = a->to_string();
165 if (rrd_create(i, (
char **)rrd_argv) == -1) {
166 throw Exception(
"Creating RRD %s failed: %s",
167 rrd_def->
get_name(), rrd_get_error());
173 for (r = __rrds.begin(); r != __rrds.end(); ++r) {
174 if (strcmp((*r)->get_name(), rrd_def->
get_name()) == 0) {
175 throw Exception(
"RRD with name %s has already been registered",
181 __rrds.push_back(rrd_def);
189 for (r = __rrds.begin(); r != __rrds.end(); ++r) {
190 if (strcmp((*r)->get_name(), rrd_def->
get_name()) == 0) {
197 bool graphs_modified =
false;
199 graphs_modified =
false;
201 for (g = __graphs.begin(); g != __graphs.end(); ++g) {
202 if (strcmp((*g)->get_rrd_def()->get_name(), rrd_def->
get_name()) == 0) {
204 graphs_modified =
true;
208 }
while (graphs_modified);
216 if (asprintf(&filename,
"%s/%s.png",
".",
226 for (g = __graphs.begin(); g != __graphs.end(); ++g) {
227 if (strcmp((*g)->get_name(), rrd_graph_def->
get_name()) == 0) {
228 throw Exception(
"RRD graph with name %s has already been registered",
232 __graphs.push_back(rrd_graph_def);
240 std::vector<RRDDefinition *>::const_iterator d;
241 for (d = __rrds.begin(); d != __rrds.end(); ++d) {
243 if (strcmp(rrd_name, rrd_def->
get_name()) == 0) {
246 va_start(arg, format);
247 if (vasprintf(&data, format, arg) == -1) {
256 const char *rrd_argv[rrd_argc];
258 rrd_argv[i++] =
"update";
260 rrd_argv[i++] = data;
268 if (rrd_update(i, (
char **)rrd_argv) == -1) {
270 throw Exception(
"Failed to update RRD %s: %s", rrd_name, rrd_get_error());
278 throw Exception(
"No RRD named %s registered", rrd_name);
long int time_sec_to_usec(double sec)
Convert seconds to micro seconds.
const char * get_name() const
Get graph definition name.
Fawkes library namespace.
RefPtr< ReadWriteLock > rwlock() const
Get access to the internal read/write lock.
virtual const fawkes::RWLockVector< fawkes::RRDDefinition * > & get_rrds() const
Get RRDs.
virtual void add_rrd(fawkes::RRDDefinition *rrd_def)
Add RRD.
void set_filename(const char *filename)
Set filename.
const std::vector< RRDDataSource > & get_ds() const
Get data sources.
Thread class encapsulation of pthreads.
void set_prepfin_conc_loop(bool concurrent=true)
Set concurrent execution of prepare_finalize() and loop().
virtual void finalize()
Finalize the thread.
void wait_systime()
Wait until minimum loop time has been reached in real time.
unsigned int get_step_sec() const
Get step size in sec.
Clock * clock
By means of this member access to the clock is given.
virtual void loop()
Code to execute in the thread.
virtual void add_graph(fawkes::RRDGraphDefinition *rrd_graph_def)
Add graph.
virtual ~RRDThread()
Destructor.
virtual void remove_rrd(fawkes::RRDDefinition *rrd_def)
Remove RRD.
Base class for exceptions in Fawkes.
Class representing a graph definition.
void set_filename(const char *filename)
Set filename.
const std::vector< RRDArchive > & get_rra() const
Get RRD archives.
virtual const fawkes::RWLockVector< fawkes::RRDGraphDefinition * > & get_graphs() const
Get graphs.
Thread aspect provide a new aspect.
void mark_start()
Mark start of loop.
const char * get_name() const
Get name.
virtual void init()
Initialize the thread.
const char * get_filename() const
Get file name.
Configuration * config
This is the Configuration member used to access the configuration.
virtual float get_float(const char *path)=0
Get value from configuration which is of type float.
bool get_recreate() const
Check recreation flag.
System ran out of memory and desired operation could not be fulfilled.
void set_rrd_manager(RRDManager *rrd_manager)
Set RRD manager.
void generate_graphs()
Generate all graphs.
virtual void add_data(const char *rrd_name, const char *format,...)
Add data.