| 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 "GetSystemRam" |
| 8 | #include "../common-contexts/common-contexts.h" |
| 9 | |
| 10 | int do_GetSystemRAM(int update_every, usec_t dt __maybe_unused) |
| 11 | { |
| 12 | MEMORYSTATUSEX memStat = {0}; |
| 13 | memStat.dwLength = sizeof(memStat); |
| 14 | |
| 15 | if (!GlobalMemoryStatusEx(&memStat)) { |
| 16 | nd_log(NDLS_COLLECTORS, NDLP_ERR, "GlobalMemoryStatusEx() failed (error: %lu)", GetLastError()); |
| 17 | return 1; |
| 18 | } |
| 19 | |
| 20 | { |
| 21 | ULONGLONG total_bytes = memStat.ullTotalPhys; |
| 22 | ULONGLONG free_bytes = memStat.ullAvailPhys; |
| 23 | ULONGLONG used_bytes = total_bytes - free_bytes; |
| 24 | common_system_ram(free_bytes, used_bytes, update_every); |
| 25 | } |
| 26 | |
| 27 | { |
| 28 | ULONGLONG total_bytes = memStat.ullTotalPageFile; |
| 29 | ULONGLONG free_bytes = memStat.ullAvailPageFile; |
| 30 | ULONGLONG used_bytes = total_bytes - free_bytes; |
| 31 | common_mem_swap(free_bytes, used_bytes, update_every); |
| 32 | } |
| 33 | |
| 34 | return 0; |
| 35 | } |