Skip to content

Commit

Permalink
hostmetricsreceiver/memoryscraper: Add available memory metric
Browse files Browse the repository at this point in the history
  • Loading branch information
lootek committed Feb 21, 2023
1 parent fdd01de commit 0d4fc66
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`` |

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 @@ -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) {
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,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",
Expand All @@ -202,7 +202,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",
Expand All @@ -218,6 +218,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) {
Expand All @@ -229,4 +231,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()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0d4fc66

Please sign in to comment.