]> git.ipfire.org Git - collecty.git/commitdiff
graphs: Add context switch graph
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Oct 2025 15:15:15 +0000 (15:15 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 3 Oct 2025 15:15:15 +0000 (15:15 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/daemon/graphs.c
src/daemon/graphs/contextswitches.c [new file with mode: 0644]
src/daemon/graphs/contextswitches.h [new file with mode: 0644]

index edab88d99eb5271e7eb0c682f777b192e5fe4664..6a0c5866a75f280f28a991a1550aaf39d153f4c0 100644 (file)
@@ -107,6 +107,8 @@ dist_collectyd_SOURCES = \
        src/daemon/graphs.h \
        src/daemon/graphs/conntrack.c \
        src/daemon/graphs/conntrack.h \
+       src/daemon/graphs/contextswitches.c \
+       src/daemon/graphs/contextswitches.h \
        src/daemon/graphs/graph.h \
        src/daemon/graphs/loadavg.c \
        src/daemon/graphs/loadavg.h \
index 02bb745723616088a83edf4005ffe2255cce5da1..6edea48d56959ab9ac77d39c2827bc1a693b70dd 100644 (file)
 
 // Load all graphs
 #include "graphs/conntrack.h"
+#include "graphs/contextswitches.h"
 #include "graphs/loadavg.h"
 
 // Register all graphs
 static const collecty_graph_impl* graph_impls[] = {
        &conntrack_graph,
+       &contextswitches_graph,
        &loadavg_graph,
        NULL,
 };
diff --git a/src/daemon/graphs/contextswitches.c b/src/daemon/graphs/contextswitches.c
new file mode 100644 (file)
index 0000000..446318a
--- /dev/null
@@ -0,0 +1,67 @@
+/*#############################################################################
+#                                                                             #
+# 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 "contextswitches.h"
+
+static int contextswitches_title(collecty_ctx* ctx,
+               collecty_graph* graph, const char* object, char** title) {
+       return collecty_format_title(title, "%s", _("Context Switches"));
+}
+
+static int contextswitches_vlabel(collecty_ctx* ctx,
+               collecty_graph* graph, const char* object, char** title) {
+       return collecty_format_title(title, "%s", _("Context Switches/s"));
+}
+
+static int contextswitches_render(collecty_ctx* ctx,
+               collecty_graph* graph, collecty_args* args, const char* object) {
+       int r;
+
+       // This requires the contextswitches source
+       r = collecty_graph_require_source(graph, args, "contextswitches", object);
+       if (r < 0)
+               return r;
+
+       // Context Switches
+       DRAW_AREA_WITH_LABEL(args, "ctxt", GREEN, _("Context Switches"));
+       PRINT_LARGE_INTEGER(args, "ctxt_cur");
+       PRINT_LARGE_INTEGER(args, "ctxt_avg");
+       PRINT_LARGE_INTEGER(args, "ctxt_min");
+       PRINT_LARGE_INTEGER(args, "ctxt_max", EOL);
+
+       // Header
+       PRINT_HEADER4(args, _("Current"), _("Average"), _("Minimum"), _("Maximum"));
+
+       return 0;
+}
+
+const collecty_graph_impl contextswitches_graph = {
+       .name    = "ContextSwitches",
+       .render  = contextswitches_render,
+       .title   = contextswitches_title,
+       .vlabel  = contextswitches_vlabel,
+
+       // Limits
+       .lower_limit = 0,
+       .upper_limit = LONG_MAX,
+};
diff --git a/src/daemon/graphs/contextswitches.h b/src/daemon/graphs/contextswitches.h
new file mode 100644 (file)
index 0000000..d58c95f
--- /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_GRAPH_CONTEXTSWITCHES_H
+#define COLLECTY_GRAPH_CONTEXTSWITCHES_H
+
+#include "../graph.h"
+
+extern const collecty_graph_impl contextswitches_graph;
+
+#endif /* COLLECTY_GRAPH_CONTEXTSWITCHES_H */