Skip to content

Commit

Permalink
disk plugin: Report time metrics in seconds.
Browse files Browse the repository at this point in the history
  • Loading branch information
octo committed Feb 3, 2024
1 parent b7c3278 commit cd5352f
Showing 1 changed file with 45 additions and 39 deletions.
84 changes: 45 additions & 39 deletions src/disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ static int disk_read(void) {
metric_family_t fam_ops_time = {
.name = "system.disk.operation_time",
.help = "Sum of the time each operation took to complete",
.unit = "us",
.type = METRIC_TYPE_COUNTER,
.unit = "s",
.type = METRIC_TYPE_FPCOUNTER,
};
metric_family_t fam_merged = {
.name = "system.disk.merged",
Expand All @@ -400,8 +400,8 @@ static int disk_read(void) {
metric_family_t fam_disk_io_time = {
.name = "system.disk.io_time",
.help = "Time disk spent activated",
.unit = "us",
.type = METRIC_TYPE_COUNTER,
.unit = "s",
.type = METRIC_TYPE_FPCOUNTER,
};
metric_family_t fam_disk_io_weighted_time = {
.name = "system.disk.weighted_io_time",
Expand All @@ -410,8 +410,8 @@ static int disk_read(void) {
"number of milliseconds spent doing I/O since the last update of "
"this field. This can provide an easy measure of both I/O "
"completion time and the backlog that may be accumulating.",
.unit = "ms",
.type = METRIC_TYPE_COUNTER,
.unit = "s",
.type = METRIC_TYPE_FPCOUNTER,
};
metric_family_t fam_disk_pending_operations = {
.name = "system.disk.pending_operations",
Expand Down Expand Up @@ -590,10 +590,12 @@ static int disk_read(void) {
(value_t){.counter = write_ops}, &m);
}
if ((read_time_ns != -1LL) || (write_time_ns != -1LL)) {
metric_family_append(&fam_ops_time, direction_label, read_direction,
(value_t){.derive = read_time_ns / 1000}, &m);
metric_family_append(&fam_ops_time, direction_label, write_direction,
(value_t){.derive = write_time_ns / 1000}, &m);
metric_family_append(
&fam_ops_time, direction_label, read_direction,
(value_t){.fpcounter = ((fpcounter_t)read_time_ns) / 1e9}, &m);
metric_family_append(
&fam_ops_time, direction_label, write_direction,
(value_t){.fpcounter = ((fpcounter_t)write_time_ns) / 1e9}, &m);
}
metric_reset(&m);
}
Expand Down Expand Up @@ -718,29 +720,29 @@ static int disk_read(void) {
long double write_time_s =
devstat_compute_etime(&snap_iter->duration[DEVSTAT_WRITE], NULL);
if ((read_time_s != 0) || (write_time_s != 0)) {
metric_family_append(
&fam_ops_time, direction_label, read_direction,
(value_t){.derive = (derive_t)(read_time_s * 1000000.0)}, &m);
metric_family_append(
&fam_ops_time, direction_label, write_direction,
(value_t){.derive = (derive_t)(write_time_s * 1000000.0)}, &m);
metric_family_append(&fam_ops_time, direction_label, read_direction,
(value_t){.fpcounter = (fpcounter_t)read_time_s},
&m);
metric_family_append(&fam_ops_time, direction_label, write_direction,
(value_t){.fpcounter = (fpcounter_t)write_time_s},
&m);
}

long double busy_time = 0, utilization = 0, total_duration = 0;
long double busy_time = 0, utilization = 0, total_duration_s = 0;
uint64_t queue_length = 0;
if (devstat_compute_statistics(
snap_iter, NULL, 1.0, DSM_TOTAL_BUSY_TIME, &busy_time, DSM_BUSY_PCT,
&utilization, DSM_TOTAL_DURATION, &total_duration, DSM_QUEUE_LENGTH,
&queue_length, DSM_NONE) != 0) {
&utilization, DSM_TOTAL_DURATION, &total_duration_s,
DSM_QUEUE_LENGTH, &queue_length, DSM_NONE) != 0) {
WARNING("%s", devstat_errbuf);
} else {
m.value.counter = (counter_t)(1000000.0 * busy_time);
m.value.fpcounter = (fpcounter_t)busy_time;
metric_family_metric_append(&fam_disk_io_time, m);

m.value.gauge = (gauge_t)utilization;
metric_family_metric_append(&fam_utilization, m);

m.value.counter = (counter_t)total_duration;
m.value.fpcounter = (fpcounter_t)total_duration_s;
metric_family_metric_append(&fam_disk_io_weighted_time, m);

m.value.gauge = (gauge_t)queue_length;
Expand Down Expand Up @@ -768,7 +770,7 @@ static int disk_read(void) {
counter_t write_time_ms = 0;
gauge_t in_progress = NAN;
counter_t io_time_ms = 0;
counter_t weighted_time = 0;
counter_t weighted_time_ms = 0;
gauge_t io_time_rate_ms = NAN; // unit: ms/s

diskstats_t *ds, *pre_ds;
Expand Down Expand Up @@ -830,7 +832,7 @@ static int disk_read(void) {
in_progress = atof(fields[11]);

io_time_ms = parse_counter(fields[12]);
weighted_time = parse_counter(fields[13]);
weighted_time_ms = parse_counter(fields[13]);
}

/* Scale the "sectors" counters to bytes. */
Expand Down Expand Up @@ -895,10 +897,12 @@ static int disk_read(void) {
}

if ((read_time_ms != 0) || (write_time_ms != 0)) {
metric_family_append(&fam_ops_time, direction_label, read_direction,
(value_t){.derive = read_time_ms * 1000}, &m);
metric_family_append(&fam_ops_time, direction_label, write_direction,
(value_t){.derive = write_time_ms * 1000}, &m);
metric_family_append(
&fam_ops_time, direction_label, read_direction,
(value_t){.fpcounter = ((fpcounter_t)read_time_ms) / 1000}, &m);
metric_family_append(
&fam_ops_time, direction_label, write_direction,
(value_t){.fpcounter = ((fpcounter_t)write_time_ms) / 1000}, &m);
}

if (read_merged != 0 || write_merged != 0) {
Expand All @@ -914,12 +918,12 @@ static int disk_read(void) {
}

if (io_time_ms != 0) {
m.value.derive = 1000 * io_time_ms;
m.value.fpcounter = ((fpcounter_t)io_time_ms) / 1000.0;
metric_family_metric_append(&fam_disk_io_time, m);
}

if (weighted_time != 0) {
m.value.counter = weighted_time;
if (weighted_time_ms != 0) {
m.value.fpcounter = ((fpcounter_t)weighted_time_ms) / 1000.0;
metric_family_metric_append(&fam_disk_io_weighted_time, m);
}

Expand Down Expand Up @@ -1008,11 +1012,11 @@ static int disk_read(void) {

if (strncmp(ksp[i]->ks_class, "disk", strlen("disk")) == 0) {
hrtime_t run_time_ns = kio.rtime;
m.value.derive = (derive_t)(run_time_ns / 1000);
m.value.fpcounter = ((fpcounter_t)run_time_ns) / 1e9;
metric_family_metric_append(&fam_disk_io_time, m);

hrtime_t weighted_io_time_ns = kio.rlentime;
m.value.derive = (derive_t)(weighted_io_time_ns / 1000000);
m.value.fpcounter = ((fpcounter_t)weighted_io_time_ns) / 1e9;
metric_family_metric_append(&fam_disk_io_weighted_time, m);

uint_t ops_waiting = kio.wcnt;
Expand Down Expand Up @@ -1106,12 +1110,14 @@ static int disk_read(void) {
_system_configuration.Xfrac;
derive_t write_time_ns = stat_disk[i].wserv * _system_configuration.Xint /
_system_configuration.Xfrac;
metric_family_append(&fam_ops_time, direction_label, read_direction,
(value_t){.derive = read_time_ns / 1000}, &m);
metric_family_append(&fam_ops_time, direction_label, write_direction,
(value_t){.derive = write_time_ns / 1000, &m);
metric_family_append(
&fam_ops_time, direction_label, read_direction,
(value_t){.fpcounter = ((fpcounter_t)read_time_ns) / 1e9}, &m);
metric_family_append(
&fam_ops_time, direction_label, write_direction,
(value_t){.fpcounter = ((fpcounter_t)write_time_ns) / 1e9}, &m);

metric_reset(&m);
metric_reset(&m);
}
/* #endif defined(HAVE_PERFSTAT) */
#elif HAVE_SYSCTL && KERNEL_NETBSD
Expand Down Expand Up @@ -1170,8 +1176,8 @@ static int disk_read(void) {
metric_family_append(&fam_ops, direction_label, write_direction,
(value_t){.counter = drives[i].wxfer}, &m);

m.value.derive = ((derive_t)drives[i].time_sec * 1000000) +
((derive_t)drives[i].time_usec);
m.value.fpcounter = ((fpcounter_t)drives[i].time_sec) +
((fpcounter_t)drives[i].time_usec) / 1e6;
metric_family_metric_append(&fam_disk_io_time, m);

metric_reset(&m);
Expand Down

0 comments on commit cd5352f

Please sign in to comment.