From c37866c9f4d3582d7cc80bc0c9d4791c8b6749da Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 3 Oct 2025 15:15:15 +0000 Subject: [PATCH] graphs: Add context switch graph Signed-off-by: Michael Tremer --- Makefile.am | 2 + src/daemon/graphs.c | 2 + src/daemon/graphs/contextswitches.c | 67 +++++++++++++++++++++++++++++ src/daemon/graphs/contextswitches.h | 28 ++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 src/daemon/graphs/contextswitches.c create mode 100644 src/daemon/graphs/contextswitches.h diff --git a/Makefile.am b/Makefile.am index edab88d..6a0c586 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/src/daemon/graphs.c b/src/daemon/graphs.c index 02bb745..6edea48 100644 --- a/src/daemon/graphs.c +++ b/src/daemon/graphs.c @@ -28,11 +28,13 @@ // 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 index 0000000..446318a --- /dev/null +++ b/src/daemon/graphs/contextswitches.c @@ -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 . # +# # +#############################################################################*/ + +#include + +#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 index 0000000..d58c95f --- /dev/null +++ b/src/daemon/graphs/contextswitches.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_GRAPH_CONTEXTSWITCHES_H +#define COLLECTY_GRAPH_CONTEXTSWITCHES_H + +#include "../graph.h" + +extern const collecty_graph_impl contextswitches_graph; + +#endif /* COLLECTY_GRAPH_CONTEXTSWITCHES_H */ -- 2.47.3