#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
#include <rrd.h>
return collecty_daemon_submit(self->daemon, self, object, value);
}
+static int collecty_module_create_database(collecty_module* self, const char* path) {
+ DEBUG(self->ctx, "Creating database for %s at %s\n", collecty_module_name(self), path);
+
+ // XXX TODO
+
+ return 0;
+}
+
/*
Called to write all collected samples to disk
*/
int collecty_module_commit(collecty_module* self,
const char* object, unsigned int num_samples, const char** samples) {
+ struct stat st = {};
char path[PATH_MAX];
int r;
if (r < 0)
return r;
+ // Try to stat() the file
+ r = stat(path, &st);
+ if (r < 0) {
+ switch (errno) {
+ case ENOENT:
+ r = collecty_module_create_database(self, path);
+ if (r < 0)
+ return r;
+ break;
+
+ default:
+ return -errno;
+ }
+ }
+
// Write the samples
r = rrd_update_r(path, NULL, num_samples, samples);
if (r < 0) {