#include "proc.h"
+int collecty_proc_read_meminfo(collecty_ctx* ctx, collecty_proc_meminfo* meminfo) {
+ unsigned long v;
+ FILE* f = NULL;
+ char k[64];
+ int r;
+
+ // Open /proc/meminfo
+ f = fopen("/proc/meminfo", "r");
+ if (!f)
+ return -errno;
+
+ // Read line by line
+ for (;;) {
+ r = fscanf(f, "%63s %lu kB\n", k, &v);
+ if (r < 0)
+ break;
+
+ // Skip any lines that could not be parsed
+ if (r < 2)
+ continue;
+
+ // Convert the value from kB into Bytes
+ v *= 1024;
+
+ // Store the values
+ if (strcmp("MemTotal:", k) == 0)
+ meminfo->mem_total = v;
+ else if (strcmp("MemFree:", k) == 0)
+ meminfo->mem_free = v;
+ else if (strcmp("MemAvailable:", k) == 0)
+ meminfo->mem_available = v;
+ else if (strcmp("Cached:", k) == 0)
+ meminfo->cached = v;
+ else if (strcmp("Buffers:", k) == 0)
+ meminfo->buffers = v;
+ else if (strcmp("Active:", k) == 0)
+ meminfo->active = v;
+ else if (strcmp("Inactive:", k) == 0)
+ meminfo->inactive = v;
+ else if (strcmp("Active(anon):", k) == 0)
+ meminfo->active_anon = v;
+ else if (strcmp("Inactive(anon):", k) == 0)
+ meminfo->inactive_anon = v;
+ else if (strcmp("Active(file):", k) == 0)
+ meminfo->active_file = v;
+ else if (strcmp("Inactive(file):", k) == 0)
+ meminfo->inactive_file = v;
+ else if (strcmp("SwapTotal:", k) == 0)
+ meminfo->swap_total = v;
+ else if (strcmp("SwapFree:", k) == 0)
+ meminfo->swap_free = v;
+ else if (strcmp("Shmem:", k) == 0)
+ meminfo->shmem = v;
+ else if (strcmp("Slab:", k) == 0)
+ meminfo->slab = v;
+ else if (strcmp("SReclaimable:", k) == 0)
+ meminfo->sreclaimable = v;
+ else if (strcmp("SUnreclaim:", k) == 0)
+ meminfo->sunreclaim = v;
+ }
+
+ // Success
+ r = 0;
+
+ // Cleanup
+ if (f)
+ fclose(f);
+
+ return r;
+}
+
static int collecty_proc_read_stat_line(collecty_ctx* ctx,
const char* tag, char* line, unsigned long* fields, size_t max_fields) {
char* p = NULL;
--- /dev/null
+/*#############################################################################
+# #
+# 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 "memory.h"
+
+static int memory_collect(collecty_ctx* ctx, collecty_source* source) {
+ collecty_proc_meminfo meminfo = {};
+ int r;
+
+ // Read all values from /proc/meminfo
+ r = collecty_proc_read_meminfo(ctx, &meminfo);
+ if (r < 0)
+ return r;
+
+ // Submit the values
+ return collecty_source_submit(source, NULL,
+ "%lu:%lu:%lu:%lu:%lu:%lu:%lu:%lu:%lu:%lu:%lu:%lu:%lu:%lu:%lu:%lu:%lu",
+ meminfo.mem_total, meminfo.mem_free, meminfo.mem_available,
+ meminfo.cached, meminfo.buffers, meminfo.active, meminfo.inactive,
+ meminfo.active_anon, meminfo.inactive_anon, meminfo.active_file,
+ meminfo.inactive_file, meminfo.shmem, meminfo.slab, meminfo.sreclaimable,
+ meminfo.sunreclaim, meminfo.swap_total, meminfo.swap_free);
+}
+
+const collecty_source_impl memory_source = {
+ .name = "memory",
+
+ // RRD Data Sources
+ .rrd_dss = {
+ // Memory
+ { "mem_total", "GAUGE", 0, -1, },
+ { "mem_free", "GAUGE", 0, -1, },
+ { "mem_available", "GAUGE", 0, -1, },
+ { "cached", "GAUGE", 0, -1, },
+ { "buffers", "GAUGE", 0, -1, },
+ { "active", "GAUGE", 0, -1, },
+ { "inactive", "GAUGE", 0, -1, },
+ { "active_anon", "GAUGE", 0, -1, },
+ { "inactive_anon", "GAUGE", 0, -1, },
+ { "active_file", "GAUGE", 0, -1, },
+ { "inactive_file", "GAUGE", 0, -1, },
+ { "shmem", "GAUGE", 0, -1, },
+ { "slab", "GAUGE", 0, -1, },
+ { "sreclaimable", "GAUGE", 0, -1, },
+ { "sunreclaimable", "GAUGE", 0, -1, },
+
+ // Swap
+ { "swap_total", "GAUGE", 0, -1, },
+ { "swap_free", "GAUGE", 0, -1, },
+ { NULL },
+ },
+
+ // Methods
+ .collect = memory_collect,
+};
--- /dev/null
+/*#############################################################################
+# #
+# 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_MEMORY_H
+#define COLLECTY_SOURCE_MEMORY_H
+
+#include "../source.h"
+
+extern const collecty_source_impl memory_source;
+
+#endif /* COLLECTY_SOURCE_MEMORY_H */