@cryptotaxi247 / netdata-1 / commits / 749346365

Win processes ("System" name) (#17704)

thiagoftsm committed May 24, 2024 at 17:59 UTC 749346365aff2bfc86624148f8c1eb2341b9d16a
9 files changed +278 -52
CMakeLists.txt
+2
@@ -1005,6 +1005,7 @@ set(INTERNAL_COLLECTORS_FILES
1005 src/collectors/common-contexts/common-contexts.h
1006 src/collectors/common-contexts/disk.io.h
1007 src/collectors/common-contexts/system.io.h
1008 + src/collectors/common-contexts/system.processes.h
1009 src/collectors/common-contexts/system.ram.h
1010 src/collectors/common-contexts/mem.swap.h
1011 src/collectors/common-contexts/mem.pgfaults.h
@@ -1274,6 +1275,7 @@ set(WINDOWS_PLUGIN_FILES
1275 src/collectors/windows.plugin/perflib-processor.c
1276 src/collectors/windows.plugin/perflib-network.c
1277 src/collectors/windows.plugin/perflib-memory.c
1278 + src/collectors/windows.plugin/perflib-processes.c
1279 )
1280
1281 set(PROC_PLUGIN_FILES
src/collectors/all.h
+1
@@ -54,6 +54,7 @@
54 #define NETDATA_CHART_PRIO_SYSTEM_IPC_SHARED_MEM_SIZE 1206
55 #define NETDATA_CHART_PRIO_SYSTEM_IPC_SHARED_MEM_CALLS 1207
56 #define NETDATA_CHART_PRIO_SYSTEM_PACKETS 7001 // freebsd only
57 +#define NETDATA_CHART_PRIO_WINDOWS_THREADS 8001 // Windows only
58
59
60 // CPU per core
src/collectors/common-contexts/common-contexts.h
+1
@@ -20,6 +20,7 @@ typedef void (*instance_labels_cb_t)(RRDSET *st, void *data);
20
21 #include "system.io.h"
22 #include "system.ram.h"
23 +#include "system.processes.h"
24 #include "mem.swap.h"
25 #include "mem.pgfaults.h"
26 #include "mem.available.h"
src/collectors/common-contexts/system.processes.h new
+115
@@ -0,0 +1,115 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#ifndef NETDATA_SYSTEM_PROCESSES_H
4 +#define NETDATA_SYSTEM_PROCESSES_H
5 +
6 +#include "common-contexts.h"
7 +
8 +#define _system_process_chart() \
9 + rrdset_create_localhost( \
10 + "system" \
11 + , "processes" \
12 + , NULL \
13 + , "processes" \
14 + , NULL \
15 + , "System Processes" \
16 + , "processes" \
17 + , _COMMON_PLUGIN_NAME \
18 + , _COMMON_PLUGIN_MODULE_NAME \
19 + , NETDATA_CHART_PRIO_SYSTEM_PROCESSES \
20 + , update_every \
21 + , RRDSET_TYPE_LINE \
22 + )
23 +
24 +#if defined(OS_WINDOWS)
25 +static inline void common_system_processes(uint64_t running, int update_every) {
26 + static RRDSET *st_processes = NULL;
27 + static RRDDIM *rd_running = NULL;
28 +
29 + if(unlikely(!st_processes)) {
30 + st_processes = _system_process_chart();
31 +
32 + rd_running = rrddim_add(st_processes, "running", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
33 + }
34 +
35 + rrddim_set_by_pointer(st_processes, rd_running, running);
36 + rrdset_done(st_processes);
37 +}
38 +
39 +// EBPF COUNTER PART
40 +static inline void common_system_threads(uint64_t threads, int update_every) {
41 + static RRDSET *st_threads = NULL;
42 + static RRDDIM *rd_threads = NULL;
43 +
44 + if(unlikely(!st_threads)) {
45 + st_threads = rrdset_create_localhost(
46 + "system"
47 + , "threads"
48 + , NULL
49 + , "processes"
50 + , NULL
51 + , "Threads"
52 + , "threads"
53 + , _COMMON_PLUGIN_NAME
54 + , _COMMON_PLUGIN_MODULE_NAME
55 + , NETDATA_CHART_PRIO_WINDOWS_THREADS
56 + , update_every
57 + , RRDSET_TYPE_LINE
58 + );
59 +
60 + rd_threads = rrddim_add(st_threads, "threads", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
61 + }
62 +
63 + rrddim_set_by_pointer(st_threads, rd_threads, threads);
64 + rrdset_done(st_threads);
65 +}
66 +#endif
67 +
68 +#if defined(OS_LINUX)
69 +static inline void common_system_processes(uint64_t running, uint64_t blocked, int update_every) {
70 + static RRDSET *st_processes = NULL;
71 + static RRDDIM *rd_running = NULL;
72 + static RRDDIM *rd_blocked = NULL;
73 +
74 + if(unlikely(!st_processes)) {
75 + st_processes = _system_process_chart();
76 +
77 + rd_running = rrddim_add(st_processes, "running", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
78 + rd_blocked = rrddim_add(st_processes, "blocked", NULL, -1, 1, RRD_ALGORITHM_ABSOLUTE);
79 + }
80 +
81 + rrddim_set_by_pointer(st_processes, rd_running, (collected_number)running);
82 + rrddim_set_by_pointer(st_processes, rd_blocked, (collected_number)blocked);
83 + rrdset_done(st_processes);
84 +}
85 +#endif
86 +
87 +static inline void common_system_context_switch(uint64_t value, int update_every) {
88 + static RRDSET *st_ctxt = NULL;
89 + static RRDDIM *rd_switches = NULL;
90 +
91 + if(unlikely(!st_ctxt)) {
92 + st_ctxt = rrdset_create_localhost(
93 + "system"
94 + , "ctxt"
95 + , NULL
96 + , "processes"
97 + , NULL
98 + , "CPU Context Switches"
99 + , "context switches/s"
100 + , _COMMON_PLUGIN_NAME
101 + , _COMMON_PLUGIN_MODULE_NAME
102 + , NETDATA_CHART_PRIO_SYSTEM_CTXT
103 + , update_every
104 + , RRDSET_TYPE_LINE
105 + );
106 +
107 + rd_switches = rrddim_add(st_ctxt, "switches", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
108 + }
109 +
110 + rrddim_set_by_pointer(st_ctxt, rd_switches, (collected_number)value);
111 + rrdset_done(st_ctxt);
112 +}
113 +
114 +
115 +#endif //NETDATA_SYSTEM_PROCESSES_H
src/collectors/proc.plugin/proc_stat.c
+6 -51
@@ -4,6 +4,10 @@
4
5 #define PLUGIN_PROC_MODULE_STAT_NAME "/proc/stat"
6
7 +#define _COMMON_PLUGIN_NAME PLUGIN_PROC_NAME
8 +#define _COMMON_PLUGIN_MODULE_NAME PLUGIN_PROC_MODULE_STAT_NAME
9 +#include "../common-contexts/common-contexts.h"
10 +
11 struct per_core_single_number_file {
12 unsigned char found:1;
13 const char *filename;
@@ -779,31 +783,8 @@ int do_proc_stat(int update_every, usec_t dt) {
783 }
784 else if(unlikely(hash == hash_ctxt && strcmp(row_key, "ctxt") == 0)) {
785 if(likely(do_context)) {
782 - static RRDSET *st_ctxt = NULL;
783 - static RRDDIM *rd_switches = NULL;
786 unsigned long long value = str2ull(procfile_lineword(ff, l, 1), NULL);
785 -
786 - if(unlikely(!st_ctxt)) {
787 - st_ctxt = rrdset_create_localhost(
788 - "system"
789 - , "ctxt"
790 - , NULL
791 - , "processes"
792 - , NULL
793 - , "CPU Context Switches"
794 - , "context switches/s"
795 - , PLUGIN_PROC_NAME
796 - , PLUGIN_PROC_MODULE_STAT_NAME
797 - , NETDATA_CHART_PRIO_SYSTEM_CTXT
798 - , update_every
799 - , RRDSET_TYPE_LINE
800 - );
801 -
802 - rd_switches = rrddim_add(st_ctxt, "switches", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
803 - }
804 -
805 - rrddim_set_by_pointer(st_ctxt, rd_switches, value);
806 - rrdset_done(st_ctxt);
787 + common_system_context_switch(value, update_every);
788 }
789 }
790 else if(unlikely(hash == hash_processes && !processes && strcmp(row_key, "processes") == 0)) {
@@ -850,33 +831,7 @@ int do_proc_stat(int update_every, usec_t dt) {
831 // --------------------------------------------------------------------
832
833 if(likely(do_processes)) {
853 - static RRDSET *st_processes = NULL;
854 - static RRDDIM *rd_running = NULL;
855 - static RRDDIM *rd_blocked = NULL;
856 -
857 - if(unlikely(!st_processes)) {
858 - st_processes = rrdset_create_localhost(
859 - "system"
860 - , "processes"
861 - , NULL
862 - , "processes"
863 - , NULL
864 - , "System Processes"
865 - , "processes"
866 - , PLUGIN_PROC_NAME
867 - , PLUGIN_PROC_MODULE_STAT_NAME
868 - , NETDATA_CHART_PRIO_SYSTEM_PROCESSES
869 - , update_every
870 - , RRDSET_TYPE_LINE
871 - );
872 -
873 - rd_running = rrddim_add(st_processes, "running", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
874 - rd_blocked = rrddim_add(st_processes, "blocked", NULL, -1, 1, RRD_ALGORITHM_ABSOLUTE);
875 - }
876 -
877 - rrddim_set_by_pointer(st_processes, rd_running, running);
878 - rrddim_set_by_pointer(st_processes, rd_blocked, blocked);
879 - rrdset_done(st_processes);
834 + common_system_processes(running, blocked, update_every);
835 }
836
837 if(likely(all_cpu_charts_size > 1)) {
src/collectors/windows.plugin/metdata.yaml new
+92
@@ -0,0 +1,92 @@
1 +plugin_name: windows.plugin
2 +modules:
3 + - meta:
4 + plugin_name: proc.plugin
5 + module_name: PerflibProcesses
6 + monitored_instance:
7 + name: System statistics
8 + link: ""
9 + categories:
10 + - data-collection.windows-systems
11 + icon_filename: "windows.svg"
12 + related_resources:
13 + integrations:
14 + list: [ ]
15 + info_provided_to_referring_integrations:
16 + description: ""
17 + keywords:
18 + - process counts
19 + - threads
20 + most_popular: false
21 + overview:
22 + data_collection:
23 + metrics_description: |
24 + Perflib provides different statistical methods about Microsoft Windows environment. This collector query for
25 + Object 'System' to show actual number of processes, threads and context switches.
26 + method_description: ""
27 + supported_platforms:
28 + include: [ "windows" ]
29 + exclude: [ ]
30 + multi_instance: false
31 + additional_permissions:
32 + description: ""
33 + default_behavior:
34 + auto_detection:
35 + description: |
36 + The collector auto-detects all metrics. No configuration is needed.
37 + limits:
38 + description: ""
39 + performance_impact:
40 + description: ""
41 + setup:
42 + prerequisites:
43 + list: [ ]
44 + configuration:
45 + file:
46 + section_name: ""
47 + name: ""
48 + description: ""
49 + options:
50 + description: ""
51 + folding:
52 + title: ""
53 + enabled: true
54 + list: [ ]
55 + examples:
56 + folding:
57 + enabled: true
58 + title: ""
59 + list: [ ]
60 + troubleshooting:
61 + problems:
62 + list: [ ]
63 + alerts:
64 + metrics:
65 + folding:
66 + title: Metrics
67 + enabled: false
68 + description: ""
69 + availability: [ ]
70 + scopes:
71 + - name: global
72 + description: ""
73 + labels: [ ]
74 + metrics:
75 + - name: system.processes
76 + description: System Processes
77 + unit: "processes"
78 + chart_type: line
79 + dimensions:
80 + - name: running
81 + - name: system.threads
82 + description: System Threads
83 + unit: "threads"
84 + chart_type: line
85 + dimensions:
86 + - name: threads
87 + - name: system.ctxt
88 + description: CPU Context Switches
89 + unit: "context switches/s"
90 + chart_type: line
91 + dimensions:
92 + - name: switches
\ No newline at end of file
src/collectors/windows.plugin/perflib-processes.c new
+58
@@ -0,0 +1,58 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#include "windows_plugin.h"
4 +#include "windows-internals.h"
5 +
6 +#define _COMMON_PLUGIN_NAME "windows.plugin"
7 +#define _COMMON_PLUGIN_MODULE_NAME "PerflibProcesses"
8 +#include "../common-contexts/common-contexts.h"
9 +
10 +static void initialize(void) {
11 + ;
12 +}
13 +
14 +static bool do_processes(PERF_DATA_BLOCK *pDataBlock, int update_every) {
15 + PERF_OBJECT_TYPE *pObjectType = perflibFindObjectTypeByName(pDataBlock, "System");
16 + if (!pObjectType)
17 + return false;
18 +
19 + static COUNTER_DATA processesRunning = { .key = "Processes" };
20 + static COUNTER_DATA contextSwitchPerSec = { .key = "Context Switches/sec" };
21 + static COUNTER_DATA threads = { .key = "Threads" };
22 +
23 + if(perflibGetObjectCounter(pDataBlock, pObjectType, &processesRunning)) {
24 + ULONGLONG running = processesRunning.current.Data;
25 + common_system_processes(running, update_every);
26 + }
27 +
28 + if(perflibGetObjectCounter(pDataBlock, pObjectType, &contextSwitchPerSec)) {
29 + ULONGLONG contexts = contextSwitchPerSec.current.Data;
30 + common_system_context_switch(contexts, update_every);
31 + }
32 +
33 + if(perflibGetObjectCounter(pDataBlock, pObjectType, &threads)) {
34 + ULONGLONG totalThreads = threads.current.Data;
35 + common_system_threads(totalThreads, update_every);
36 + }
37 + return true;
38 +}
39 +
40 +int do_PerflibProcesses(int update_every, usec_t dt __maybe_unused) {
41 + static bool initialized = false;
42 +
43 + if(unlikely(!initialized)) {
44 + initialize();
45 + initialized = true;
46 + }
47 +
48 + DWORD id = RegistryFindIDByName("System");
49 + if(id == PERFLIB_REGISTRY_NAME_NOT_FOUND)
50 + return -1;
51 +
52 + PERF_DATA_BLOCK *pDataBlock = perflibGetPerformanceData(id);
53 + if(!pDataBlock) return -1;
54 +
55 + do_processes(pDataBlock, update_every);
56 +
57 + return 0;
58 +}
src/collectors/windows.plugin/windows_plugin.c
+2 -1
@@ -19,8 +19,9 @@ static struct proc_module {
19 // the same is provided by PerflibProcessor, with more detailed analysis
20 //{.name = "GetSystemCPU", .dim = "GetSystemCPU", .func = do_GetSystemCPU},
21
22 + {.name = "PerflibProcesses", .dim = "PerflibProcesses", .func = do_PerflibProcesses},
23 {.name = "PerflibProcessor", .dim = "PerflibProcessor", .func = do_PerflibProcessor},
23 - {.name = "PerflibMemory", .dim = "PerflibMemory", .func = do_PerflibMemory},
24 + {.name = "PerflibMemory", .dim = "PerflibMemory", .func = do_PerflibMemory},
25 {.name = "PerflibStorage", .dim = "PerflibStorage", .func = do_PerflibStorage},
26 {.name = "PerflibNetwork", .dim = "PerflibNetwork", .func = do_PerflibNetwork},
27
src/collectors/windows.plugin/windows_plugin.h
+1
@@ -16,6 +16,7 @@ int do_GetSystemRAM(int update_every, usec_t dt);
16 int do_GetSystemCPU(int update_every, usec_t dt);
17 int do_PerflibStorage(int update_every, usec_t dt);
18 int do_PerflibNetwork(int update_every, usec_t dt);
19 +int do_PerflibProcesses(int update_every, usec_t dt);
20 int do_PerflibProcessor(int update_every, usec_t dt);
21 int do_PerflibMemory(int update_every, usec_t dt);
22