Semaphore (common context) (#18041)
thiagoftsm committed
Jul 8, 2024 at 22:58 UTC
92ebdd2ddb6d6e42c4937b1b1d21ef6959bae085
8 files changed
+99
-47
CMakeLists.txt
+1
@@ -1299,6 +1299,7 @@ set(WINDOWS_PLUGIN_FILES
1299
src/collectors/windows.plugin/perflib-dump.c
1300
src/collectors/windows.plugin/perflib-storage.c
1301
src/collectors/windows.plugin/perflib-processor.c
1302
+ src/collectors/windows.plugin/perflib-objects.c
1303
src/collectors/windows.plugin/perflib-network.c
1304
src/collectors/windows.plugin/perflib-memory.c
1305
src/collectors/windows.plugin/perflib-processes.c
src/collectors/common-contexts/common-contexts.h
+1
@@ -22,6 +22,7 @@ typedef void (*instance_labels_cb_t)(RRDSET *st, void *data);
22
#include "system.ram.h"
23
#include "system.interrupts.h"
24
#include "system.processes.h"
25
+#include "system.ipc.h"
26
#include "mem.swap.h"
27
#include "mem.pgfaults.h"
28
#include "mem.available.h"
src/collectors/common-contexts/system.ipc.h
new
+34
@@ -0,0 +1,34 @@
1
+// SPDX-License-Identifier: GPL-3.0-or-later
2
+
3
+#ifndef NETDATA_SYSTEM_IPC_H
4
+#define NETDATA_SYSTEM_IPC_H
5
+
6
+#include "common-contexts.h"
7
+
8
+static inline void common_semaphore_ipc(uint64_t semaphore, NETDATA_DOUBLE red, char *module, int update_every) {
9
+ static RRDSET *st_semaphores = NULL;
10
+ static RRDDIM *rd_semaphores = NULL;
11
+ if(unlikely(!st_semaphores)) {
12
+ st_semaphores = rrdset_create_localhost("system"
13
+ , "ipc_semaphores"
14
+ , NULL
15
+ , "ipc semaphores"
16
+ , NULL
17
+ , "IPC Semaphores"
18
+ , "semaphores"
19
+ , _COMMON_PLUGIN_NAME
20
+ , module
21
+ , NETDATA_CHART_PRIO_SYSTEM_IPC_SEMAPHORES
22
+ , update_every
23
+ , RRDSET_TYPE_AREA
24
+ );
25
+ rd_semaphores = rrddim_add(st_semaphores, "semaphores", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
26
+ }
27
+
28
+ rrddim_set_by_pointer(st_semaphores, rd_semaphores, semaphore);
29
+ rrdset_done(st_semaphores);
30
+ if (!strcmp(module, "ipc"))
31
+ st_semaphores->red = red;
32
+}
33
+
34
+#endif //NETDATA_SYSTEM_IPC_H
src/collectors/freebsd.plugin/freebsd_sysctl.c
+3
-23
@@ -1142,30 +1142,10 @@ int do_kern_ipc_sem(int update_every, usec_t dt) {
1142
}
1143
}
1144
1145
- static RRDSET *st_semaphores = NULL, *st_semaphore_arrays = NULL;
1146
- static RRDDIM *rd_semaphores = NULL, *rd_semaphore_arrays = NULL;
1145
+ static RRDSET *st_semaphore_arrays = NULL;
1146
+ static RRDDIM *rd_semaphore_arrays = NULL;
1147
1148
- if (unlikely(!st_semaphores)) {
1149
- st_semaphores = rrdset_create_localhost(
1150
- "system",
1151
- "ipc_semaphores",
1152
- NULL,
1153
- "ipc semaphores",
1154
- NULL,
1155
- "IPC Semaphores",
1156
- "semaphores",
1157
- "freebsd.plugin",
1158
- "kern.ipc.sem",
1159
- NETDATA_CHART_PRIO_SYSTEM_IPC_SEMAPHORES,
1160
- update_every,
1161
- RRDSET_TYPE_AREA
1162
- );
1163
-
1164
- rd_semaphores = rrddim_add(st_semaphores, "semaphores", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1165
- }
1166
-
1167
- rrddim_set_by_pointer(st_semaphores, rd_semaphores, ipc_sem.semaphores);
1168
- rrdset_done(st_semaphores);
1148
+ common_semaphore_ipc(ipc_sem.semaphores, 0.0, "kern.ipc.sem", update_every);
1149
1150
if (unlikely(!st_semaphore_arrays)) {
1151
st_semaphore_arrays = rrdset_create_localhost(
src/collectors/proc.plugin/ipc.c
+7
-24
@@ -6,6 +6,9 @@
6
#include <sys/msg.h>
7
#include <sys/shm.h>
8
9
+#define _COMMON_PLUGIN_NAME PLUGIN_PROC_NAME
10
+#define _COMMON_PLUGIN_MODULE_NAME "ipc"
11
+#include "../common-contexts/common-contexts.h"
12
13
#ifndef SEMVMX
14
#define SEMVMX 32767 /* <= 32767 semaphore maximum value */
@@ -282,8 +285,8 @@ int do_ipc(int update_every, usec_t dt) {
285
static struct ipc_limits limits;
286
static struct ipc_status status;
287
static const RRDVAR_ACQUIRED *arrays_max = NULL, *semaphores_max = NULL;
285
- static RRDSET *st_semaphores = NULL, *st_arrays = NULL;
286
- static RRDDIM *rd_semaphores = NULL, *rd_arrays = NULL;
288
+ static RRDSET *st_arrays = NULL;
289
+ static RRDDIM *rd_arrays = NULL;
290
static char *msg_filename = NULL;
291
static struct message_queue *message_queue_root = NULL;
292
static long long dimensions_limit;
@@ -314,25 +317,7 @@ int do_ipc(int update_every, usec_t dt) {
317
do_sem = CONFIG_BOOLEAN_NO;
318
}
319
else {
317
- // create the charts
318
- if(unlikely(!st_semaphores)) {
319
- st_semaphores = rrdset_create_localhost(
320
- "system"
321
- , "ipc_semaphores"
322
- , NULL
323
- , "ipc semaphores"
324
- , NULL
325
- , "IPC Semaphores"
326
- , "semaphores"
327
- , PLUGIN_PROC_NAME
328
- , "ipc"
329
- , NETDATA_CHART_PRIO_SYSTEM_IPC_SEMAPHORES
330
- , localhost->rrd_update_every
331
- , RRDSET_TYPE_AREA
332
- );
333
- rd_semaphores = rrddim_add(st_semaphores, "semaphores", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
334
- }
335
-
320
+ // create the chart
321
if(unlikely(!st_arrays)) {
322
st_arrays = rrdset_create_localhost(
323
"system"
@@ -379,7 +364,6 @@ int do_ipc(int update_every, usec_t dt) {
364
rrdvar_host_variable_set(localhost, arrays_max, limits.semmni);
365
366
st_arrays->red = limits.semmni;
382
- st_semaphores->red = limits.semmns;
367
368
read_limits_next = 60 / update_every;
369
}
@@ -392,8 +376,7 @@ int do_ipc(int update_every, usec_t dt) {
376
return 0;
377
}
378
395
- rrddim_set_by_pointer(st_semaphores, rd_semaphores, status.semaem);
396
- rrdset_done(st_semaphores);
379
+ common_semaphore_ipc(status.semaem, limits.semmns, "ipc", localhost->rrd_update_every);
380
381
rrddim_set_by_pointer(st_arrays, rd_arrays, status.semusz);
382
rrdset_done(st_arrays);
src/collectors/windows.plugin/perflib-objects.c
new
+47
@@ -0,0 +1,47 @@
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 "PerflibObjects"
8
+#include "../common-contexts/common-contexts.h"
9
+
10
+static void initialize(void) {
11
+ ;
12
+}
13
+
14
+static bool do_objects(PERF_DATA_BLOCK *pDataBlock, int update_every) {
15
+ PERF_OBJECT_TYPE *pObjectType = perflibFindObjectTypeByName(pDataBlock, "Objects");
16
+ if (!pObjectType)
17
+ return false;
18
+
19
+ static COUNTER_DATA semaphores = { .key = "Semaphores" };
20
+
21
+ if(perflibGetObjectCounter(pDataBlock, pObjectType, &semaphores)) {
22
+ ULONGLONG sem = semaphores.current.Data;
23
+ common_semaphore_ipc(sem, WINDOWS_MAX_KERNEL_OBJECT, _COMMON_PLUGIN_MODULE_NAME, update_every);
24
+ }
25
+
26
+ return true;
27
+}
28
+
29
+int do_PerflibObjects(int update_every, usec_t dt __maybe_unused) {
30
+ static bool initialized = false;
31
+
32
+ if(unlikely(!initialized)) {
33
+ initialize();
34
+ initialized = true;
35
+ }
36
+
37
+ DWORD id = RegistryFindIDByName("Objects");
38
+ if(id == PERFLIB_REGISTRY_NAME_NOT_FOUND)
39
+ return -1;
40
+
41
+ PERF_DATA_BLOCK *pDataBlock = perflibGetPerformanceData(id);
42
+ if(!pDataBlock) return -1;
43
+
44
+ do_objects(pDataBlock, update_every);
45
+
46
+ return 0;
47
+}
src/collectors/windows.plugin/windows_plugin.c
+1
@@ -24,6 +24,7 @@ static struct proc_module {
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
+ {.name = "PerflibObjects", .dim = "PerflibObjects", .func = do_PerflibObjects},
28
29
// the terminator of this array
30
{.name = NULL, .dim = NULL, .func = NULL}
src/collectors/windows.plugin/windows_plugin.h
+5
@@ -7,6 +7,10 @@
7
8
#define PLUGIN_WINDOWS_NAME "windows.plugin"
9
10
+// https://learn.microsoft.com/es-es/windows/win32/sysinfo/kernel-objects?redirectedfrom=MSDN
11
+// 2^24
12
+#define WINDOWS_MAX_KERNEL_OBJECT 16777216
13
+
14
void *win_plugin_main(void *ptr);
15
16
extern char windows_shared_buffer[8192];
@@ -19,6 +23,7 @@ int do_PerflibNetwork(int update_every, usec_t dt);
23
int do_PerflibProcesses(int update_every, usec_t dt);
24
int do_PerflibProcessor(int update_every, usec_t dt);
25
int do_PerflibMemory(int update_every, usec_t dt);
26
+int do_PerflibObjects(int update_every, usec_t dt);
27
28
#include "perflib.h"
29