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 optional metric process.memory.utilization #14633

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-memory-utilization-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.memory.utilization` to the metrics scraped by 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 @@ -102,6 +102,14 @@ The amount of physical memory in use.
| ---- | ----------- | ---------- | ----------------------- | --------- |
| By | Sum | Int | Cumulative | false |

### process.memory.utilization

Percentage of total physical memory that is used by the process.

| Unit | Metric Type | Value Type |
| ---- | ----------- | ---------- |
| 1 | Gauge | Double |

### process.memory.virtual

Virtual memory size.
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 @@ -129,6 +129,13 @@ metrics:
aggregation: cumulative
monotonic: false

process.memory.utilization:
enabled: false
description: Percentage of total physical memory that is used by the process.
unit: 1
Comment on lines +134 to +135
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@astencel-sumo it's unclear from the docs and unit if the metric is emitted in a fraction of 1 of percentage. I believe it's the same issue for other "utilization" metrics in hostreceiver. Maybe even not well defined in the spec. Can you please help with making it consistent and clear?

gauge:
value_type: double

process.disk.io:
enabled: true
description: Disk bytes transferred.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type processHandle interface {
Times() (*cpu.TimesStat, error)
Percent(time.Duration) (float64, error)
MemoryInfo() (*process.MemoryInfoStat, error)
MemoryPercent() (float32, error)
IOCounters() (*process.IOCountersStat, error)
NumThreads() (int32, error)
CreateTime() (int64, error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ import (
)

const (
cpuMetricsLen = 1
memoryMetricsLen = 2
diskMetricsLen = 1
pagingMetricsLen = 1
threadMetricsLen = 1
contextSwitchMetricsLen = 1
fileDescriptorMetricsLen = 1
signalMetricsLen = 1

metricsLen = cpuMetricsLen + memoryMetricsLen + diskMetricsLen + pagingMetricsLen + threadMetricsLen + contextSwitchMetricsLen + fileDescriptorMetricsLen + signalMetricsLen
cpuMetricsLen = 1
memoryMetricsLen = 2
memoryUtilizationMetricsLen = 1
diskMetricsLen = 1
pagingMetricsLen = 1
threadMetricsLen = 1
contextSwitchMetricsLen = 1
fileDescriptorMetricsLen = 1
signalMetricsLen = 1

metricsLen = cpuMetricsLen + memoryMetricsLen + diskMetricsLen + memoryUtilizationMetricsLen + pagingMetricsLen + threadMetricsLen + contextSwitchMetricsLen + fileDescriptorMetricsLen + signalMetricsLen
)

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

if err = s.scrapeAndAppendMemoryUtilizationMetric(now, md.handle); err != nil {
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 {
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 @@ -254,6 +259,21 @@ func (s *scraper) scrapeAndAppendMemoryUsageMetrics(now pcommon.Timestamp, handl
return nil
}

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

memoryPercent, err := handle.MemoryPercent()
if err != nil {
return err
}

s.mb.RecordProcessMemoryUtilizationDataPoint(now, float64(memoryPercent))

return nil
}

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