@cryptotaxi247 / netdata-1 / commits / f16d13c2b

Adjust Disk Size (Windows.plugin) (#21081)

thiagoftsm committed Oct 1, 2025 at 12:47 UTC f16d13c2bca8a521928f481a2ed78c330db7a687
2 files changed +12 -15
src/collectors/windows.plugin/perflib-storage.c
+8 -15
@@ -14,6 +14,7 @@ struct logical_disk {
14
15 UINT DriveType;
16 DWORD SerialNumber;
17 + ULONG divisor;
18 bool readonly;
19
20 STRING *filesystem;
@@ -238,13 +239,6 @@ static const char *drive_type_to_str(UINT type)
239 }
240 }
241
241 -static inline LONGLONG convertToBytes(LONGLONG value, double factor) {
242 - double dvalue = value;
243 - dvalue /= (factor);
244 -
245 - return (LONGLONG) dvalue*100;
246 -}
247 -
242 static inline void netdata_set_hd_usage(PERF_DATA_BLOCK *pDataBlock,
243 PERF_OBJECT_TYPE *pObjectType,
244 PERF_INSTANCE_DEFINITION *pi,
@@ -261,19 +255,18 @@ static inline void netdata_set_hd_usage(PERF_DATA_BLOCK *pDataBlock,
255 // Description of incompatibilities present in both methods we are using
256 // https://devblogs.microsoft.com/oldnewthing/20071101-00/?p=24613
257 // We are using the variable that should not be affected by qyota ()
264 - if ((GetDriveTypeA(path) != DRIVE_FIXED) || !GetDiskFreeSpaceExA(path,
258 + if ((GetDriveTypeA(path) == DRIVE_UNKNOWN) || !GetDiskFreeSpaceExA(path,
259 NULL,
260 &totalNumberOfBytes,
261 &totalNumberOfFreeBytes)) {
262 perflibGetInstanceCounter(pDataBlock, pObjectType, pi, &d->percentDiskFree);
269 -
270 - d->percentDiskFree.current.Data = convertToBytes(d->percentDiskFree.current.Data, 1024);
271 - d->percentDiskFree.current.Time = convertToBytes(d->percentDiskFree.current.Time, 1024);
263 + d->divisor = 1024;
264 return;
265 }
266
275 - d->percentDiskFree.current.Data = convertToBytes(totalNumberOfFreeBytes.QuadPart, 1024 * 1024 * 1024);
276 - d->percentDiskFree.current.Time = convertToBytes(totalNumberOfBytes.QuadPart, 1024 * 1024 * 1024);
267 + d->divisor = GIGA_FACTOR;
268 + d->percentDiskFree.current.Data = totalNumberOfFreeBytes.QuadPart;
269 + d->percentDiskFree.current.Time = totalNumberOfBytes.QuadPart;
270 }
271
272 static bool do_logical_disk(PERF_DATA_BLOCK *pDataBlock, int update_every, usec_t now_ut)
@@ -338,8 +331,8 @@ static bool do_logical_disk(PERF_DATA_BLOCK *pDataBlock, int update_every, usec_
331 rrdlabels_add(d->st_disk_space->rrdlabels, "serial_number", buf, RRDLABEL_SRC_AUTO);
332 }
333
341 - d->rd_disk_space_free = rrddim_add(d->st_disk_space, "avail", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE);
342 - d->rd_disk_space_used = rrddim_add(d->st_disk_space, "used", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE);
334 + d->rd_disk_space_free = rrddim_add(d->st_disk_space, "avail", NULL, 1, d->divisor, RRD_ALGORITHM_ABSOLUTE);
335 + d->rd_disk_space_used = rrddim_add(d->st_disk_space, "used", NULL, 1, d->divisor, RRD_ALGORITHM_ABSOLUTE);
336 }
337
338 // percentDiskFree has the free space in Data and the size of the disk in Time, in MiB.
src/collectors/windows.plugin/windows_plugin.h
+4
@@ -15,6 +15,10 @@
15 #define MEGA_FACTOR (1048576)
16 #endif
17
18 +#ifndef GIGA_FACTOR
19 +#define GIGA_FACTOR (1073741824)
20 +#endif
21 +
22 void win_plugin_main(void *ptr);
23
24 extern char windows_shared_buffer[8192];