Skip to content

Commit

Permalink
Add disk/weighted_io_time (Linux only)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-bebbington committed Dec 21, 2020
1 parent 7a6598f commit 31c0def
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), 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)
assertInt64DiskMetricValid(t, metrics.At(5), diskMergedDescriptor, test.expectedStartTime)
assertDoubleDiskMetricValid(t, metrics.At(6), diskWeightedIOTimeDescriptor, true, 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 31c0def

Please sign in to comment.