Skip to content

Commit

Permalink
Add disk/weighted_io_time (Linux only) (#2312)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-bebbington committed Jan 3, 2021
1 parent c9d5a7d commit 2b25f11
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
2 changes: 1 addition & 1 deletion receiver/hostmetricsreceiver/hostmetrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ var resourceMetrics = []string{
}

var systemSpecificMetrics = map[string][]string{
"linux": {"system.disk.merged", "system.filesystem.inodes.usage", "system.paging.faults", "system.processes.created", "system.processes.count"},
"linux": {"system.disk.merged", "system.disk.weighted_io_time", "system.filesystem.inodes.usage", "system.paging.faults", "system.processes.created", "system.processes.count"},
"darwin": {"system.filesystem.inodes.usage", "system.paging.faults", "system.processes.count"},
"freebsd": {"system.filesystem.inodes.usage", "system.paging.faults", "system.processes.count"},
"openbsd": {"system.filesystem.inodes.usage", "system.paging.faults", "system.processes.created", "system.processes.count"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ var diskOperationTimeDescriptor = func() pdata.Metric {
return metric
}()

var diskWeightedIOTimeDescriptor = func() pdata.Metric {
metric := pdata.NewMetric()
metric.SetName("system.disk.weighted_io_time")
metric.SetDescription("Time disk spent activated multiplied by the queue length.")
metric.SetUnit("s")
metric.SetDataType(pdata.MetricDataTypeDoubleSum)
sum := metric.DoubleSum()
sum.SetIsMonotonic(true)
sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative)
return metric
}()

var diskPendingOperationsDescriptor = func() pdata.Metric {
metric := pdata.NewMetric()
metric.SetName("system.disk.pending_operations")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,27 @@ import (
"go.opentelemetry.io/collector/consumer/pdata"
)

const systemSpecificMetricsLen = 1
const systemSpecificMetricsLen = 2

func appendSystemSpecificMetrics(metrics pdata.MetricSlice, startIdx int, startTime, now pdata.TimestampUnixNano, ioCounters map[string]disk.IOCountersStat) {
metric := metrics.At(startIdx)
initializeDiskWeightedIOTimeMetric(metrics.At(startIdx+0), startTime, now, ioCounters)
initializeDiskMergedMetric(metrics.At(startIdx+1), startTime, now, ioCounters)
}

func initializeDiskWeightedIOTimeMetric(metric pdata.Metric, startTime, now pdata.TimestampUnixNano, ioCounters map[string]disk.IOCountersStat) {
diskWeightedIOTimeDescriptor.CopyTo(metric)

ddps := metric.DoubleSum().DataPoints()
ddps.Resize(len(ioCounters))

idx := 0
for device, ioCounter := range ioCounters {
initializeDoubleDataPoint(ddps.At(idx+0), startTime, now, device, "", float64(ioCounter.WeightedIO)/1e3)
idx++
}
}

func initializeDiskMergedMetric(metric pdata.Metric, startTime, now pdata.TimestampUnixNano, ioCounters map[string]disk.IOCountersStat) {
diskMergedDescriptor.CopyTo(metric)

idps := metric.IntSum().DataPoints()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,40 +102,35 @@ func TestScrape(t *testing.T) {
return
}

assert.GreaterOrEqual(t, metrics.Len(), 4)
assert.Equal(t, metricsLen, metrics.Len())

assertInt64DiskMetricValid(t, metrics.At(0), diskIODescriptor, true, test.expectedStartTime)
assertInt64DiskMetricValid(t, metrics.At(1), diskOperationsDescriptor, true, test.expectedStartTime)
assertInt64DiskMetricValid(t, metrics.At(0), diskIODescriptor, test.expectedStartTime)
assertInt64DiskMetricValid(t, metrics.At(1), diskOperationsDescriptor, test.expectedStartTime)
assertDoubleDiskMetricValid(t, metrics.At(2), diskIOTimeDescriptor, false, test.expectedStartTime)
assertDoubleDiskMetricValid(t, metrics.At(3), diskOperationTimeDescriptor, true, test.expectedStartTime)
assertDiskPendingOperationsMetricValid(t, metrics.At(4))

if runtime.GOOS == "linux" {
assertInt64DiskMetricValid(t, metrics.At(5), diskMergedDescriptor, true, test.expectedStartTime)
assertDoubleDiskMetricValid(t, metrics.At(5), diskWeightedIOTimeDescriptor, false, test.expectedStartTime)
assertInt64DiskMetricValid(t, metrics.At(6), diskMergedDescriptor, test.expectedStartTime)
}

internal.AssertSameTimeStampForAllMetrics(t, metrics)
})
}
}

func assertInt64DiskMetricValid(t *testing.T, metric pdata.Metric, expectedDescriptor pdata.Metric, expectDirectionLabels bool, startTime pdata.TimestampUnixNano) {
func assertInt64DiskMetricValid(t *testing.T, metric pdata.Metric, expectedDescriptor pdata.Metric, startTime pdata.TimestampUnixNano) {
internal.AssertDescriptorEqual(t, expectedDescriptor, metric)
if startTime != 0 {
internal.AssertIntSumMetricStartTimeEquals(t, metric, startTime)
}

minExpectedPoints := 1
if expectDirectionLabels {
minExpectedPoints = 2
}
assert.GreaterOrEqual(t, metric.IntSum().DataPoints().Len(), minExpectedPoints)
assert.GreaterOrEqual(t, metric.IntSum().DataPoints().Len(), 2)

internal.AssertIntSumMetricLabelExists(t, metric, 0, deviceLabelName)
if expectDirectionLabels {
internal.AssertIntSumMetricLabelHasValue(t, metric, 0, directionLabelName, readDirectionLabelValue)
internal.AssertIntSumMetricLabelHasValue(t, metric, 1, directionLabelName, writeDirectionLabelValue)
}
internal.AssertIntSumMetricLabelHasValue(t, metric, 0, directionLabelName, readDirectionLabelValue)
internal.AssertIntSumMetricLabelHasValue(t, metric, 1, directionLabelName, writeDirectionLabelValue)
}

func assertDoubleDiskMetricValid(t *testing.T, metric pdata.Metric, expectedDescriptor pdata.Metric, expectDirectionLabels bool, startTime pdata.TimestampUnixNano) {
Expand Down

0 comments on commit 2b25f11

Please sign in to comment.