Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
bfc4ea7
Emit system.memory.shared in hostmetricsreceiver
osullivandonal Dec 29, 2025
18ba18d
generate the neccesary code for system.memory.shared
osullivandonal Dec 29, 2025
7fdac29
Add system.memory.shared to receiver/hostmetrics for linux only
osullivandonal Dec 30, 2025
7a13db0
Test receiver/hostmetrics system.memory.shared on linux
osullivandonal Dec 30, 2025
b372a60
Update system.memory.shared description for receiver/hostmetrics
osullivandonal Dec 30, 2025
0615d67
Add change log for adding new system.memory.shared metric
osullivandonal Dec 30, 2025
a36b732
Merge branch 'main' into hostmetricsreceiver-add-systemmemoryshared-m…
osullivandonal Jan 6, 2026
0a6c8f3
Merge branch 'main' into hostmetricsreceiver-add-systemmemoryshared-m…
osullivandonal Jan 6, 2026
e8a7069
Merge branch 'main' into hostmetricsreceiver-add-systemmemoryshared-m…
osullivandonal Jan 6, 2026
fdb6318
Merge branch 'main' into hostmetricsreceiver-add-systemmemoryshared-m…
osullivandonal Jan 7, 2026
c2f0004
Merge branch 'main' into hostmetricsreceiver-add-systemmemoryshared-m…
osullivandonal Jan 7, 2026
13f2a9a
docs(receiver/hostmetrics): clarify system.memory.shared is Linux-only
osullivandonal Jan 7, 2026
958b857
Merge branch 'main' into hostmetricsreceiver-add-systemmemoryshared-m…
osullivandonal Jan 15, 2026
3d982a9
Update hostmetricsreceiver metric system.memory.shared to be system.m…
osullivandonal Jan 15, 2026
b8d2201
Generate code and docs from updating hostmetricsreceiver shared metric
osullivandonal Jan 15, 2026
1f0302c
Update hostmetricsreceiver memory scraper for linux shared mem
osullivandonal Jan 15, 2026
b7ab719
Update changelog for system.memory.linux.shared metric
osullivandonal Jan 15, 2026
96a23fe
Merge branch 'main' into hostmetricsreceiver-add-systemmemoryshared-m…
osullivandonal Jan 15, 2026
1709177
Update hostmetricsreceiver shared memory description
osullivandonal Jan 19, 2026
451af87
Update test to correct test system.memory.linux.shared
osullivandonal Jan 19, 2026
831d228
Merge branch 'main' into hostmetricsreceiver-add-systemmemoryshared-m…
osullivandonal Jan 19, 2026
0029f1b
Merge branch 'main' into hostmetricsreceiver-add-systemmemoryshared-m…
osullivandonal Jan 20, 2026
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Use this changelog template to create an entry for release notes.

# 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. receiver/filelog)
component: receiver/hostmetrics

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add optional `system.memory.linux.shared` metric

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [32712]

# (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: |
This metric reports shared memory usage, including tmpfs filesystems,
System V shared memory, and POSIX shared memory. Currently only available
on Linux systems due to platform-specific data availability.
This corresponds to the `Shmem` field in `/proc/meminfo`.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ Total bytes of memory available.
| ---- | ----------- | ---------- | ----------------------- | --------- | --------- |
| By | Sum | Int | Cumulative | false | Development |

### system.memory.linux.shared

Shared memory usage, including tmpfs filesystems and System V/POSIX shared memory. Only supported on Linux.

| Unit | Metric Type | Value Type | Aggregation Temporality | Monotonic | Stability |
| ---- | ----------- | ---------- | ----------------------- | --------- | --------- |
| By | Sum | Int | Cumulative | false | Development |

### system.memory.page_size

