--- /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 <errno.h>
+#include <mntent.h>
+#include <sys/statvfs.h>
+
+#include "../ctx.h"
+#include "../source.h"
+#include "df.h"
+
+static int df_collect(collecty_ctx* ctx, collecty_source* source) {
+ struct mntent* mountpoint = NULL;
+ struct statvfs stat = {};
+ FILE* f = NULL;
+ int r = 0;
+
+ // Open /proc/self/mounts
+ f = setmntent("/proc/self/mounts", "r");
+ if (!f) {
+ ERROR(ctx, "Failed to open /proc/self/mounts: %m\n");
+ r = -errno;
+ goto ERROR;
+ }
+
+ // Walk through all mountpoints
+ for (;;) {
+ // Fetch the next mountpoint
+ mountpoint = getmntent(f);
+ if (!mountpoint)
+ break;
+
+ // Ignore everything that is a virtually mounted device
+ if (*mountpoint->mnt_fsname != '/')
+ continue;
+
+ // Call statvfs() on the mountpoint
+ r = statvfs(mountpoint->mnt_dir, &stat);
+ if (r < 0) {
+ ERROR(ctx, "statvfs() on %s failed: %m\n", mountpoint->mnt_dir);
+ r = -errno;
+ goto ERROR;
+ }
+
+ // Determine the block size
+ size_t block_size = (stat.f_frsize) ? stat.f_frsize : stat.f_bsize;
+
+ // Submit stats
+ r = collecty_source_submit(source, mountpoint->mnt_dir, "%lu:%lu:%lu:%lu",
+ // used
+ (stat.f_blocks - stat.f_bfree) * block_size,
+ // free
+ stat.f_bfree * block_size,
+ // inodes used
+ stat.f_files - stat.f_ffree,
+ // inodes free
+ stat.f_ffree
+ );
+ if (r < 0)
+ return r;
+ }
+
+ERROR:
+ if (f)
+ endmntent(f);
+
+ return r;
+}
+
+const collecty_source_impl df_source = {
+ .name = "df",
+
+ // RRD Data Sources
+ .rrd_dss = {
+ { "bytes_used", "GAUGE", 0, -1, },
+ { "bytes_free", "GAUGE", 0, -1, },
+ { "inodes_used", "GAUGE", 0, -1, },
+ { "inodes_free", "GAUGE", 0, -1, },
+ { NULL },
+ },
+
+ // Methods
+ .collect = df_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_DF_H
+#define COLLECTY_SOURCE_DF_H
+
+#include "../source.h"
+
+extern const collecty_source_impl df_source;
+
+#endif /* COLLECTY_SOURCE_DF_H */