From: Michael Tremer Date: Sat, 4 Oct 2025 12:47:00 +0000 (+0000) Subject: sources: Add PSI for memory X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=001fc58560e4c2d77e2cbe0ba23b95e3335e152c;p=collecty.git sources: Add PSI for memory Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 6fc22a5..649dcaa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/daemon/sources.c b/src/daemon/sources.c index 7065584..2156ca2 100644 --- a/src/daemon/sources.c +++ b/src/daemon/sources.c @@ -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 index 0000000..13e0456 --- /dev/null +++ b/src/daemon/sources/pressure-memory.c @@ -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 . # +# # +#############################################################################*/ + +#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 index 0000000..7b5b794 --- /dev/null +++ b/src/daemon/sources/pressure-memory.h @@ -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 . # +# # +#############################################################################*/ + +#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 */