A constant value for the system's configured page 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.

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 @@ -7,6 +7,8 @@ all_set:
enabled: true
system.memory.limit:
enabled: true
system.memory.linux.shared:
enabled: true
system.memory.page_size:
enabled: true
system.memory.usage:
Expand All @@ -21,6 +23,8 @@ none_set:
enabled: false
system.memory.limit:
enabled: false
system.memory.linux.shared:
enabled: false
system.memory.page_size:
enabled: false
system.memory.usage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ func (s *memoryScraper) recordMemoryUsageMetric(now pcommon.Timestamp, memInfo *
s.mb.RecordSystemMemoryUsageDataPoint(now, int64(memInfo.Sunreclaim), metadata.AttributeStateSlabUnreclaimable)
}

func (s *memoryScraper) recordMemoryLinuxSharedMetric(now pcommon.Timestamp, memInfo *mem.VirtualMemoryStat) {
s.mb.RecordSystemMemoryLinuxSharedDataPoint(now, int64(memInfo.Shared))
}

func (s *memoryScraper) recordMemoryUtilizationMetric(now pcommon.Timestamp, memInfo *mem.VirtualMemoryStat) {
// TODO: rely on memInfo.Used value once https://github.com/shirou/gopsutil/pull/1882 is released
// gopsutil formula: https://github.com/shirou/gopsutil/pull/1882/files#diff-5af8322731595fb792b48f3c38f31ddb24f596cf11a74a9c37b19734597baef6R321
Expand Down Expand Up @@ -66,4 +70,5 @@ func (s *memoryScraper) recordLinuxMemoryDirtyMetric(now pcommon.Timestamp, memI
func (s *memoryScraper) recordSystemSpecificMetrics(now pcommon.Timestamp, memInfo *mem.VirtualMemoryStat) {
s.recordLinuxMemoryAvailableMetric(now, memInfo)
s.recordLinuxMemoryDirtyMetric(now, memInfo)
s.recordMemoryLinuxSharedMetric(now, memInfo)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/scraper/scrapertest"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/internal/metadata"
Expand Down Expand Up @@ -53,3 +54,40 @@ func TestScrape_UseMemAvailable(t *testing.T) {
assert.Greater(t, memUsedMd.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).IntValue(), legacyMd.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(0).Sum().DataPoints().At(0).IntValue(), "system.memory.usage for the used state should be greater when computed using memAvailable")
assert.Greater(t, memUsedMd.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(1).Gauge().DataPoints().At(0).DoubleValue(), legacyMd.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics().At(1).Gauge().DataPoints().At(0).DoubleValue(), "system.memory.utilization for the used state should be greater when computed using memAvailable")
}

func TestScrape_SharedMemory(t *testing.T) {
mbc := metadata.DefaultMetricsBuilderConfig()
mbc.Metrics.SystemMemoryLinuxShared.Enabled = true
scraperConfig := Config{
MetricsBuilderConfig: mbc,
}
scraper := newMemoryScraper(t.Context(), scrapertest.NewNopSettings(metadata.Type), &scraperConfig)

err := scraper.start(t.Context(), componenttest.NewNopHost())
require.NoError(t, err, "Failed to initialize memory scraper: %v", err)

memInfo, err := scraper.virtualMemory(t.Context())
require.NoError(t, err)
require.NotNil(t, memInfo)

scraper.recordMemoryLinuxSharedMetric(pcommon.NewTimestampFromTime(time.Now()), memInfo)
md := scraper.mb.Emit()

require.Equal(t, 1, md.ResourceMetrics().Len())
require.Equal(t, 1, md.ResourceMetrics().At(0).ScopeMetrics().Len())

metrics := md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics()
require.Equal(t, 1, metrics.Len(), "Expected exactly one metric")

metric := metrics.At(0)
assert.Equal(t, "system.memory.linux.shared", metric.Name())
assert.Equal(t, pmetric.MetricTypeSum, metric.Type())

dataPoints := metric.Sum().DataPoints()
require.Equal(t, 1, dataPoints.Len(), "Expected exactly one data point")

assert.GreaterOrEqual(t, dataPoints.At(0).IntValue(), int64(0))

_, hasState := dataPoints.At(0).Attributes().Get("state")
assert.False(t, hasState, "system.memory.shared should not have a state attribute")
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func TestScrape(t *testing.T) {
SystemMemoryPageSize: metadata.MetricConfig{
Enabled: true,
},
SystemMemoryLinuxShared: metadata.MetricConfig{
Enabled: true,
},
SystemLinuxMemoryAvailable: metadata.MetricConfig{
Enabled: true,
},
Expand All @@ -66,7 +69,7 @@ func TestScrape(t *testing.T) {
},
expectedMetricCount: func() int {
if runtime.GOOS == "linux" {
return 5
return 6
}
return 3
}(),
Expand Down Expand Up @@ -127,15 +130,22 @@ func TestScrape(t *testing.T) {

metrics := md.ResourceMetrics().At(0).ScopeMetrics().At(0).Metrics()
memUsageIdx := -1
memSharedIdx := -1
for i := 0; i < md.MetricCount(); i++ {
if metrics.At(i).Name() == "system.memory.usage" {
memUsageIdx = i
}
if metrics.At(i).Name() == "system.memory.linux.shared" {
memSharedIdx = i
}
}
assert.NotEqual(t, -1, memUsageIdx)
assertMemoryUsageMetricValid(t, metrics.At(memUsageIdx), "system.memory.usage")

if runtime.GOOS == "linux" {
if memSharedIdx != -1 {
assertMemorySharedMetricValid(t, metrics.At(memSharedIdx), "system.memory.linux.shared")
}
assertMemoryUsageMetricHasLinuxSpecificStateLabels(t, metrics.At(memUsageIdx))
} else if runtime.GOOS != "windows" {
internal.AssertSumMetricHasAttributeValue(t, metrics.At(memUsageIdx), 2, "state",
Expand Down Expand Up @@ -202,6 +212,20 @@ func TestScrape_MemoryUtilization(t *testing.T) {
}
}

func assertMemorySharedMetricValid(t *testing.T, metric pmetric.Metric, expectedName string) {
assert.Equal(t, expectedName, metric.Name())
assert.Equal(t, pmetric.MetricTypeSum, metric.Type())
assert.Equal(t, "By", metric.Unit())
assert.Equal(t, "Shared memory usage, including tmpfs filesystems and System V/POSIX shared memory. Only supported on Linux.", metric.Description())
assert.False(t, metric.Sum().IsMonotonic(), "shared memory is not monotonic")
assert.Equal(t, pmetric.AggregationTemporalityCumulative, metric.Sum().AggregationTemporality())
dataPoints := metric.Sum().DataPoints()
assert.Equal(t, 1, dataPoints.Len(), "should have exactly one data point (no state attribute)")
assert.GreaterOrEqual(t, dataPoints.At(0).IntValue(), int64(0), "shared memory should be non-negative")
_, hasState := dataPoints.At(0).Attributes().Get("state")
assert.False(t, hasState, "system.memory.shared should not have a state attribute")
}

func assertMemoryUsageMetricValid(t *testing.T, metric pmetric.Metric, expectedName string) {
assert.Equal(t, expectedName, metric.Name())
assert.GreaterOrEqual(t, metric.Sum().DataPoints().Len(), 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ metrics:
value_type: int
aggregation_temporality: cumulative
monotonic: false

system.memory.limit:
enabled: false
description: Total bytes of memory available.
Expand All @@ -49,6 +50,17 @@ metrics:
aggregation_temporality: cumulative
monotonic: false

system.memory.linux.shared:
enabled: false
description: Shared memory usage, including tmpfs filesystems and System V/POSIX shared memory. Only supported on Linux.
unit: By
stability:
level: development
sum:
value_type: int
aggregation_temporality: cumulative
monotonic: false

system.memory.page_size:
enabled: false
description: A constant value for the system's configured page size.
Expand Down