@cryptotaxi247 / netdata-1 / commits / cb974ac38

Update Windows.plugin (#21797)

thiagoftsm committed Mar 3, 2026 at 18:29 UTC cb974ac384e3e64635d638a8334e7e668ef039b6
4 files changed +255 -38
packaging/windows/package-windows.sh
+2 -1
@@ -45,7 +45,8 @@ rm -rf /opt/netdata/msys64/
45 ${GITHUB_ACTIONS+echo "::endgroup::"}
46
47 ${GITHUB_ACTIONS+echo "::group::Configure Editor"}
48 -if [ -f /opt/netdata/etc/profile ]; then
48 +if [ ! -f "/opt/netdata/etc/profile" ]; then
49 echo 'EDITOR="/usr/bin/nano.exe"' >> /opt/netdata/etc/profile
50 fi
51 ${GITHUB_ACTIONS+echo "::endgroup::"}
52 +
src/collectors/windows.plugin/GetHardwareInfo.c
+106 -16
@@ -12,6 +12,8 @@ struct cpu_data {
12 RRDDIM *rd_cpu_temp;
13
14 collected_number cpu_temp;
15 + collected_number last_valid_temp;
16 + int read_errors;
17 };
18
19 struct cpu_data *cpus = NULL;
@@ -20,6 +22,14 @@ static ND_THREAD *hardware_info_thread = NULL;
22 static collected_number (*temperature_fcnt)(MSR_REQUEST *) = NULL;
23 static CRITICAL_SECTION cpus_lock;
24 bool cpus_lock_initialized = false;
25 +static HANDLE msr_device = INVALID_HANDLE_VALUE;
26 +static CRITICAL_SECTION device_lock;
27 +bool device_lock_initialized = false;
28 +static int consecutive_errors = 0;
29 +static const int MAX_CONSECUTIVE_ERRORS = 5;
30 +static const int IOCTL_RETRIES = 3;
31 +static const int IOCTL_RETRY_DELAY_MS = 10;
32 +#define INVALID_TEMP ((collected_number)(-1))
33
34 static void netdata_stop_driver()
35 {
@@ -143,10 +153,40 @@ static inline HANDLE netdata_open_device()
153 return msr_h;
154 }
155
156 +static bool netdata_reopen_device_if_needed()
157 +{
158 + if (msr_device != INVALID_HANDLE_VALUE) {
159 + return true;
160 + }
161 +
162 + msr_device = netdata_open_device();
163 + return (msr_device != INVALID_HANDLE_VALUE);
164 +}
165 +
166 +static bool netdata_read_msr(MSR_REQUEST *req)
167 +{
168 + if (!req || msr_device == INVALID_HANDLE_VALUE) {
169 + return false;
170 + }
171 +
172 + for (int retry = 0; retry < IOCTL_RETRIES; retry++) {
173 + DWORD bytes = 0;
174 + if (DeviceIoControl(msr_device, IOCTL_MSR_READ, req, sizeof(*req), req, sizeof(*req), &bytes, NULL)) {
175 + return true;
176 + }
177 +
178 + if (retry < IOCTL_RETRIES - 1) {
179 + Sleep(IOCTL_RETRY_DELAY_MS);
180 + }
181 + }
182 +
183 + return false;
184 +}
185 +
186 static collected_number netdata_intel_cpu_temp(MSR_REQUEST *req)
187 {
188 if (!req)
149 - return 0;
189 + return INVALID_TEMP;
190
191 const ULONG TJMAX = 100;
192 ULONG digital_readout = (req->low >> 16) & 0x7F; // bits [22:16]
@@ -154,7 +194,7 @@ static collected_number netdata_intel_cpu_temp(MSR_REQUEST *req)
194 collected_number temp = (collected_number)(TJMAX - digital_readout);
195
196 if (temp < 0 || temp > 150)
157 - return 0;
197 + return INVALID_TEMP;
198
199 return temp;
200 }
@@ -162,43 +202,55 @@ static collected_number netdata_intel_cpu_temp(MSR_REQUEST *req)
202 static collected_number netdata_amd_cpu_temp(MSR_REQUEST *req)
203 {
204 if (!req)
165 - return 0;
205 + return INVALID_TEMP;
206
207 ULONG amd_temp = (req->low >> 21) & 0x7FF;
208 collected_number temp = (collected_number)amd_temp / 8;
209
210 if (temp < 0 || temp > 150)
171 - return 0;
211 + return INVALID_TEMP;
212
213 return temp;
214 }
215
216 void netdata_collect_cpu_chart()
217 {
178 - HANDLE device = netdata_open_device();
179 - if (device == INVALID_HANDLE_VALUE) {
218 + if (!netdata_reopen_device_if_needed()) {
219 + consecutive_errors++;
220 + if (consecutive_errors >= MAX_CONSECUTIVE_ERRORS) {
221 + nd_log(
222 + NDLS_COLLECTORS, NDLP_ERR, "MSR device unavailable for %d consecutive attempts\n", consecutive_errors);
223 + }
224 return;
225 }
226
227 + consecutive_errors = 0;
228 const uint32_t MSR_THERM_STATUS = 0x19C;
229
230 EnterCriticalSection(&cpus_lock);
231 for (size_t cpu = 0; cpu < ncpus; cpu++) {
187 - DWORD bytes = 0;
232 MSR_REQUEST req = {MSR_THERM_STATUS, (ULONG)cpu, 0, 0};
233
190 - if (DeviceIoControl(device, IOCTL_MSR_READ, &req, sizeof(req), &req, sizeof(req), &bytes, NULL)) {
191 - if (temperature_fcnt)
192 - cpus[cpu].cpu_temp = temperature_fcnt(&req);
193 - else
194 - cpus[cpu].cpu_temp = 0;
234 + if (netdata_read_msr(&req)) {
235 + collected_number temp = 0;
236 + if (temperature_fcnt) {
237 + temp = temperature_fcnt(&req);
238 + }
239 +
240 + if (temp != INVALID_TEMP) {
241 + cpus[cpu].last_valid_temp = temp;
242 + cpus[cpu].cpu_temp = temp;
243 + cpus[cpu].read_errors = 0;
244 + } else {
245 + cpus[cpu].cpu_temp = cpus[cpu].last_valid_temp;
246 + cpus[cpu].read_errors++;
247 + }
248 } else {
196 - cpus[cpu].cpu_temp = 0;
249 + cpus[cpu].cpu_temp = cpus[cpu].last_valid_temp;
250 + cpus[cpu].read_errors++;
251 }
252 }
253 LeaveCriticalSection(&cpus_lock);
200 -
201 - CloseHandle(device);
254 }
255
256 static void get_hardware_info_thread(void *ptr __maybe_unused)
@@ -240,9 +292,28 @@ static void netdata_detect_cpu()
292
293 static int initialize()
294 {
295 + char expanded_path[MAX_PATH];
296 + if (ExpandEnvironmentStringsA(drv_path, expanded_path, sizeof(expanded_path)) == 0) {
297 + nd_log(
298 + NDLS_COLLECTORS, NDLP_ERR, "Cannot expand driver path environment strings. Error= %lu \n", GetLastError());
299 + return -1;
300 + }
301 +
302 + if (GetFileAttributesA(expanded_path) == INVALID_FILE_ATTRIBUTES) {
303 + nd_log(
304 + NDLS_COLLECTORS,
305 + NDLP_ERR,
306 + "Driver not found at '%s'. Please ensure the driver is properly installed.\n",
307 + expanded_path);
308 + return -1;
309 + }
310 +
311 InitializeCriticalSection(&cpus_lock);
312 cpus_lock_initialized = true;
313
314 + InitializeCriticalSection(&device_lock);
315 + device_lock_initialized = true;
316 +
317 netdata_detect_cpu();
318 if (!temperature_fcnt) {
319 return -1;
@@ -259,6 +330,12 @@ static int initialize()
330 ncpus = os_get_system_cpus();
331 cpus = callocz(ncpus, sizeof(struct cpu_data));
332
333 + for (size_t i = 0; i < ncpus; i++) {
334 + cpus[i].cpu_temp = INVALID_TEMP;
335 + cpus[i].last_valid_temp = INVALID_TEMP;
336 + cpus[i].read_errors = 0;
337 + }
338 +
339 hardware_info_thread =
340 nd_thread_create("hw_info_thread", NETDATA_THREAD_OPTION_DEFAULT, get_hardware_info_thread, NULL);
341
@@ -299,7 +376,12 @@ static void netdata_loop_cpu_chart(int update_every)
376 snprintfz(id, RRD_ID_LENGTH_MAX, "cpu%d.temp", i);
377 lcpu->rd_cpu_temp = rrddim_add(chart, id, NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
378 }
302 - rrddim_set_by_pointer(chart, lcpu->rd_cpu_temp, lcpu->cpu_temp);
379 +
380 + if (lcpu->cpu_temp != INVALID_TEMP) {
381 + rrddim_set_by_pointer(chart, lcpu->rd_cpu_temp, lcpu->cpu_temp);
382 + } else {
383 + rrddim_set_by_pointer(chart, lcpu->rd_cpu_temp, 0);
384 + }
385 }
386 LeaveCriticalSection(&cpus_lock);
387
@@ -328,11 +410,19 @@ void do_GetHardwareInfo_cleanup()
410 nd_log_daemon(NDLP_ERR, "Failed to join Get Hardware Info thread");
411 }
412
413 + if (msr_device != INVALID_HANDLE_VALUE) {
414 + CloseHandle(msr_device);
415 + msr_device = INVALID_HANDLE_VALUE;
416 + }
417 +
418 netdata_stop_driver();
419
420 if (cpus_lock_initialized)
421 DeleteCriticalSection(&cpus_lock);
422
423 + if (device_lock_initialized)
424 + DeleteCriticalSection(&device_lock);
425 +
426 if (cpus) {
427 freez(cpus);
428 cpus = NULL;
src/collectors/windows.plugin/metadata.yaml
+146 -20
@@ -41,7 +41,13 @@ modules:
41 description: ""
42 setup:
43 prerequisites:
44 - list: []
44 + list:
45 + - name: Netdata installation
46 + description: |
47 + When Netdata is installed on Windows, it automatically registers as a Windows Service
48 + and appears in "Add or remove programs" (also known as "Programs and Features" or
49 + "Apps & features" in newer Windows versions). The service can be managed through
50 + Windows Services (services.msc) or via the Netdata UI.
51 configuration:
52 file:
53 name: "netdata.conf"
@@ -144,7 +150,13 @@ modules:
150 description: ""
151 setup:
152 prerequisites:
147 - list: []
153 + list:
154 + - name: Netdata installation
155 + description: |
156 + When Netdata is installed on Windows, it automatically registers as a Windows Service
157 + and appears in "Add or remove programs" (also known as "Programs and Features" or
158 + "Apps & features" in newer Windows versions). The service can be managed through
159 + Windows Services (services.msc) or via the Netdata UI.
160 configuration:
161 file:
162 name: "netdata.conf"
@@ -247,7 +259,13 @@ modules:
259 description: ""
260 setup:
261 prerequisites:
250 - list: []
262 + list:
263 + - name: Netdata installation
264 + description: |
265 + When Netdata is installed on Windows, it automatically registers as a Windows Service
266 + and appears in "Add or remove programs" (also known as "Programs and Features" or
267 + "Apps & features" in newer Windows versions). The service can be managed through
268 + Windows Services (services.msc) or via the Netdata UI.
269 configuration:
270 file:
271 name: "netdata.conf"
@@ -350,7 +368,13 @@ modules:
368 description: ""
369 setup:
370 prerequisites:
353 - list: []
371 + list:
372 + - name: Netdata installation
373 + description: |
374 + When Netdata is installed on Windows, it automatically registers as a Windows Service
375 + and appears in "Add or remove programs" (also known as "Programs and Features" or
376 + "Apps & features" in newer Windows versions). The service can be managed through
377 + Windows Services (services.msc) or via the Netdata UI.
378 configuration:
379 file:
380 name: "netdata.conf"
@@ -532,7 +556,13 @@ modules:
556 description: ""
557 setup:
558 prerequisites:
535 - list: []
559 + list:
560 + - name: Netdata installation
561 + description: |
562 + When Netdata is installed on Windows, it automatically registers as a Windows Service
563 + and appears in "Add or remove programs" (also known as "Programs and Features" or
564 + "Apps & features" in newer Windows versions). The service can be managed through
565 + Windows Services (services.msc) or via the Netdata UI.
566 configuration:
567 file:
568 name: "netdata.conf"
@@ -855,7 +885,13 @@ modules:
885 description: ""
886 setup:
887 prerequisites:
858 - list: []
888 + list:
889 + - name: Netdata installation
890 + description: |
891 + When Netdata is installed on Windows, it automatically registers as a Windows Service
892 + and appears in "Add or remove programs" (also known as "Programs and Features" or
893 + "Apps & features" in newer Windows versions). The service can be managed through
894 + Windows Services (services.msc) or via the Netdata UI.
895 configuration:
896 file:
897 name: "netdata.conf"
@@ -942,7 +978,13 @@ modules:
978 description: ""
979 setup:
980 prerequisites:
945 - list: []
981 + list:
982 + - name: Netdata installation
983 + description: |
984 + When Netdata is installed on Windows, it automatically registers as a Windows Service
985 + and appears in "Add or remove programs" (also known as "Programs and Features" or
986 + "Apps & features" in newer Windows versions). The service can be managed through
987 + Windows Services (services.msc) or via the Netdata UI.
988 configuration:
989 file:
990 name: "netdata.conf"
@@ -1023,7 +1065,13 @@ modules:
1065 description: ""
1066 setup:
1067 prerequisites:
1026 - list: []
1068 + list:
1069 + - name: Netdata installation
1070 + description: |
1071 + When Netdata is installed on Windows, it automatically registers as a Windows Service
1072 + and appears in "Add or remove programs" (also known as "Programs and Features" or
1073 + "Apps & features" in newer Windows versions). The service can be managed through
1074 + Windows Services (services.msc) or via the Netdata UI.
1075 configuration:
1076 file:
1077 section_name: "[plugin:windows:PerflibThermalZone]"
@@ -1103,7 +1151,13 @@ modules:
1151 description: ""
1152 setup:
1153 prerequisites:
1106 - list: []
1154 + list:
1155 + - name: Netdata installation
1156 + description: |
1157 + When Netdata is installed on Windows, it automatically registers as a Windows Service
1158 + and appears in "Add or remove programs" (also known as "Programs and Features" or
1159 + "Apps & features" in newer Windows versions). The service can be managed through
1160 + Windows Services (services.msc) or via the Netdata UI.
1161 configuration:
1162 file:
1163 section_name: "[plugin:windows:GetPowerSupply]"
@@ -1196,7 +1250,13 @@ modules:
1250 description: ""
1251 setup:
1252 prerequisites:
1199 - list: []
1253 + list:
1254 + - name: Netdata installation
1255 + description: |
1256 + When Netdata is installed on Windows, it automatically registers as a Windows Service
1257 + and appears in "Add or remove programs" (also known as "Programs and Features" or
1258 + "Apps & features" in newer Windows versions). The service can be managed through
1259 + Windows Services (services.msc) or via the Netdata UI.
1260 configuration:
1261 file:
1262 section_name: "[plugin:windows:GetSensors]"
@@ -1422,7 +1482,13 @@ modules:
1482 description: ""
1483 setup:
1484 prerequisites:
1425 - list: []
1485 + list:
1486 + - name: Netdata installation
1487 + description: |
1488 + When Netdata is installed on Windows, it automatically registers as a Windows Service
1489 + and appears in "Add or remove programs" (also known as "Programs and Features" or
1490 + "Apps & features" in newer Windows versions). The service can be managed through
1491 + Windows Services (services.msc) or via the Netdata UI.
1492 configuration:
1493 file:
1494 name: "netdata.conf"
@@ -1740,7 +1806,13 @@ modules:
1806 description: ""
1807 setup:
1808 prerequisites:
1743 - list: []
1809 + list:
1810 + - name: Netdata installation
1811 + description: |
1812 + When Netdata is installed on Windows, it automatically registers as a Windows Service
1813 + and appears in "Add or remove programs" (also known as "Programs and Features" or
1814 + "Apps & features" in newer Windows versions). The service can be managed through
1815 + Windows Services (services.msc) or via the Netdata UI.
1816 configuration:
1817 file:
1818 name: "netdata.conf"
@@ -2111,6 +2183,12 @@ modules:
2183 setup:
2184 prerequisites:
2185 list:
2186 + - title: Netdata installation
2187 + description: |
2188 + When Netdata is installed on Windows, it automatically registers as a Windows Service
2189 + and appears in "Add or remove programs" (also known as "Programs and Features" or
2190 + "Apps & features" in newer Windows versions). The service can be managed through
2191 + Windows Services (services.msc) or via the Netdata UI.
2192 - title: Configure SQL Server for Monitoring
2193 description: |
2194 For **each SQL Server** instance you want to monitor, complete the following steps:
@@ -2728,7 +2806,13 @@ modules:
2806 description: ""
2807 setup:
2808 prerequisites:
2731 - list: []
2809 + list:
2810 + - name: Netdata installation
2811 + description: |
2812 + When Netdata is installed on Windows, it automatically registers as a Windows Service
2813 + and appears in "Add or remove programs" (also known as "Programs and Features" or
2814 + "Apps & features" in newer Windows versions). The service can be managed through
2815 + Windows Services (services.msc) or via the Netdata UI.
2816 configuration:
2817 file:
2818 name: "netdata.conf"
@@ -2993,7 +3077,13 @@ modules:
3077 description: ""
3078 setup:
3079 prerequisites:
2996 - list: []
3080 + list:
3081 + - name: Netdata installation
3082 + description: |
3083 + When Netdata is installed on Windows, it automatically registers as a Windows Service
3084 + and appears in "Add or remove programs" (also known as "Programs and Features" or
3085 + "Apps & features" in newer Windows versions). The service can be managed through
3086 + Windows Services (services.msc) or via the Netdata UI.
3087 configuration:
3088 file:
3089 name: "netdata.conf"
@@ -3159,7 +3249,13 @@ modules:
3249 description: ""
3250 setup:
3251 prerequisites:
3162 - list: []
3252 + list:
3253 + - name: Netdata installation
3254 + description: |
3255 + When Netdata is installed on Windows, it automatically registers as a Windows Service
3256 + and appears in "Add or remove programs" (also known as "Programs and Features" or
3257 + "Apps & features" in newer Windows versions). The service can be managed through
3258 + Windows Services (services.msc) or via the Netdata UI.
3259 configuration:
3260 file:
3261 name: "netdata.conf"
@@ -3335,7 +3431,13 @@ modules:
3431 description: ""
3432 setup:
3433 prerequisites:
3338 - list: []
3434 + list:
3435 + - name: Netdata installation
3436 + description: |
3437 + When Netdata is installed on Windows, it automatically registers as a Windows Service
3438 + and appears in "Add or remove programs" (also known as "Programs and Features" or
3439 + "Apps & features" in newer Windows versions). The service can be managed through
3440 + Windows Services (services.msc) or via the Netdata UI.
3441 configuration:
3442 file:
3443 name: "netdata.conf"
@@ -3610,7 +3712,13 @@ modules:
3712 description: ""
3713 setup:
3714 prerequisites:
3613 - list: []
3715 + list:
3716 + - name: Netdata installation
3717 + description: |
3718 + When Netdata is installed on Windows, it automatically registers as a Windows Service
3719 + and appears in "Add or remove programs" (also known as "Programs and Features" or
3720 + "Apps & features" in newer Windows versions). The service can be managed through
3721 + Windows Services (services.msc) or via the Netdata UI.
3722 configuration:
3723 file:
3724 name: "netdata.conf"
@@ -3702,7 +3810,13 @@ modules:
3810 description: ""
3811 setup:
3812 prerequisites:
3705 - list: []
3813 + list:
3814 + - name: Netdata installation
3815 + description: |
3816 + When Netdata is installed on Windows, it automatically registers as a Windows Service
3817 + and appears in "Add or remove programs" (also known as "Programs and Features" or
3818 + "Apps & features" in newer Windows versions). The service can be managed through
3819 + Windows Services (services.msc) or via the Netdata UI.
3820 configuration:
3821 file:
3822 name: "netdata.conf"
@@ -3965,7 +4079,13 @@ modules:
4079 description: ""
4080 setup:
4081 prerequisites:
3968 - list: []
4082 + list:
4083 + - name: Netdata installation
4084 + description: |
4085 + When Netdata is installed on Windows, it automatically registers as a Windows Service
4086 + and appears in "Add or remove programs" (also known as "Programs and Features" or
4087 + "Apps & features" in newer Windows versions). The service can be managed through
4088 + Windows Services (services.msc) or via the Netdata UI.
4089 configuration:
4090 file:
4091 name: "netdata.conf"
@@ -4050,7 +4170,13 @@ modules:
4170 description: ""
4171 setup:
4172 prerequisites:
4053 - list: []
4173 + list:
4174 + - name: Netdata installation
4175 + description: |
4176 + When Netdata is installed on Windows, it automatically registers as a Windows Service
4177 + and appears in "Add or remove programs" (also known as "Programs and Features" or
4178 + "Apps & features" in newer Windows versions). The service can be managed through
4179 + Windows Services (services.msc) or via the Netdata UI.
4180 configuration:
4181 file:
4182 name: "netdata.conf"
src/collectors/windows.plugin/windows_plugin.c
+1 -1
@@ -50,7 +50,7 @@ static struct proc_module {
50 .cleanup = do_Sensors_cleanup},
51 {.name = "GetHardwareInfo",
52 .dim = "GetHardwareInfo",
53 - .enabled = CONFIG_BOOLEAN_NO,
53 + .enabled = CONFIG_BOOLEAN_YES,
54 .update_every = 10 * UPDATE_EVERY_MIN,
55 .func = do_GetHardwareInfo,
56 .rd = NULL,