]> git.ipfire.org Git - telemetry.git/commitdiff
module: Define all DEFs and VDEFs for any imported modules
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Oct 2025 17:17:07 +0000 (17:17 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Oct 2025 17:17:07 +0000 (17:17 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/module.c

index db7e06cfb22a21f2aa7120e201144e8315642641..fc21b83dd7204b32a52aa8dcc9b03d85fb8f6882 100644 (file)
@@ -370,6 +370,65 @@ int collecty_module_commit(collecty_module* self,
        return 0;
 }
 
+static int collecty_module_render_add_DEF(collecty_module* self,
+               collecty_args* args, const char* path, const collecty_rrd_ds* ds, const char* object) {
+       char field[NAME_MAX];
+       int r;
+
+       // Append the object to the field name so that we can load multiple RRD of the same module
+       if (object) {
+               r = snprintf(field, sizeof(field), "%s_%s", ds->field, object);
+               if (r < 0)
+                       return -errno;
+       } else {
+               r = snprintf(field, sizeof(field), "%s", ds->field);
+               if (r < 0)
+                       return -errno;
+       }
+
+       // Add the classic DEF line
+       r = collecty_args_push(args, "DEF:%s=%s:%s:AVERAGE", field, path, ds->field);
+       if (r < 0)
+               return r;
+
+       // Add VDEF for LAST
+       r = collecty_args_push(args, "VDEF:%s_cur=%s,LAST", field, field);
+       if (r < 0)
+               return r;
+
+       // Add VDEF for AVERAGE
+       r = collecty_args_push(args, "VDEF:%s_avg=%s,AVERAGE", field, field);
+       if (r < 0)
+               return r;
+
+       // Add VDEF for MAXIMUM
+       r = collecty_args_push(args, "VDEF:%s_max=%s,MAXIMUM", field, field);
+       if (r < 0)
+               return r;
+
+       // Add VDEF for MINIMUM
+       r = collecty_args_push(args, "VDEF:%s_min=%s,MINIMUM", field, field);
+       if (r < 0)
+               return r;
+
+       return 0;
+}
+
 int collecty_module_render(collecty_module* self, collecty_args* args, const char* object) {
+       char path[PATH_MAX];
+       int r;
+
+       // Determine the path to the RRD file
+       r = collecty_module_path(self, object, path);
+       if (r < 0)
+               return r;
+
+       // Add all data sources
+       for (const collecty_rrd_ds* ds = self->methods->rrd_dss; ds->field; ds++) {
+               r = collecty_module_render_add_DEF(self, args, path, ds, object);
+               if (r < 0)
+                       return r;
+       }
+
        return 0;
 }