Skip to content
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
5 changes: 5 additions & 0 deletions internal/lib/stats/descriptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ var (
Help: "Container swap usage in bytes.",
LabelKeys: baseLabelKeys,
}
containerSpecMemoryLimitBytes = &types.MetricDescriptor{
Name: "container_spec_memory_limit_bytes",
Help: "Memory limit for the container in bytes.",
LabelKeys: baseLabelKeys,
}
containerMemoryFailcnt = &types.MetricDescriptor{
Name: "container_memory_failcnt",
Help: "Number of memory usage hits limits",
Expand Down
17 changes: 17 additions & 0 deletions internal/lib/stats/memory_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"github.com/cri-o/cri-o/internal/oci"
)

// Size after which we consider memory to be "unlimited". This is not
// MaxInt64 due to rounding by the kernel.
const maxMemorySize = uint64(1 << 62)

func generateSandboxMemoryMetrics(sb *sandbox.Sandbox, mem *cgmgr.MemoryStats) []*types.Metric {
memoryMetrics := []*containerMetric{
{
Expand Down Expand Up @@ -40,6 +44,19 @@ func generateSandboxMemoryMetrics(sb *sandbox.Sandbox, mem *cgmgr.MemoryStats) [
return metricValues{{value: mem.SwapUsage, metricType: types.MetricType_GAUGE}}
},
},
{
desc: containerSpecMemoryLimitBytes,
valueFunc: func() metricValues {
// For consistency with cAdvisor and Kubernetes, consider memory to be "unlimited"
// when above a certain threshold (2^62) and report it as 0 in the metrics.
// This approach is more useful for monitoring tools than reporting the physical limit.
limit := mem.Limit
if limit > maxMemorySize {
return metricValues{{value: 0, metricType: types.MetricType_GAUGE}}
}
return metricValues{{value: limit, metricType: types.MetricType_GAUGE}}
},
},
{
desc: containerMemoryFailcnt,
valueFunc: func() metricValues {
Expand Down
1 change: 1 addition & 0 deletions internal/lib/stats/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (ss *StatsServer) PopulateMetricDescriptors(includedKeys []string) map[stri
containerMemoryKernelUsage,
containerMemoryMappedFile,
containerMemorySwap,
containerSpecMemoryLimitBytes,
containerMemoryFailcnt,
containerMemoryUsageBytes,
containerMemoryMaxUsageBytes,
Expand Down