From: Michael Tremer Date: Sun, 5 Oct 2025 14:37:12 +0000 (+0000) Subject: sources: Add source for the system's uptime X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d80f9954216ff21954dcaa26e798228db1c60c83;p=collecty.git sources: Add source for the system's uptime Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index dbd32b5..309135e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/daemon/sources.c b/src/daemon/sources.c index 51b0a99..a979f91 100644 --- a/src/daemon/sources.c +++ b/src/daemon/sources.c @@ -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 index 0000000..69e64bb --- /dev/null +++ b/src/daemon/sources/uptime.c @@ -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 . # +# # +#############################################################################*/ + +#include +#include + +#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 index 0000000..c953b59 --- /dev/null +++ b/src/daemon/sources/uptime.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_UPTIME_H +#define COLLECTY_SOURCE_UPTIME_H + +#include "../source.h" + +extern const collecty_source_impl uptime_source; + +#endif /* COLLECTY_SOURCE_UPTIME_H */