| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_SYSTEM_RAM_H |
| 4 | #define NETDATA_SYSTEM_RAM_H |
| 5 | |
| 6 | #include "common-contexts.h" |
| 7 | |
| 8 | #define _system_ram_chart() \ |
| 9 | rrdset_create_localhost( \ |
| 10 | "system" \ |
| 11 | , "ram" \ |
| 12 | , NULL \ |
| 13 | , "ram" \ |
| 14 | , NULL \ |
| 15 | , "System RAM" \ |
| 16 | , "MiB" \ |
| 17 | , _COMMON_PLUGIN_NAME \ |
| 18 | , _COMMON_PLUGIN_MODULE_NAME \ |
| 19 | , NETDATA_CHART_PRIO_SYSTEM_RAM \ |
| 20 | , update_every \ |
| 21 | , RRDSET_TYPE_STACKED \ |
| 22 | ) |
| 23 | |
| 24 | #ifdef OS_WINDOWS |
| 25 | static inline void common_system_ram(uint64_t free_bytes, uint64_t used_bytes, int update_every) { |
| 26 | static RRDSET *st_system_ram = NULL; |
| 27 | static RRDDIM *rd_free = NULL; |
| 28 | static RRDDIM *rd_used = NULL; |
| 29 | |
| 30 | if(unlikely(!st_system_ram)) { |
| 31 | st_system_ram = _system_ram_chart(); |
| 32 | rd_free = rrddim_add(st_system_ram, "free", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE); |
| 33 | rd_used = rrddim_add(st_system_ram, "used", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE); |
| 34 | } |
| 35 | |
| 36 | // this always have to be in base units, so that exporting sends base units to other time-series db |
| 37 | rrddim_set_by_pointer(st_system_ram, rd_free, (collected_number)free_bytes); |
| 38 | rrddim_set_by_pointer(st_system_ram, rd_used, (collected_number)used_bytes); |
| 39 | rrdset_done(st_system_ram); |
| 40 | } |
| 41 | #endif |
| 42 | |
| 43 | #ifdef OS_LINUX |
| 44 | static inline void common_system_ram(uint64_t free_bytes, uint64_t used_bytes, uint64_t cached_bytes, uint64_t buffers_bytes, int update_every) { |
| 45 | static RRDSET *st_system_ram = NULL; |
| 46 | static RRDDIM *rd_free = NULL; |
| 47 | static RRDDIM *rd_used = NULL; |
| 48 | static RRDDIM *rd_cached = NULL; |
| 49 | static RRDDIM *rd_buffers = NULL; |
| 50 | |
| 51 | if(unlikely(!st_system_ram)) { |
| 52 | st_system_ram = _system_ram_chart(); |
| 53 | rd_free = rrddim_add(st_system_ram, "free", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE); |
| 54 | rd_used = rrddim_add(st_system_ram, "used", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE); |
| 55 | rd_cached = rrddim_add(st_system_ram, "cached", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE); |
| 56 | rd_buffers = rrddim_add(st_system_ram, "buffers", NULL, 1, 1024 * 1024, RRD_ALGORITHM_ABSOLUTE); |
| 57 | } |
| 58 | |
| 59 | // this always have to be in base units, so that exporting sends base units to other time-series db |
| 60 | rrddim_set_by_pointer(st_system_ram, rd_free, (collected_number)free_bytes); |
| 61 | rrddim_set_by_pointer(st_system_ram, rd_used, (collected_number)used_bytes); |
| 62 | rrddim_set_by_pointer(st_system_ram, rd_cached, (collected_number)cached_bytes); |
| 63 | rrddim_set_by_pointer(st_system_ram, rd_buffers, (collected_number)buffers_bytes); |
| 64 | rrdset_done(st_system_ram); |
| 65 | } |
| 66 | #endif |
| 67 | |
| 68 | #endif //NETDATA_SYSTEM_RAM_H |