]> git.ipfire.org Git - collecty.git/commitdiff
sources: Add PSI for memory
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 4 Oct 2025 12:47:00 +0000 (12:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 4 Oct 2025 12:47:00 +0000 (12:47 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/daemon/sources.c
src/daemon/sources/pressure-memory.c [new file with mode: 0644]
src/daemon/sources/pressure-memory.h [new file with mode: 0644]

index 6fc22a5ba28084340d5f882756f92c517f839ba3..649dcaa60e4c7941b0da4b3e750981b0d3127326 100644 (file)
@@ -134,6 +134,8 @@ dist_collectyd_SOURCES = \
        src/daemon/sources/loadavg.h \
        src/daemon/sources/pressure-cpu.c \
        src/daemon/sources/pressure-cpu.h \
+       src/daemon/sources/pressure-memory.c \
+       src/daemon/sources/pressure-memory.h \
        src/daemon/sources/processor.c \
        src/daemon/sources/processor.h \
        src/daemon/util.c \
index 7065584d24ab77fe67e56e12d94d818df8748f3a..2156ca2ff79cd6f1928058625bb03f1b69064770 100644 (file)
@@ -32,6 +32,7 @@
 #include "sources/contextswitches.h"
 #include "sources/loadavg.h"
 #include "sources/pressure-cpu.h"
+#include "sources/pressure-memory.h"
 #include "sources/processor.h"
 
 // Register all sources
@@ -40,6 +41,7 @@ static const collecty_source_impl* source_impls[] = {
        &contextswitches_source,
        &loadavg_source,
        &pressure_cpu_source,
+       &pressure_memory_source,
        &processor_source,
        NULL,
 };
diff --git a/src/daemon/sources/pressure-memory.c b/src/daemon/sources/pressure-memory.c
new file mode 100644 (file)
index 0000000..13e0456
--- /dev/null
@@ -0,0 +1,62 @@
+/*#############################################################################
+#                                                                             #
+# collecty - A system statistics collection daemon for IPFire                 #
+# Copyright (C) 2025 IPFire Development Team                                  #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include "../ctx.h"
+#include "../proc.h"
+#include "../source.h"
+#include "pressure-memory.h"
+
+static int pressure_memory_collect(collecty_ctx* ctx, collecty_source* source) {
+       collecty_pressure_stats stats = {};
+       int r;
+
+       // Read all values from /proc/pressure/memory
+       r = collecty_proc_read_pressure(ctx, "memory", &stats);
+       if (r < 0)
+               return r;
+
+       // Submit the values
+       return collecty_source_submit(source, NULL, "%.2f:%.2f:%.2f:%lu:%.2f:%.2f:%.2f:%lu",
+               stats.some.avg10, stats.some.avg60, stats.some.avg300, stats.some.total,
+               stats.full.avg10, stats.full.avg60, stats.full.avg300, stats.full.total);
+}
+
+const collecty_source_impl pressure_memory_source = {
+       .name    = "pressure-memory",
+
+       // RRD Data Sources
+       .rrd_dss = {
+               // some
+               { "some_avg10",  "GAUGE", 0, 100, },
+               { "some_avg60",  "GAUGE", 0, 100, },
+               { "some_avg300", "GAUGE", 0, 100, },
+               { "some_total",  "DERIVE", 0, -1, },
+
+               // full
+               { "full_avg10",  "GAUGE", 0, 100, },
+               { "full_avg60",  "GAUGE", 0, 100, },
+               { "full_avg300", "GAUGE", 0, 100, },
+               { "full_total",  "DERIVE", 0, -1, },
+               { NULL },
+       },
+
+       // Methods
+       .collect = pressure_memory_collect,
+};
diff --git a/src/daemon/sources/pressure-memory.h b/src/daemon/sources/pressure-memory.h
new file mode 100644 (file)
index 0000000..7b5b794
--- /dev/null
@@ -0,0 +1,28 @@
+/*#############################################################################
+#                                                                             #
+# collecty - A system statistics collection daemon for IPFire                 #
+# Copyright (C) 2025 IPFire Development Team                                  #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef COLLECTY_SOURCE_PRESSURE_MEMORY_H
+#define COLLECTY_SOURCE_PRESSURE_MEMORY_H
+
+#include "../source.h"
+
+extern const collecty_source_impl pressure_memory_source;
+
+#endif /* COLLECTY_SOURCE_PRESSURE_MEMORY_H */