]> git.ipfire.org Git - collecty.git/commitdiff
sources: Add source for the system's uptime
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 5 Oct 2025 14:37:12 +0000 (14:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 5 Oct 2025 14:37:12 +0000 (14:37 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/daemon/sources.c
src/daemon/sources/uptime.c [new file with mode: 0644]
src/daemon/sources/uptime.h [new file with mode: 0644]

index dbd32b575be57a5ea4a68168dc1c628fc108f6d6..309135e26cdbaaa0ec1a7fad812bceda744db5c6 100644 (file)
@@ -156,6 +156,8 @@ dist_collectyd_SOURCES = \
        src/daemon/sources/test-flapping.h \
        src/daemon/sources/test-stall.c \
        src/daemon/sources/test-stall.h \
+       src/daemon/sources/uptime.c \
+       src/daemon/sources/uptime.h \
        src/daemon/string.h \
        src/daemon/time.h \
        src/daemon/util.c \
index 51b0a99c344c11d708e5e4ecc337ea2f04db1bb6..a979f917f9e281774060ad59f97595a519082bd6 100644 (file)
@@ -40,6 +40,9 @@
 #include "sources/pressure-memory.h"
 #include "sources/processor.h"
 #include "sources/softirq.h"
+#include "sources/uptime.h"
+
+// Load test sources
 #include "sources/test-error.h"
 #include "sources/test-flapping.h"
 #include "sources/test-stall.h"
@@ -57,6 +60,7 @@ static const collecty_source_impl* source_impls[] = {
        &pressure_memory_source,
        &processor_source,
        &softirq_source,
+       &uptime_source,
 
        // Tests
        &test_error_source,
diff --git a/src/daemon/sources/uptime.c b/src/daemon/sources/uptime.c
new file mode 100644 (file)
index 0000000..69e64bb
--- /dev/null
@@ -0,0 +1,52 @@
+/*#############################################################################
+#                                                                             #
+# 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 <sys/sysinfo.h>
+
+#include "../ctx.h"
+#include "../source.h"
+#include "uptime.h"
+
+static int uptime_collect(collecty_ctx* ctx, collecty_source* source) {
+       struct sysinfo info = {};
+       int r;
+
+       // Fetch system information
+       r = sysinfo(&info);
+       if (r < 0)
+               return -errno;
+
+       // Submit the uptime
+       return collecty_source_submit(source, NULL, "%ld", info.uptime);
+}
+
+const collecty_source_impl uptime_source = {
+       .name    = "uptime",
+
+       // RRD Data Sources
+       .rrd_dss = {
+               { "uptime", "GAUGE", 0, -1, },
+               { NULL },
+       },
+
+       // Methods
+       .collect = uptime_collect,
+};
diff --git a/src/daemon/sources/uptime.h b/src/daemon/sources/uptime.h
new file mode 100644 (file)
index 0000000..c953b59
--- /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_UPTIME_H
+#define COLLECTY_SOURCE_UPTIME_H
+
+#include "../source.h"
+
+extern const collecty_source_impl uptime_source;
+
+#endif /* COLLECTY_SOURCE_UPTIME_H */