]> git.ipfire.org Git - collecty.git/commitdiff
loadavg: Actually read the loadavg
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 27 Sep 2025 14:48:49 +0000 (14:48 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 27 Sep 2025 14:48:49 +0000 (14:48 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/daemon/modules/loadavg.c

index 276ea37a56e886fd153102b32fd4760c15aba0a3..dcd463ad3367e04a91781275105a056e0ada7a52 100644 (file)
 #                                                                             #
 #############################################################################*/
 
+#include <stdlib.h>
+
 #include "../ctx.h"
+#include "../module.h"
 #include "loadavg.h"
 
+static int loadavg_collect(collecty_ctx* ctx, collecty_module* module) {
+       double loadavg[3];
+       int r;
+
+       // Fetch the current loadavg
+       r = getloadavg(loadavg, 3);
+       if (r < 0)
+               return r;
+
+       // Submit the values
+       return collecty_module_submit(module, NULL,
+               "%f:%f:%f", loadavg[0], loadavg[1], loadavg[2]);
+}
+
 const collecty_module_methods loadavg_module = {
-       .name = "loadavg",
+       .name    = "loadavg",
+       .collect = loadavg_collect,
 };