src/daemon/graphs/loadavg.h \
src/daemon/graphs/processor.c \
src/daemon/graphs/processor.h \
+ src/daemon/graphs/uptime.c \
+ src/daemon/graphs/uptime.h \
src/daemon/i18n.h \
src/daemon/logging.c \
src/daemon/logging.h \
#define BLACK "#000000"
#define WHITE "#ffffff"
+#define GREY "#9e9e9e"
#define RED "#f44336"
#define LIGHT_RED "#cc0033"
#define YELLOW "#ffeb3b"
Define some colours with a special meaning...
*/
+// Default - If something does not need to have a special meaning
+#define DEFAULT GREY
+
// Limit - When there is a ceiling to resource usage
#define LIMIT RED
#include "graphs/contextswitches.h"
#include "graphs/loadavg.h"
#include "graphs/processor.h"
+#include "graphs/uptime.h"
// Register all graphs
static const collecty_graph_impl* graph_impls[] = {
&contextswitches_graph,
&loadavg_graph,
&processor_graph,
+ &uptime_graph,
NULL,
};
#define PRINT_FLOAT(args, field, ...) PRINT(args, field, FLOAT __VA_ARGS__)
#define PRINT_LARGE_FLOAT(args, field, ...) PRINT(args, field, LARGE_FLOAT __VA_ARGS__)
+#define PRINT_HEADER1(args, header1) \
+ do { \
+ PRINT_EMPTY_LABEL(args); \
+ PRINT_HEADER(args, header1, EOL); \
+ } while (0)
+
#define PRINT_HEADER4(args, header1, header2, header3, header4) \
do { \
PRINT_EMPTY_LABEL(args); \
VALUE_ALL(args, sum); \
} while (0)
+#define COMPUTE_DIVIDE(args, fraction, dividend, divisor) \
+ do { \
+ SCRIPT(args, "CDEF:" fraction "=" dividend "," TOSTRING(divisor) ",/"); \
+ VALUE_ALL(args, fraction); \
+ } while (0)
+
#define COMPUTE_PERCENTAGE(args, field, total) \
do { \
SCRIPT(args, "CDEF:" FIELD_PERCENT(field) "=100," field ",*," total ",/"); \
--- /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 <limits.h>
+
+#include "graph.h"
+#include "uptime.h"
+
+static int uptime_title(collecty_ctx* ctx, collecty_graph* graph,
+ const char* object, char** title) {
+ return collecty_format_title(title, "%s", _("Uptime"));
+}
+
+static int uptime_vlabel(collecty_ctx* ctx, collecty_graph* graph,
+ const char* object, char** title) {
+ return collecty_format_title(title, "%s", _("Days"));
+}
+
+static int uptime_render(collecty_ctx* ctx,
+ collecty_graph* graph, collecty_args* args, const char* object) {
+ int r;
+
+ // This requires the uptime source
+ r = collecty_graph_require_source(graph, args, "uptime", object);
+ if (r < 0)
+ return r;
+
+ // Convert the uptime into days
+ COMPUTE_DIVIDE(args, "uptime_days", "uptime", 86400);
+
+ // Header
+ PRINT_HEADER1(args, _("Current"));
+
+ // Draw the uptime
+ DRAW_AREA_WITH_LABEL(args, "uptime_days", DEFAULT, _("Uptime"));
+ PRINT_INTEGER(args, "uptime_days_cur", EOL);
+
+ return 0;
+}
+
+const collecty_graph_impl uptime_graph = {
+ .name = "Uptime",
+ .render = uptime_render,
+ .title = uptime_title,
+ .vlabel = uptime_vlabel,
+
+ // Limits
+ .lower_limit = 0,
+ .upper_limit = LONG_MAX,
+};
--- /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_GRAPH_UPTIME_H
+#define COLLECTY_GRAPH_UPTIME_H
+
+#include "../graph.h"
+
+extern const collecty_graph_impl uptime_graph;
+
+#endif /* COLLECTY_GRAPH_UPTIME_H */
#include <stdint.h>
#include <stdlib.h>
+// Preprocessor macro to make something a string
+#define STRINGIFY(x) #x
+#define TOSTRING(x) STRINGIFY(x)
+
// Macros to help the compiler with branch prediction
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)