summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1b2b58c)
raw | patch | inline | side by side (parent: 1b2b58c)
author | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 24 Jul 2008 09:53:36 +0000 (11:53 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Thu, 24 Jul 2008 09:53:36 +0000 (11:53 +0200) |
If set to `true' (the default) RRD files will be created if they don't
exist.
exist.
src/collectd.conf.in | patch | blob | history | |
src/rrdcached.c | patch | blob | history |
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 740f76f3df6f5607646eb0bf3c5e1a9337be8c1a..462e2f8be210d35c3577be031e5e9dad580bc862 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
#<Plugin rrdcached>
# DaemonAddress "unix:/tmp/rrdcached.sock"
# DataDir "@prefix@/var/lib/@PACKAGE_NAME@/rrd"
+# CreateFiles true
#</Plugin>
#<Plugin rrdtool>
diff --git a/src/rrdcached.c b/src/rrdcached.c
index fef78ce42cad94cc8d640b5df6947d330d84a4fd..ab2484b0d59ccc43c975dfa7d4f5383a763bfb95 100644 (file)
--- a/src/rrdcached.c
+++ b/src/rrdcached.c
#include "collectd.h"
#include "plugin.h"
#include "common.h"
+#include "utils_rrdcreate.h"
#include <rrd_client.h>
static const char *config_keys[] =
{
"DaemonAddress",
- "DataDir"
+ "DataDir",
+ "CreateFiles"
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
static char *datadir = NULL;
static char *daemon_address = NULL;
+static int config_create_files = 1;
+static rrdcreate_config_t rrdcreate_config =
+{
+ /* stepsize = */ 0,
+ /* heartbeat = */ 0,
+ /* rrarows = */ 1200,
+ /* xff = */ 0.1,
+
+ /* timespans = */ NULL,
+ /* timespans_num = */ 0,
+
+ /* consolidation_functions = */ NULL,
+ /* consolidation_functions_num = */ 0
+};
static int value_list_to_string (char *buffer, int buffer_len,
const data_set_t *ds, const value_list_t *vl)
return (1);
}
}
+ else if (strcasecmp ("CreateFiles", key) == 0)
+ {
+ if ((strcasecmp ("true", value) == 0)
+ || (strcasecmp ("yes", value) == 0)
+ || (strcasecmp ("on", value) == 0))
+ config_create_files = 1;
+ else
+ config_create_files = 0;
+ }
else
{
return (-1);
values_array[0] = values;
values_array[1] = NULL;
- /* TODO: Check if the file exists. */
+ if (config_create_files != 0)
+ {
+ struct stat statbuf;
+
+ status = stat (filename, &statbuf);
+ if (status != 0)
+ {
+ if (errno != ENOENT)
+ {
+ char errbuf[1024];
+ ERROR ("rrdcached plugin: stat (%s) failed: %s",
+ filename, sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (-1);
+ }
+
+ status = cu_rrd_create_file (filename, ds, vl, &rrdcreate_config);
+ if (status != 0)
+ {
+ ERROR ("rrdcached plugin: cu_rrd_create_file (%s) failed.",
+ filename);
+ return (-1);
+ }
+ }
+ }
status = rrdc_connect (daemon_address);
if (status != 0)