master
h 115 lines 3.26 KB
Raw
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