From: Michael Tremer Date: Wed, 22 Oct 2025 19:12:55 +0000 (+0000) Subject: source: Fetch the last update timestamp X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f0719c834410a0c2d1b58cb846fdd62e43c48920;p=telemetry.git source: Fetch the last update timestamp Signed-off-by: Michael Tremer --- diff --git a/src/daemon/source.c b/src/daemon/source.c index b19ad67..0099251 100644 --- a/src/daemon/source.c +++ b/src/daemon/source.c @@ -891,12 +891,29 @@ static int td_source_migrate(td_source* self, const char* path, rrd_info_t* info 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; @@ -920,12 +937,19 @@ static int td_source_commit_samples(td_source* self, 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);