]> git.ipfire.org Git - collecty.git/commitdiff
module: Define some default RRAs
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 28 Sep 2025 10:06:18 +0000 (10:06 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 28 Sep 2025 10:06:18 +0000 (10:06 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/module.c
src/daemon/module.h

index d3c950fc23c9ebdc6286a67daac93b5c6d836844..4c4aebc4c1b8e2574af63b65ba4c5d200a08fd3c 100644 (file)
 // Interval after which the heartbeat function is being called again
 #define HEARTBEAT (STEPSIZE * 1000000) // usecs
 
+// XXX We need to check whether it is a good idea to hardcode this here
+#define XFF 0.1
+
+// Define some default RRAs
+static const collecty_rrd_rra default_rras[] = {
+       // Keep AVERAGE/MIN/MAX with a one minute resolution for two weeks
+       { "AVERAGE", "1m", "14d", },
+       { "MIN",     "1m", "14d", },
+       { "MAX",     "1m", "14d", },
+
+       // After that, keep a one hour resolution for the next 18 months
+       { "AVERAGE", "1h", "18M", },
+       { "MIN",     "1h", "18M", },
+       { "MAX",     "1h", "18M", },
+
+       // Finally, keep a one day resolution for ten years
+       { "AVERAGE", "1d", "10y", },
+       { "MIN",     "1d", "10y", },
+       { "MAX",     "1d", "10y", },
+
+       { NULL },
+};
+
 struct collecty_module {
        collecty_ctx* ctx;
        int nrefs;
@@ -305,6 +328,20 @@ static int collecty_module_create_database(collecty_module* self, const char* pa
                        goto ERROR;
        }
 
+       // Add all default round-robin archives
+       for (const collecty_rrd_rra* rra = default_rras; rra->type; rra++) {
+               r = collecty_args_push(args, "RRA:%s:%.2f:%s:%s", rra->type, XFF, rra->steps, rra->rows);
+               if (r < 0)
+                       goto ERROR;
+       }
+
+       // Add all custom round-robin archives
+       for (const collecty_rrd_rra* rra = self->methods->rrd_rras; rra->type; rra++) {
+               r = collecty_args_push(args, "RRA:%s:%.2f:%s:%s", rra->type, XFF, rra->steps, rra->rows);
+               if (r < 0)
+                       goto ERROR;
+       }
+
        // Dump all arguments
        r = collecty_args_dump(args);
        if (r < 0)
index e6b56017c8a404dc0d499cef124436583994a54c..06789918b08d14ed92b536571b74fed2a0b142c3 100644 (file)
@@ -26,7 +26,8 @@ typedef struct collecty_module collecty_module;
 #include "ctx.h"
 #include "daemon.h"
 
-#define MAX_FIELDS 64
+#define MAX_DS 64
+#define MAX_RRA 8
 
 typedef struct collecty_rrd_ds {
        // Field
@@ -40,11 +41,23 @@ typedef struct collecty_rrd_ds {
        int max;
 } collecty_rrd_ds;
 
+typedef struct collecty_rrd_rra {
+       // Type
+       const char* type;
+
+       // Steps
+       const char* steps;
+
+       // Rows
+       const char* rows;
+} collecty_rrd_rra;
+
 typedef struct collecty_module_methods {
        const char* name;
 
        // RRD Schema
-       collecty_rrd_ds rrd_dss[MAX_FIELDS];
+       collecty_rrd_ds rrd_dss[MAX_DS];
+       collecty_rrd_rra rrd_rras[MAX_RRA];
 
        // Init
        int (*init)(collecty_ctx* ctx);