bugfix: add nil pointer check for cgroup v1 mem usage

Signed-off-by: Cardy.Tang <zuniorone@gmail.com>
This commit is contained in:
Cardy.Tang 2023-05-19 09:49:58 +08:00
parent 73645b1dfe
commit a35ead5b9d

View File

@ -543,7 +543,7 @@ var memoryMetrics = []*metric{
unit: metrics.Total, unit: metrics.Total,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetUsage() == nil {
return nil return nil
} }
return []value{ return []value{
@ -559,7 +559,7 @@ var memoryMetrics = []*metric{
unit: metrics.Bytes, unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetUsage() == nil {
return nil return nil
} }
return []value{ return []value{
@ -575,7 +575,7 @@ var memoryMetrics = []*metric{
unit: metrics.Bytes, unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetUsage() == nil {
return nil return nil
} }
return []value{ return []value{
@ -591,7 +591,7 @@ var memoryMetrics = []*metric{
unit: metrics.Bytes, unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetUsage() == nil {
return nil return nil
} }
return []value{ return []value{
@ -607,7 +607,7 @@ var memoryMetrics = []*metric{
unit: metrics.Total, unit: metrics.Total,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetSwap() == nil {
return nil return nil
} }
return []value{ return []value{
@ -623,7 +623,7 @@ var memoryMetrics = []*metric{
unit: metrics.Bytes, unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetSwap() == nil {
return nil return nil
} }
return []value{ return []value{
@ -639,7 +639,7 @@ var memoryMetrics = []*metric{
unit: metrics.Bytes, unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetSwap() == nil {
return nil return nil
} }
return []value{ return []value{
@ -655,7 +655,7 @@ var memoryMetrics = []*metric{
unit: metrics.Bytes, unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetSwap() == nil {
return nil return nil
} }
return []value{ return []value{
@ -671,7 +671,7 @@ var memoryMetrics = []*metric{
unit: metrics.Total, unit: metrics.Total,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetKernel() == nil {
return nil return nil
} }
return []value{ return []value{
@ -687,7 +687,7 @@ var memoryMetrics = []*metric{
unit: metrics.Bytes, unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetKernel() == nil {
return nil return nil
} }
return []value{ return []value{
@ -703,7 +703,7 @@ var memoryMetrics = []*metric{
unit: metrics.Bytes, unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetKernel() == nil {
return nil return nil
} }
return []value{ return []value{
@ -719,7 +719,7 @@ var memoryMetrics = []*metric{
unit: metrics.Bytes, unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetKernel() == nil {
return nil return nil
} }
return []value{ return []value{
@ -735,7 +735,7 @@ var memoryMetrics = []*metric{
unit: metrics.Total, unit: metrics.Total,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetKernelTCP() == nil {
return nil return nil
} }
return []value{ return []value{
@ -751,7 +751,7 @@ var memoryMetrics = []*metric{
unit: metrics.Bytes, unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetKernelTCP() == nil {
return nil return nil
} }
return []value{ return []value{
@ -767,7 +767,7 @@ var memoryMetrics = []*metric{
unit: metrics.Bytes, unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetKernelTCP() == nil {
return nil return nil
} }
return []value{ return []value{
@ -783,7 +783,7 @@ var memoryMetrics = []*metric{
unit: metrics.Bytes, unit: metrics.Bytes,
vt: prometheus.GaugeValue, vt: prometheus.GaugeValue,
getValues: func(stats *v1.Metrics) []value { getValues: func(stats *v1.Metrics) []value {
if stats.Memory == nil { if stats.GetMemory().GetKernelTCP() == nil {
return nil return nil
} }
return []value{ return []value{