Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions src/collectors/windows.plugin/perflib-storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct logical_disk {

UINT DriveType;
DWORD SerialNumber;
ULONG divisor;
bool readonly;

STRING *filesystem;
Expand Down Expand Up @@ -238,13 +239,6 @@ static const char *drive_type_to_str(UINT type)
}
}

static inline LONGLONG convertToBytes(LONGLONG value, double factor) {
double dvalue = value;
dvalue /= (factor);

return (LONGLONG) dvalue*100;
}

static inline void netdata_set_hd_usage(PERF_DATA_BLOCK *pDataBlock,
PERF_OBJECT_TYPE *pObjectType,
PERF_INSTANCE_DEFINITION *pi,
Expand All @@ -261,19 +255,18 @@ static inline void netdata_set_hd_usage(PERF_DATA_BLOCK *pDataBlock,
// Description of incompatibilities present in both methods we are using
// https://devblogs.microsoft.com/oldnewthing/20071101-00/?p=24613
// We are using the variable that should not be affected by qyota ()
if ((GetDriveTypeA(path) != DRIVE_FIXED) || !GetDiskFreeSpaceExA(path,
if ((GetDriveTypeA(path) == DRIVE_UNKNOWN) || !GetDiskFreeSpaceExA(path,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you briefly explain this change? Why? Doesn't look like a problem to me, but I'd like to hear "why".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. If the driver cannot be identified, it indicates that the next function could fail.

If the driver can be identified, I try to get the data directly from GetDiskFreeSpaceExA. If that fails, I use Perflib.

The idea is to use Perflib only if there is no way to get the data from the Windows API.

NULL,
&totalNumberOfBytes,
&totalNumberOfFreeBytes)) {
perflibGetInstanceCounter(pDataBlock, pObjectType, pi, &d->percentDiskFree);

d->percentDiskFree.current.Data = convertToBytes(d->percentDiskFree.current.Data, 1024);
d->percentDiskFree.current.Time = convertToBytes(d->percentDiskFree.current.Time, 1024);
d->divisor = 1024;
return;
}

d->percentDiskFree.current.Data = convertToBytes(totalNumberOfFreeBytes.QuadPart, 1024 * 1024 * 1024);
d->percentDiskFree.current.Time = convertToBytes(totalNumberOfBytes.QuadPart, 1024 * 1024 * 1024);
d->divisor = GIGA_FACTOR;
d->percentDiskFree.current.Data = totalNumberOfFreeBytes.QuadPart;
d->percentDiskFree.current.Time = totalNumberOfBytes.QuadPart;
}

static bool do_logical_disk(PERF_DATA_BLOCK *pDataBlock, int update_every, usec_t now_ut)
Expand Down Expand Up @@ -338,8 +331,8 @@ static bool do_logical_disk(PERF_DATA_BLOCK *pDataBlock, int update_every, usec_
rrdlabels_add(d->st_disk_space->rrdlabels, "serial_number", buf, RRDLABEL_SRC_AUTO);
}

d->rd_disk_space_free = rrddim_add(d->st_disk_space, "avail", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE);
d->rd_disk_space_used = rrddim_add(d->st_disk_space, "used", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE);
d->rd_disk_space_free = rrddim_add(d->st_disk_space, "avail", NULL, 1, d->divisor, RRD_ALGORITHM_ABSOLUTE);
d->rd_disk_space_used = rrddim_add(d->st_disk_space, "used", NULL, 1, d->divisor, RRD_ALGORITHM_ABSOLUTE);
}

// percentDiskFree has the free space in Data and the size of the disk in Time, in MiB.
Expand Down
4 changes: 4 additions & 0 deletions src/collectors/windows.plugin/windows_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#define MEGA_FACTOR (1048576)
#endif

#ifndef GIGA_FACTOR
#define GIGA_FACTOR (1073741824)
#endif

void win_plugin_main(void *ptr);

extern char windows_shared_buffer[8192];
Expand Down
Loading