Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[receiver/hostmetrics] Add process.paging.faults metric #14604

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .chloggen/add-process-paging-faults-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 metric `process.paging.faults` 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:
6 changes: 4 additions & 2 deletions receiver/hostmetricsreceiver/hostmetrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,10 @@ func assertIncludesExpectedMetrics(t *testing.T, got pmetric.Metrics) {
return
}

assert.Equal(t, len(resourceMetrics), len(returnedResourceMetrics))
for _, expected := range resourceMetrics {
var expectedResourceMetrics []string
expectedResourceMetrics = append(expectedResourceMetrics, resourceMetrics...)
assert.Equal(t, len(expectedResourceMetrics), len(returnedResourceMetrics))
for _, expected := range expectedResourceMetrics {
assert.Contains(t, returnedResourceMetrics, expected)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ These are the metrics available for this scraper.
| **process.disk.io** | Disk bytes transferred. | By | Sum(Int) | <ul> <li>direction</li> </ul> |
| **process.memory.physical_usage** | The amount of physical memory in use. | By | Sum(Int) | <ul> </ul> |
| **process.memory.virtual_usage** | Virtual memory size. | By | Sum(Int) | <ul> </ul> |
| process.paging.faults | Number of page faults the process has made. This metric is only available on Linux. | {faults} | Sum(Int) | <ul> <li>type</li> </ul> |
| process.threads | Process threads count. | {threads} | Sum(Int) | <ul> </ul> |

**Highlighted metrics** are emitted by default. Other metrics are optional and not emitted by default.
Expand Down Expand Up @@ -41,3 +42,4 @@ metrics:
| ---- | ----------- | ------ |
| direction | Direction of flow of bytes (read or write). | read, write |
| state | Breakdown of CPU usage by type. | system, user, wait |
| type | Type of memory paging fault. | major, minor |

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 @@ -47,6 +47,10 @@ attributes:
description: Breakdown of CPU usage by type.
enum: [system, user, wait]

type:
description: Type of memory paging fault.
enum: [major, minor]

metrics:
process.cpu.time:
enabled: true
Expand Down Expand Up @@ -86,6 +90,16 @@ metrics:
monotonic: true
attributes: [direction]

process.paging.faults:
enabled: false
description: Number of page faults the process has made. This metric is only available on Linux.
unit: "{faults}"
sum:
value_type: int
aggregation: cumulative
monotonic: true
attributes: [type]

process.threads:
enabled: false
description: Process threads count.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type processHandle interface {
NumThreads() (int32, error)
CreateTime() (int64, error)
Parent() (*process.Process, error)
PageFaults() (*process.PageFaultsStat, error)
}

type gopsProcessHandles struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ const (
cpuMetricsLen = 1
memoryMetricsLen = 2
diskMetricsLen = 1
pagingMetricsLen = 1
threadMetricsLen = 1

metricsLen = cpuMetricsLen + memoryMetricsLen + diskMetricsLen + threadMetricsLen
metricsLen = cpuMetricsLen + memoryMetricsLen + diskMetricsLen + pagingMetricsLen + threadMetricsLen
)

// scraper for Process Metrics
Expand Down Expand Up @@ -113,6 +114,10 @@ func (s *scraper) scrape(_ context.Context) (pmetric.Metrics, error) {
errs.AddPartial(diskMetricsLen, fmt.Errorf("error reading disk usage for process %q (pid %v): %w", md.executable.name, md.pid, err))
}

if err = s.scrapeAndAppendPagingMetric(now, md.handle); err != nil {
errs.AddPartial(pagingMetricsLen, fmt.Errorf("error reading memory paging info for process %q (pid %v): %w", md.executable.name, md.pid, err))
}

if err = s.scrapeAndAppendThreadsMetrics(now, md.handle); err != nil {
errs.AddPartial(threadMetricsLen, fmt.Errorf("error reading thread info for process %q (pid %v): %w", md.executable.name, md.pid, err))
}
Expand Down Expand Up @@ -229,6 +234,21 @@ func (s *scraper) scrapeAndAppendDiskIOMetric(now pcommon.Timestamp, handle proc
return nil
}

func (s *scraper) scrapeAndAppendPagingMetric(now pcommon.Timestamp, handle processHandle) error {
if !s.config.Metrics.ProcessPagingFaults.Enabled {
return nil
}

pageFaultsStat, err := handle.PageFaults()
if err != nil {
return err
}

s.mb.RecordProcessPagingFaultsDataPoint(now, int64(pageFaultsStat.MajorFaults), metadata.AttributeTypeMajor)
s.mb.RecordProcessPagingFaultsDataPoint(now, int64(pageFaultsStat.MinorFaults), metadata.AttributeTypeMinor)
return nil
}

func (s *scraper) scrapeAndAppendThreadsMetrics(now pcommon.Timestamp, handle processHandle) error {
if !s.config.Metrics.ProcessThreads.Enabled {
return nil
Expand Down
Loading