Skip to content

Commit

Permalink
[receiver/hostmetrics] Add optional metric `process.memory.utilizatio…
Browse files Browse the repository at this point in the history
…n` (#14633)

[receiver/hostmetrics] add optional metric `process.memory.utilization`
  • Loading branch information
andrzej-stencel authored Dec 14, 2022
1 parent bc29302 commit 989a66b
Show file tree
Hide file tree
Showing 8 changed files with 181 additions and 15 deletions.
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
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

0 comments on commit 989a66b

Please sign in to comment.