Skip to content

Commit

Permalink
[receiver/hostmetrics] Add optional metric process.disk.operations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzej-stencel authored Dec 20, 2022
1 parent d777e30 commit 50333f4
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 9 deletions.
16 changes: 16 additions & 0 deletions .chloggen/add-process-disk-operations-metric.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: hostmetricsreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add a new optional metric `process.disk.operations` to the `process` scraper of the `hostmetrics` receiver.

# One or more tracking issues related to the change
issues: [14084]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ Percentage of total CPU time used by the process since last scrape, expressed as
| ---- | ----------- | ------ |
| state | Breakdown of CPU usage by type. | Str: ``system``, ``user``, ``wait`` |

### process.disk.operations

Number of disk operations performed by the process.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic |
| ---- | ----------- | ---------- | ----------------------- | --------- |
| {operations} | Sum | Int | Cumulative | true |

#### Attributes

| Name | Description | Values |
| ---- | ----------- | ------ |
| direction | Direction of flow of bytes (read or write). | Str: ``read``, ``write`` |

### process.memory.usage

The amount of physical memory in use.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,13 @@ metrics:
aggregation: cumulative
monotonic: true
attributes: [context_switch_type]

process.disk.operations:
enabled: false
description: Number of disk operations performed by the process.
unit: "{operations}"
sum:
value_type: int
aggregation: cumulative
monotonic: true
attributes: [direction]
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (s *scraper) scrape(_ context.Context) (pmetric.Metrics, error) {
errs.AddPartial(memoryUtilizationMetricsLen, fmt.Errorf("error reading memory utilization for process %q (pid %v): %w", md.executable.name, md.pid, err))
}

if err = s.scrapeAndAppendDiskIOMetric(now, md.handle); err != nil {
if err = s.scrapeAndAppendDiskMetrics(now, md.handle); err != nil {
errs.AddPartial(diskMetricsLen, fmt.Errorf("error reading disk usage for process %q (pid %v): %w", md.executable.name, md.pid, err))
}

Expand Down Expand Up @@ -274,8 +274,8 @@ func (s *scraper) scrapeAndAppendMemoryUtilizationMetric(now pcommon.Timestamp,
return nil
}

func (s *scraper) scrapeAndAppendDiskIOMetric(now pcommon.Timestamp, handle processHandle) error {
if !s.config.Metrics.ProcessDiskIo.Enabled {
func (s *scraper) scrapeAndAppendDiskMetrics(now pcommon.Timestamp, handle processHandle) error {
if !(s.config.Metrics.ProcessDiskIo.Enabled || s.config.Metrics.ProcessDiskOperations.Enabled) {
return nil
}

Expand All @@ -286,6 +286,8 @@ func (s *scraper) scrapeAndAppendDiskIOMetric(now pcommon.Timestamp, handle proc

s.mb.RecordProcessDiskIoDataPoint(now, int64(io.ReadBytes), metadata.AttributeDirectionRead)
s.mb.RecordProcessDiskIoDataPoint(now, int64(io.WriteBytes), metadata.AttributeDirectionWrite)
s.mb.RecordProcessDiskOperationsDataPoint(now, int64(io.ReadCount), metadata.AttributeDirectionRead)
s.mb.RecordProcessDiskOperationsDataPoint(now, int64(io.WriteCount), metadata.AttributeDirectionWrite)

return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ func TestScrape(t *testing.T) {
assertMetricMissing(t, md.ResourceMetrics(), "process.cpu.utilization")
}
assertMemoryUsageMetricValid(t, md.ResourceMetrics(), expectedStartTime)
assertOldDiskIOMetricValid(t, md.ResourceMetrics(), expectedStartTime)
assertDiskIoMetricValid(t, md.ResourceMetrics(), expectedStartTime)
if metricsSettings.ProcessDiskOperations.Enabled {
assertDiskOperationsMetricValid(t, md.ResourceMetrics(), expectedStartTime)
} else {
assertMetricMissing(t, md.ResourceMetrics(), "process.disk.operations")
}
if metricsSettings.ProcessPagingFaults.Enabled {
assertPagingMetricValid(t, md.ResourceMetrics(), expectedStartTime)
}
Expand Down Expand Up @@ -259,15 +264,26 @@ func assertMetricMissing(t *testing.T, resourceMetrics pmetric.ResourceMetricsSl
}
}

func assertOldDiskIOMetricValid(t *testing.T, resourceMetrics pmetric.ResourceMetricsSlice,
func assertDiskIoMetricValid(t *testing.T, resourceMetrics pmetric.ResourceMetricsSlice,
startTime pcommon.Timestamp) {
diskIOMetric := getMetric(t, "process.disk.io", resourceMetrics)
diskIoMetric := getMetric(t, "process.disk.io", resourceMetrics)
if startTime != 0 {
internal.AssertSumMetricStartTimeEquals(t, diskIoMetric, startTime)
}
internal.AssertSumMetricHasAttributeValue(t, diskIoMetric, 0, "direction",
pcommon.NewValueStr(metadata.AttributeDirectionRead.String()))
internal.AssertSumMetricHasAttributeValue(t, diskIoMetric, 1, "direction",
pcommon.NewValueStr(metadata.AttributeDirectionWrite.String()))
}

func assertDiskOperationsMetricValid(t *testing.T, resourceMetrics pmetric.ResourceMetricsSlice, startTime pcommon.Timestamp) {
diskOperationsMetric := getMetric(t, "process.disk.operations", resourceMetrics)
if startTime != 0 {
internal.AssertSumMetricStartTimeEquals(t, diskIOMetric, startTime)
internal.AssertSumMetricStartTimeEquals(t, diskOperationsMetric, startTime)
}
internal.AssertSumMetricHasAttributeValue(t, diskIOMetric, 0, "direction",
internal.AssertSumMetricHasAttributeValue(t, diskOperationsMetric, 0, "direction",
pcommon.NewValueStr(metadata.AttributeDirectionRead.String()))
internal.AssertSumMetricHasAttributeValue(t, diskIOMetric, 1, "direction",
internal.AssertSumMetricHasAttributeValue(t, diskOperationsMetric, 1, "direction",
pcommon.NewValueStr(metadata.AttributeDirectionWrite.String()))
}

Expand Down Expand Up @@ -945,6 +961,7 @@ func TestScrapeMetrics_DontCheckDisabledMetrics(t *testing.T) {

metricSettings.ProcessCPUTime.Enabled = false
metricSettings.ProcessDiskIo.Enabled = false
metricSettings.ProcessDiskOperations.Enabled = false
metricSettings.ProcessMemoryPhysicalUsage.Enabled = false
metricSettings.ProcessMemoryVirtualUsage.Enabled = false

Expand Down

0 comments on commit 50333f4

Please sign in to comment.