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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
// SPDX-License-Identifier: GPL-3.0-or-later
#include "win_system-info.h"
#ifdef OS_WINDOWS
// Hardware
static char *netdata_windows_arch(DWORD value)
{
switch (value) {
case 9:
return "x86_64";
case 5:
return "ARM";
case 12:
return "ARM64";
case 6:
return "Intel Intaniun-based";
case 0:
return "x86";
default:
return NETDATA_DEFAULT_SYSTEM_INFO_VALUE_UNKNOWN;
}
}
static DWORD netdata_windows_cpu_frequency(HKEY lKey)
{
DWORD freq = 0;
long ret = netdata_registry_get_dword_from_open_key(&freq, lKey, "~MHz");
if (ret != ERROR_SUCCESS)
return freq;
freq *= 1000000;
return freq;
}
static void netdata_windows_cpu_from_system_info(struct rrdhost_system_info *systemInfo)
{
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
char cpuData[256];
(void)snprintf(cpuData, 255, "%d", sysInfo.dwNumberOfProcessors);
(void)rrdhost_set_system_info_variable(systemInfo, "NETDATA_SYSTEM_CPU_LOGICAL_CPU_COUNT", cpuData);
char *arch = netdata_windows_arch(sysInfo.wProcessorArchitecture);
(void)rrdhost_set_system_info_variable(systemInfo, "NETDATA_SYSTEM_ARCHITECTURE", arch);
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_SYSTEM_VIRTUALIZATION", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_NONE);
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_SYSTEM_VIRT_DETECTION", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_NONE);
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_SYSTEM_CONTAINER", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_NONE);
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_SYSTEM_CONTAINER_DETECTION", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_NONE);
}
static void netdata_windows_cpu_vendor_model(struct rrdhost_system_info *systemInfo,
HKEY lKey,
char *variable,
char *key)
{
char cpuData[256];
long ret = netdata_registry_get_string_from_open_key(cpuData, 255, lKey, key);
(void)rrdhost_set_system_info_variable(systemInfo,
variable,
(ret == ERROR_SUCCESS) ? cpuData : NETDATA_DEFAULT_SYSTEM_INFO_VALUE_UNKNOWN);
}
static void netdata_windows_cpu_from_registry(struct rrdhost_system_info *systemInfo)
{
HKEY lKey;
long ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
0,
KEY_READ,
&lKey);
if (ret != ERROR_SUCCESS)
return;
ULONGLONG cpuFreq = netdata_windows_cpu_frequency(lKey);
char cpuData[256];
if (cpuFreq)
(void)snprintf(cpuData, 255, "%lu", (unsigned long)cpuFreq);
(void)rrdhost_set_system_info_variable(systemInfo,
"NETDATA_SYSTEM_CPU_FREQ",
(!cpuFreq) ? NETDATA_DEFAULT_SYSTEM_INFO_VALUE_UNKNOWN : cpuData);
netdata_windows_cpu_vendor_model(systemInfo, lKey, "NETDATA_SYSTEM_CPU_VENDOR", "VendorIdentifier");
netdata_windows_cpu_vendor_model(systemInfo, lKey, "NETDATA_SYSTEM_CPU_MODEL", "ProcessorNameString");
(void)rrdhost_set_system_info_variable(systemInfo, "NETDATA_SYSTEM_CPU_DETECTION", NETDATA_WIN_DETECTION_METHOD);
}
static void netdata_windows_get_cpu(struct rrdhost_system_info *systemInfo)
{
netdata_windows_cpu_from_system_info(systemInfo);
netdata_windows_cpu_from_registry(systemInfo);
}
static void netdata_windows_get_mem(struct rrdhost_system_info *systemInfo)
{
ULONGLONG size;
char memSize[256];
// The amount of physically installed RAM, in kilobytes.
if (!GetPhysicallyInstalledSystemMemory(&size))
size = 0;
else
(void)snprintf(memSize, 255, "%llu", size * 1024); // to bytes
(void)rrdhost_set_system_info_variable(systemInfo,
"NETDATA_SYSTEM_TOTAL_RAM",
(!size) ? NETDATA_DEFAULT_SYSTEM_INFO_VALUE_UNKNOWN : memSize);
(void)rrdhost_set_system_info_variable(systemInfo, "NETDATA_SYSTEM_RAM_DETECTION", NETDATA_WIN_DETECTION_METHOD);
}
static ULONGLONG netdata_windows_get_disk_size(char *cVolume)
{
HANDLE disk = CreateFile(cVolume, GENERIC_READ, FILE_SHARE_VALID_FLAGS, 0, OPEN_EXISTING, 0, 0);
if (!disk)
return 0;
GET_LENGTH_INFORMATION length;
DWORD ret;
if (!DeviceIoControl(disk, IOCTL_DISK_GET_LENGTH_INFO, 0, 0, &length, sizeof(length), &ret, 0))
return 0;
CloseHandle(disk);
return length.Length.QuadPart;
}
static void netdata_windows_get_total_disk_size(struct rrdhost_system_info *systemInfo)
{
ULONGLONG total = 0;
char cVolume[8];
snprintf(cVolume, 7, "\\\\.\\C:");
DWORD lDrives = GetLogicalDrives();
if (!lDrives) {
return;
}
int i;
#define ND_POSSIBLE_VOLUMES 26
for (i = 0; i < ND_POSSIBLE_VOLUMES; i++) {
if (!(lDrives & 1 << i))
continue;
cVolume[4] = 'A' + i;
total += netdata_windows_get_disk_size(cVolume);
}
char diskSize[256];
(void)snprintf(diskSize, 255, "%llu", total);
(void)rrdhost_set_system_info_variable(systemInfo, "NETDATA_SYSTEM_TOTAL_DISK_SIZE", diskSize);
(void)rrdhost_set_system_info_variable(systemInfo, "NETDATA_SYSTEM_DISK_DETECTION", NETDATA_WIN_DETECTION_METHOD);
}
// Host
static DWORD netdata_windows_get_current_build()
{
char cBuild[64];
if (!netdata_registry_get_string(
cBuild, 63, HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "CurrentBuild"))
return 0;
errno_clear();
DWORD version = strtol(cBuild, NULL, 10);
if (errno == ERANGE)
return 0;
return version;
}
static void netdata_windows_discover_os_version(char *os, size_t length, DWORD build)
{
char versionName[256];
if (!netdata_registry_get_string(versionName,
255,
HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
"DisplayVersion"))
{
(void)snprintf(os, length, "Microsoft Windows");
return;
}
if (IsWindowsServer()) {
(void)snprintf(os, length, "Microsoft Windows Version %s", versionName);
return;
}
#define ND_WIN_VER_LENGTH 16
char version[ND_WIN_VER_LENGTH + 1];
if (IsWindows10OrGreater()) {
// https://learn.microsoft.com/en-us/windows/release-health/windows11-release-information
(void)snprintf(version, ND_WIN_VER_LENGTH, (build < 22000) ? "10" : "11");
} else if (IsWindows8Point1OrGreater()) {
(void)snprintf(version, ND_WIN_VER_LENGTH, "8.1");
} else if (IsWindows8OrGreater()) {
(void)snprintf(version, ND_WIN_VER_LENGTH, "8");
} else if (IsWindows7SP1OrGreater()) {
(void)snprintf(version, ND_WIN_VER_LENGTH, "7 SP1");
} else if (IsWindows7OrGreater()) {
(void)snprintf(version, ND_WIN_VER_LENGTH, "7");
} else if (IsWindowsVistaSP2OrGreater()) {
(void)snprintf(version, ND_WIN_VER_LENGTH, "Vista SP2");
} else if (IsWindowsVistaSP1OrGreater()) {
(void)snprintf(version, ND_WIN_VER_LENGTH, "Vista SP1");
} else if (IsWindowsVistaOrGreater()) {
(void)snprintf(version, ND_WIN_VER_LENGTH, "Vista");
}
// We are not testing older, because it is not supported anymore by Microsoft
(void)snprintf(os, length, "Microsoft Windows Version %s, Build %d", version, build);
}
static void netdata_windows_os_kernel_version(char *out, DWORD length, DWORD build)
{
DWORD major, minor;
if (!netdata_registry_get_dword(&major,
HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
"CurrentMajorVersionNumber"))
major = 0;
if (!netdata_registry_get_dword(&minor,
HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
"CurrentMinorVersionNumber"))
minor = 0;
(void)snprintf(out, length, "Windows %u.%u.%u Build: %u", major, minor, build, build);
}
static void netdata_windows_host(struct rrdhost_system_info *systemInfo)
{
char osVersion[4096];
(void)rrdhost_set_system_info_variable(systemInfo, "NETDATA_HOST_OS_NAME", "Microsoft Windows");
DWORD build = netdata_windows_get_current_build();
netdata_windows_discover_os_version(osVersion, 4095, build);
(void)rrdhost_set_system_info_variable(systemInfo, "NETDATA_HOST_OS_ID", osVersion);
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_HOST_OS_ID_LIKE", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_UNKNOWN);
(void)rrdhost_set_system_info_variable(systemInfo, "NETDATA_HOST_OS_VERSION", osVersion);
(void)rrdhost_set_system_info_variable(systemInfo, "NETDATA_HOST_OS_VERSION_ID", osVersion);
(void)rrdhost_set_system_info_variable(systemInfo, "NETDATA_HOST_OS_DETECTION", NETDATA_WIN_DETECTION_METHOD);
(void)rrdhost_set_system_info_variable(systemInfo, "NETDATA_SYSTEM_KERNEL_NAME", "Windows");
netdata_windows_os_kernel_version(osVersion, 4095, build);
(void)rrdhost_set_system_info_variable(systemInfo, "NETDATA_SYSTEM_KERNEL_VERSION", osVersion);
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_HOST_IS_K8S_NODE", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_FALSE);
}
// Cloud
static void netdata_windows_cloud(struct rrdhost_system_info *systemInfo)
{
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_INSTANCE_CLOUD_TYPE", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_UNKNOWN);
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_INSTANCE_CLOUD_INSTANCE_TYPE", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_UNKNOWN);
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_INSTANCE_CLOUD_INSTANCE_REGION", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_UNKNOWN);
}
// Container
static void netdata_windows_container(struct rrdhost_system_info *systemInfo)
{
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_CONTAINER_OS_NAME", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_NONE);
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_CONTAINER_OS_ID", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_NONE);
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_CONTAINER_OS_ID_LIKE", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_NONE);
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_CONTAINER_OS_VERSION", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_NONE);
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_CONTAINER_OS_VERSION_ID", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_NONE);
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_CONTAINER_OS_DETECTION", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_NONE);
(void)rrdhost_set_system_info_variable(
systemInfo, "NETDATA_CONTAINER_IS_OFFICIAL_IMAGE", NETDATA_DEFAULT_SYSTEM_INFO_VALUE_FALSE);
}
static void netdata_windows_install_type(struct rrdhost_system_info *systemInfo)
{
(void)rrdhost_set_system_info_variable(systemInfo, "NETDATA_INSTALL_TYPE", "netdata-installer.exe");
}
void netdata_windows_get_system_info(struct rrdhost_system_info *systemInfo)
{
netdata_windows_cloud(systemInfo);
netdata_windows_container(systemInfo);
netdata_windows_host(systemInfo);
netdata_windows_get_cpu(systemInfo);
netdata_windows_get_mem(systemInfo);
netdata_windows_get_total_disk_size(systemInfo);
netdata_windows_install_type(systemInfo);
}
#endif
|