diff --git a/.chloggen/hostmetrics-add-mem-available.yaml b/.chloggen/hostmetrics-add-mem-available.yaml new file mode 100755 index 000000000000..e2d37045020f --- /dev/null +++ b/.chloggen/hostmetrics-add-mem-available.yaml @@ -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 available memory metric. + +# One or more tracking issues related to the change +issues: [7417] + +# (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: diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/documentation.md b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/documentation.md index 419b9c134e1e..f006547c0538 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/documentation.md +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/documentation.md @@ -24,7 +24,7 @@ Bytes of memory in use. | Name | Description | Values | | ---- | ----------- | ------ | -| state | Breakdown of memory usage by type. | Str: ``buffered``, ``cached``, ``inactive``, ``free``, ``slab_reclaimable``, ``slab_unreclaimable``, ``used`` | +| state | Breakdown of memory usage by type. | Str: ``buffered``, ``cached``, ``inactive``, ``free``, ``slab_reclaimable``, ``slab_unreclaimable``, ``used``, ``available`` | ## Optional Metrics @@ -48,4 +48,4 @@ Percentage of memory bytes in use. | Name | Description | Values | | ---- | ----------- | ------ | -| state | Breakdown of memory usage by type. | Str: ``buffered``, ``cached``, ``inactive``, ``free``, ``slab_reclaimable``, ``slab_unreclaimable``, ``used`` | +| state | Breakdown of memory usage by type. | Str: ``buffered``, ``cached``, ``inactive``, ``free``, ``slab_reclaimable``, ``slab_unreclaimable``, ``used``, ``available`` | diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/internal/metadata/generated_metrics.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/internal/metadata/generated_metrics.go index 89d42846ad79..e0df3621820f 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/internal/metadata/generated_metrics.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/internal/metadata/generated_metrics.go @@ -74,6 +74,7 @@ const ( AttributeStateSlabReclaimable AttributeStateSlabUnreclaimable AttributeStateUsed + AttributeStateAvailable ) // String returns the string representation of the AttributeState. @@ -93,6 +94,8 @@ func (av AttributeState) String() string { return "slab_unreclaimable" case AttributeStateUsed: return "used" + case AttributeStateAvailable: + return "available" } return "" } @@ -106,6 +109,7 @@ var MapAttributeState = map[string]AttributeState{ "slab_reclaimable": AttributeStateSlabReclaimable, "slab_unreclaimable": AttributeStateSlabUnreclaimable, "used": AttributeStateUsed, + "available": AttributeStateAvailable, } type metricSystemMemoryUsage struct { diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_linux.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_linux.go index 1493a2d15396..ad60d3cf779b 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_linux.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_linux.go @@ -31,6 +31,7 @@ func (s *scraper) recordMemoryUsageMetric(now pcommon.Timestamp, memInfo *mem.Vi s.mb.RecordSystemMemoryUsageDataPoint(now, int64(memInfo.Cached), metadata.AttributeStateCached) s.mb.RecordSystemMemoryUsageDataPoint(now, int64(memInfo.Sreclaimable), metadata.AttributeStateSlabReclaimable) s.mb.RecordSystemMemoryUsageDataPoint(now, int64(memInfo.Sunreclaim), metadata.AttributeStateSlabUnreclaimable) + s.mb.RecordSystemMemoryUsageDataPoint(now, int64(memInfo.Available), metadata.AttributeStateAvailable) } func (s *scraper) recordMemoryUtilizationMetric(now pcommon.Timestamp, memInfo *mem.VirtualMemoryStat) { @@ -40,4 +41,5 @@ func (s *scraper) recordMemoryUtilizationMetric(now pcommon.Timestamp, memInfo * s.mb.RecordSystemMemoryUtilizationDataPoint(now, float64(memInfo.Cached)/float64(memInfo.Total), metadata.AttributeStateCached) s.mb.RecordSystemMemoryUtilizationDataPoint(now, float64(memInfo.Sreclaimable)/float64(memInfo.Total), metadata.AttributeStateSlabReclaimable) s.mb.RecordSystemMemoryUtilizationDataPoint(now, float64(memInfo.Sunreclaim)/float64(memInfo.Total), metadata.AttributeStateSlabUnreclaimable) + s.mb.RecordSystemMemoryUtilizationDataPoint(now, float64(memInfo.Available)/float64(memInfo.Total), metadata.AttributeStateAvailable) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_others.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_others.go index 290de5431a0c..16f35d5e9ab5 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_others.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_others.go @@ -28,10 +28,12 @@ func (s *scraper) recordMemoryUsageMetric(now pcommon.Timestamp, memInfo *mem.Vi s.mb.RecordSystemMemoryUsageDataPoint(now, int64(memInfo.Used), metadata.AttributeStateUsed) s.mb.RecordSystemMemoryUsageDataPoint(now, int64(memInfo.Free), metadata.AttributeStateFree) s.mb.RecordSystemMemoryUsageDataPoint(now, int64(memInfo.Inactive), metadata.AttributeStateInactive) + s.mb.RecordSystemMemoryUsageDataPoint(now, int64(memInfo.Available), metadata.AttributeStateAvailable) } func (s *scraper) recordMemoryUtilizationMetric(now pcommon.Timestamp, memInfo *mem.VirtualMemoryStat) { s.mb.RecordSystemMemoryUtilizationDataPoint(now, float64(memInfo.Used)/float64(memInfo.Total), metadata.AttributeStateUsed) s.mb.RecordSystemMemoryUtilizationDataPoint(now, float64(memInfo.Free)/float64(memInfo.Total), metadata.AttributeStateFree) s.mb.RecordSystemMemoryUtilizationDataPoint(now, float64(memInfo.Inactive)/float64(memInfo.Total), metadata.AttributeStateInactive) + s.mb.RecordSystemMemoryUtilizationDataPoint(now, float64(memInfo.Available)/float64(memInfo.Total), metadata.AttributeStateAvailable) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_test.go index 72f054261fda..8c505df90fb8 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_test.go @@ -192,7 +192,7 @@ func TestScrape_MemoryUtilization(t *testing.T) { func assertMemoryUsageMetricValid(t *testing.T, metric pmetric.Metric, expectedName string) { assert.Equal(t, expectedName, metric.Name()) - assert.GreaterOrEqual(t, metric.Sum().DataPoints().Len(), 2) + assert.GreaterOrEqual(t, metric.Sum().DataPoints().Len(), 3) internal.AssertSumMetricHasAttributeValue(t, metric, 0, "state", pcommon.NewValueStr(metadata.AttributeStateUsed.String())) internal.AssertSumMetricHasAttributeValue(t, metric, 1, "state", @@ -201,7 +201,7 @@ func assertMemoryUsageMetricValid(t *testing.T, metric pmetric.Metric, expectedN func assertMemoryUtilizationMetricValid(t *testing.T, metric pmetric.Metric, expectedName string) { assert.Equal(t, expectedName, metric.Name()) - assert.GreaterOrEqual(t, metric.Gauge().DataPoints().Len(), 2) + assert.GreaterOrEqual(t, metric.Gauge().DataPoints().Len(), 3) internal.AssertGaugeMetricHasAttributeValue(t, metric, 0, "state", pcommon.NewValueStr(metadata.AttributeStateUsed.String())) internal.AssertGaugeMetricHasAttributeValue(t, metric, 1, "state", @@ -217,6 +217,8 @@ func assertMemoryUsageMetricHasLinuxSpecificStateLabels(t *testing.T, metric pme pcommon.NewValueStr(metadata.AttributeStateSlabReclaimable.String())) internal.AssertSumMetricHasAttributeValue(t, metric, 5, "state", pcommon.NewValueStr(metadata.AttributeStateSlabUnreclaimable.String())) + internal.AssertSumMetricHasAttributeValue(t, metric, 6, "state", + pcommon.NewValueStr(metadata.AttributeStateAvailable.String())) } func assertMemoryUtilizationMetricHasLinuxSpecificStateLabels(t *testing.T, metric pmetric.Metric) { @@ -228,4 +230,6 @@ func assertMemoryUtilizationMetricHasLinuxSpecificStateLabels(t *testing.T, metr pcommon.NewValueStr(metadata.AttributeStateSlabReclaimable.String())) internal.AssertGaugeMetricHasAttributeValue(t, metric, 5, "state", pcommon.NewValueStr(metadata.AttributeStateSlabUnreclaimable.String())) + internal.AssertGaugeMetricHasAttributeValue(t, metric, 6, "state", + pcommon.NewValueStr(metadata.AttributeStateAvailable.String())) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_windows.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_windows.go index 08d4ee16a1ca..5c3cb0a941d1 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_windows.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_windows.go @@ -27,9 +27,11 @@ import ( func (s *scraper) recordMemoryUsageMetric(now pcommon.Timestamp, memInfo *mem.VirtualMemoryStat) { s.mb.RecordSystemMemoryUsageDataPoint(now, int64(memInfo.Used), metadata.AttributeStateUsed) s.mb.RecordSystemMemoryUsageDataPoint(now, int64(memInfo.Free), metadata.AttributeStateFree) + s.mb.RecordSystemMemoryUsageDataPoint(now, int64(memInfo.Available), metadata.AttributeStateAvailable) } func (s *scraper) recordMemoryUtilizationMetric(now pcommon.Timestamp, memInfo *mem.VirtualMemoryStat) { s.mb.RecordSystemMemoryUtilizationDataPoint(now, float64(memInfo.Used)/float64(memInfo.Total), metadata.AttributeStateUsed) s.mb.RecordSystemMemoryUtilizationDataPoint(now, float64(memInfo.Free)/float64(memInfo.Total), metadata.AttributeStateFree) + s.mb.RecordSystemMemoryUtilizationDataPoint(now, float64(memInfo.Available)/float64(memInfo.Total), metadata.AttributeStateAvailable) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/metadata.yaml b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/metadata.yaml index 319986f481ae..8525eef5d74b 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/metadata.yaml +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/metadata.yaml @@ -6,7 +6,7 @@ attributes: state: description: Breakdown of memory usage by type. type: string - enum: [buffered, cached, inactive, free, slab_reclaimable, slab_unreclaimable, used] + enum: [buffered, cached, inactive, free, slab_reclaimable, slab_unreclaimable, used, available] metrics: system.memory.usage: