return td_source_create_database(self, path, path);
}
+static int td_source_fetch_lastupdate(td_source* self, rrd_info_t* info, time_t* t) {
+ // Find last_update
+ for (; info; info = info->next) {
+ if (td_string_equals(info->key, "last_update")) {
+ if (info->type != RD_I_CNT)
+ return -ENOTSUP;
+
+ // Write the time
+ *t = info->value.u_cnt;
+ break;
+ }
+ }
+
+ return 0;
+}
+
/*
Called to write all collected samples to disk
*/
static int td_source_commit_samples(td_source* self,
const char* object, unsigned int num_samples, const char** samples) {
rrd_info_t* info = NULL;
+ time_t lastupdate = 0;
char path[PATH_MAX];
int r;
r = -errno;
goto ERROR;
}
- }
- // Migrate the RRD file
- r = td_source_migrate(self, path, info);
- if (r < 0)
- goto ERROR;
+ // If we could parse the metadata of the file we will do some more stuff
+ } else {
+ // Migrate the RRD file
+ r = td_source_migrate(self, path, info);
+ if (r < 0)
+ goto ERROR;
+
+ // Fetch lastupdate
+ r = td_source_fetch_lastupdate(self, info, &lastupdate);
+ if (r < 0)
+ goto ERROR;
+ }
// Write the samples
r = rrd_update_r(path, NULL, num_samples, samples);