From 573507f935b1a026008536cb2107683eb236ad49 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Thu, 2 Oct 2025 17:17:07 +0000 Subject: [PATCH] module: Define all DEFs and VDEFs for any imported modules Signed-off-by: Michael Tremer --- src/daemon/module.c | 59 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/daemon/module.c b/src/daemon/module.c index db7e06c..fc21b83 100644 --- a/src/daemon/module.c +++ b/src/daemon/module.c @@ -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; } -- 2.47.3