summaryrefslogtreecommitdiffstats
path: root/src/collectors/windows.plugin/GetSystemRAM.c
blob: 9dae9a2529e3c5cece94d840e6452b58348a52c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// SPDX-License-Identifier: GPL-3.0-or-later

#include "windows_plugin.h"
#include "windows-internals.h"

#define _COMMON_PLUGIN_NAME "windows.plugin"
#define _COMMON_PLUGIN_MODULE_NAME "GetSystemRam"
#include "../common-contexts/common-contexts.h"

int do_GetSystemRAM(int update_every, usec_t dt __maybe_unused) {
    MEMORYSTATUSEX memStat = { 0 };
    memStat.dwLength = sizeof(memStat);

    if (!GlobalMemoryStatusEx(&memStat)) {
        netdata_log_error("GlobalMemoryStatusEx() failed.");
        return 1;
    }

    {
        ULONGLONG total_bytes = memStat.ullTotalPhys;
        ULONGLONG free_bytes = memStat.ullAvailPhys;
        ULONGLONG used_bytes = total_bytes - free_bytes;
        common_system_ram(free_bytes, used_bytes, update_every);
    }

    {
        DWORDLONG total_bytes = memStat.ullTotalPageFile;
        DWORDLONG free_bytes = memStat.ullAvailPageFile;
        DWORDLONG used_bytes = total_bytes - free_bytes;
        common_mem_swap(free_bytes, used_bytes, update_every);
    }

    return 0;
}