Skip to content

Commit

Permalink
Windows storage fixes (netdata#18880)
Browse files Browse the repository at this point in the history
* fix gaps on windows storage charts

* removed obsolete labels
  • Loading branch information
ktsaou authored Oct 27, 2024
1 parent 9ccb3a4 commit d6d7b93
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 72 deletions.
137 changes: 66 additions & 71 deletions src/collectors/windows.plugin/perflib-storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,17 @@ static void physical_disk_labels(RRDSET *st, void *data) {
if (d->mount_point)
rrdlabels_add(st->rrdlabels, "mount_point", string2str(d->mount_point), RRDLABEL_SRC_AUTO);

if (d->manufacturer)
rrdlabels_add(st->rrdlabels, "manufacturer", string2str(d->manufacturer), RRDLABEL_SRC_AUTO);
// if (d->manufacturer)
// rrdlabels_add(st->rrdlabels, "manufacturer", string2str(d->manufacturer), RRDLABEL_SRC_AUTO);

if (d->model)
rrdlabels_add(st->rrdlabels, "model", string2str(d->model), RRDLABEL_SRC_AUTO);

if (d->media_type)
rrdlabels_add(st->rrdlabels, "media_type", string2str(d->media_type), RRDLABEL_SRC_AUTO);
// if (d->media_type)
// rrdlabels_add(st->rrdlabels, "media_type", string2str(d->media_type), RRDLABEL_SRC_AUTO);

if (d->name)
rrdlabels_add(st->rrdlabels, "name", string2str(d->name), RRDLABEL_SRC_AUTO);
// if (d->name)
// rrdlabels_add(st->rrdlabels, "name", string2str(d->name), RRDLABEL_SRC_AUTO);

if (d->device_id)
rrdlabels_add(st->rrdlabels, "device_id", string2str(d->device_id), RRDLABEL_SRC_AUTO);
Expand All @@ -333,34 +333,48 @@ static bool str_is_numeric(const char *s) {
}

static inline double perflib_average_timer_ms(COUNTER_DATA *d) {
if(!d->updated) return 0.0;

ULONGLONG data1 = d->current.Data;
ULONGLONG data0 = d->previous.Data;
LONGLONG time1 = d->current.Time;
LONGLONG time0 = d->previous.Time;
LONGLONG freq1 = d->current.Frequency;

LONGLONG dt = (time1 - time0);
if(dt > 0)
return ((double)(data1 - data0) / (double)(freq1 / MSEC_PER_SEC)) / dt;
else
return 0;
if(data1 >= data0 && time1 > time0 && time0 && freq1)
return ((double)(data1 - data0) / (double)(freq1 / MSEC_PER_SEC)) / (double)(time1 - time0);

return 0;
}

static inline uint64_t perflib_average_bulk(COUNTER_DATA *d) {
if(!d->updated) return 0;

ULONGLONG data1 = d->current.Data;
ULONGLONG data0 = d->previous.Data;
LONGLONG time1 = d->current.Time;
LONGLONG time0 = d->previous.Time;

LONGLONG dt = (time1 - time0);
if(dt > 0)
return (data1 - data0) / dt;
else
return 0;
if(data1 >= data0 && time1 > time0 && time0)
return (data1 - data0) / (time1 - time0);

return 0;
}

static inline bool perflib_previous_is_set(COUNTER_DATA *d) {
return d->updated && d->previous.Data && d->previous.Time && d->current.Time > d->previous.Time;
static inline uint64_t perflib_idle_time_percent(COUNTER_DATA *d) {
if(!d->updated) return 0.0;

ULONGLONG data1 = d->current.Data;
ULONGLONG data0 = d->previous.Data;
LONGLONG time1 = d->current.Time;
LONGLONG time0 = d->previous.Time;

if(data1 >= data0 && time1 > time0 && time0) {
uint64_t pcent = 100 * (data1 - data0) / (time1 - time0);
return pcent > 100 ? 100 : pcent;
}

return 0;
}

#define MAX_WMI_DRIVES 100
Expand Down Expand Up @@ -467,23 +481,14 @@ static bool do_physical_disk(PERF_DATA_BLOCK *pDataBlock, int update_every, usec
}

if (perflibGetInstanceCounter(pDataBlock, pObjectType, pi, &d->percentIdleTime)) {
if (perflib_previous_is_set(&d->percentIdleTime)) {
collected_number idle_percentage =
100 * (d->percentIdleTime.current.Data - d->percentIdleTime.previous.Data)
/ (d->percentIdleTime.current.Time - d->percentIdleTime.previous.Time);

if (idle_percentage > 100)
idle_percentage = 100;

common_disk_util(
&d->disk_util,
device,
NULL,
100 - idle_percentage,
update_every,
physical_disk_labels,
d);
}
common_disk_util(
&d->disk_util,
device,
NULL,
100 - perflib_idle_time_percent(&d->percentIdleTime),
update_every,
physical_disk_labels,
d);
}

if (perflibGetInstanceCounter(pDataBlock, pObjectType, pi, &d->percentDiskTime)) {
Expand Down Expand Up @@ -525,50 +530,40 @@ static bool do_physical_disk(PERF_DATA_BLOCK *pDataBlock, int update_every, usec
if (perflibGetInstanceCounter(pDataBlock, pObjectType, pi, &d->averageDiskSecondsPerRead) &&
perflibGetInstanceCounter(pDataBlock, pObjectType, pi, &d->averageDiskSecondsPerWrite)) {

if (perflib_previous_is_set(&d->averageDiskSecondsPerRead) &&
perflib_previous_is_set(&d->averageDiskSecondsPerWrite)) {

common_disk_await(
&d->disk_await,
device,
NULL,
perflib_average_timer_ms(&d->averageDiskSecondsPerRead),
perflib_average_timer_ms(&d->averageDiskSecondsPerWrite),
update_every,
physical_disk_labels,
d);
}
common_disk_await(
&d->disk_await,
device,
NULL,
perflib_average_timer_ms(&d->averageDiskSecondsPerRead),
perflib_average_timer_ms(&d->averageDiskSecondsPerWrite),
update_every,
physical_disk_labels,
d);
}

if (perflibGetInstanceCounter(pDataBlock, pObjectType, pi, &d->averageDiskSecondsPerTransfer)) {
if (perflib_previous_is_set(&d->averageDiskSecondsPerTransfer)) {
common_disk_svctm(
&d->disk_svctm,
device,
NULL,
perflib_average_timer_ms(&d->averageDiskSecondsPerTransfer),
update_every,
physical_disk_labels,
d);
}
common_disk_svctm(
&d->disk_svctm,
device,
NULL,
perflib_average_timer_ms(&d->averageDiskSecondsPerTransfer),
update_every,
physical_disk_labels,
d);
}

if (perflibGetInstanceCounter(pDataBlock, pObjectType, pi, &d->averageDiskBytesPerRead) &&
perflibGetInstanceCounter(pDataBlock, pObjectType, pi, &d->averageDiskBytesPerWrite)) {

if (perflib_previous_is_set(&d->averageDiskBytesPerRead) &&
perflib_previous_is_set(&d->averageDiskBytesPerWrite)) {

common_disk_avgsz(
&d->disk_avgsz,
device,
NULL,
perflib_average_bulk(&d->averageDiskBytesPerRead),
perflib_average_bulk(&d->averageDiskBytesPerWrite),
update_every,
physical_disk_labels,
d);
}
common_disk_avgsz(
&d->disk_avgsz,
device,
NULL,
perflib_average_bulk(&d->averageDiskBytesPerRead),
perflib_average_bulk(&d->averageDiskBytesPerWrite),
update_every,
physical_disk_labels,
d);
}

if(perflibGetInstanceCounter(pDataBlock, pObjectType, pi, &d->splitIoPerSec)) {
Expand Down
2 changes: 1 addition & 1 deletion src/collectors/windows.plugin/windows-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef NETDATA_WINDOWS_INTERNALS_H
#define NETDATA_WINDOWS_INTERNALS_H

#include "libnetdata/common.h"
#include "libnetdata/libnetdata.h"

static inline ULONGLONG FileTimeToULL(FILETIME ft) {
ULARGE_INTEGER ul;
Expand Down

0 comments on commit d6d7b93

Please sign in to comment.