master
h 41 lines 1.41 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 #include "common-contexts.h"
4
5 static inline void common_mem_swap(uint64_t free_bytes, uint64_t used_bytes, int update_every) {
6 static RRDSET *st_system_swap = NULL;
7 static RRDDIM *rd_free = NULL, *rd_used = NULL;
8
9 if (free_bytes == 0 && used_bytes == 0 && st_system_swap) {
10 rrdset_is_obsolete___safe_from_collector_thread(st_system_swap);
11 st_system_swap = NULL;
12 rd_free = NULL;
13 rd_used = NULL;
14 return;
15 }
16
17 if(unlikely(!st_system_swap)) {
18 st_system_swap = rrdset_create_localhost(
19 "mem"
20 , "swap"
21 , NULL
22 , "swap"
23 , NULL
24 , "System Swap"
25 , "MiB"
26 , _COMMON_PLUGIN_NAME
27 , _COMMON_PLUGIN_MODULE_NAME
28 , NETDATA_CHART_PRIO_MEM_SWAP
29 , update_every
30 , RRDSET_TYPE_STACKED
31 );
32
33 rd_free = rrddim_add(st_system_swap, "free", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
34 rd_used = rrddim_add(st_system_swap, "used", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE);
35 }
36
37 // this always have to be in base units, so that exporting sends base units to other time-series db
38 rrddim_set_by_pointer(st_system_swap, rd_used, (collected_number)used_bytes);
39 rrddim_set_by_pointer(st_system_swap, rd_free, (collected_number)free_bytes);
40 rrdset_done(st_system_swap);
41 }