summaryrefslogtreecommitdiffstats
path: root/src/collectors/windows.plugin/GetSystemCPU.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-07-24 09:54:23 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-07-24 09:54:44 +0000
commit836b47cb7e99a977c5a23b059ca1d0b5065d310e (patch)
tree1604da8f482d02effa033c94a84be42bc0c848c3 /src/collectors/windows.plugin/GetSystemCPU.c
parentReleasing debian version 1.44.3-2. (diff)
downloadnetdata-836b47cb7e99a977c5a23b059ca1d0b5065d310e.tar.xz
netdata-836b47cb7e99a977c5a23b059ca1d0b5065d310e.zip
Merging upstream version 1.46.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/collectors/windows.plugin/GetSystemCPU.c')
-rw-r--r--src/collectors/windows.plugin/GetSystemCPU.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/collectors/windows.plugin/GetSystemCPU.c b/src/collectors/windows.plugin/GetSystemCPU.c
new file mode 100644
index 00000000..a7a0aca8
--- /dev/null
+++ b/src/collectors/windows.plugin/GetSystemCPU.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include "windows_plugin.h"
+#include "windows-internals.h"
+
+int do_GetSystemCPU(int update_every, usec_t dt __maybe_unused) {
+ FILETIME idleTime, kernelTime, userTime;
+
+ if(GetSystemTimes(&idleTime, &kernelTime, &userTime) == 0) {
+ netdata_log_error("GetSystemTimes() failed.");
+ return 1;
+ }
+
+ ULONGLONG idle = FileTimeToULL(idleTime);
+ ULONGLONG kernel = FileTimeToULL(kernelTime);
+ ULONGLONG user = FileTimeToULL(userTime);
+
+ // kernel includes idle
+ kernel -= idle;
+
+ static RRDSET *st = NULL;
+ static RRDDIM *rd_user = NULL, *rd_kernel = NULL, *rd_idle = NULL;
+ if(!st) {
+ st = rrdset_create_localhost(
+ "system"
+ , "cpu"
+ , NULL
+ , "cpu"
+ , "system.cpu"
+ , "Total CPU utilization"
+ , "percentage"
+ , PLUGIN_WINDOWS_NAME
+ , "GetSystemTimes"
+ , NETDATA_CHART_PRIO_SYSTEM_CPU
+ , update_every
+ , RRDSET_TYPE_STACKED
+ );
+
+ rd_user = rrddim_add(st, "user", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
+ rd_kernel = rrddim_add(st, "system", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
+ rd_idle = rrddim_add(st, "idle", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL);
+ rrddim_hide(st, "idle");
+ }
+
+ rrddim_set_by_pointer(st, rd_user, (collected_number )user);
+ rrddim_set_by_pointer(st, rd_kernel, (collected_number )kernel);
+ rrddim_set_by_pointer(st, rd_idle, (collected_number )idle);
+ rrdset_done(st);
+
+ return 0;
+}