Skip to content

Commit e9ba3fd

Browse files
author
j4ckstraw
committedJul 1, 2024
feat: export cpu uninterruptible metric as load.d
Signed-off-by: j4ckstraw <wljjackstraw@gmail.com>
1 parent fbd519b commit e9ba3fd

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed
 

‎info/v1/container.go

+2
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ type CpuStats struct {
333333
// Load is smoothed over the last 10 seconds. Instantaneous value can be read
334334
// from LoadStats.NrRunning.
335335
LoadAverage int32 `json:"load_average"`
336+
// from LoadStats.NrUninterruptible
337+
LoadDAverage int32 `json:"load_d_average"`
336338
}
337339

338340
type PerDiskStats struct {

‎manager/container.go

+14
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ type containerData struct {
7373
loadReader cpuload.CpuLoadReader
7474
summaryReader *summary.StatsSummary
7575
loadAvg float64 // smoothed load average seen so far.
76+
loadDAvg float64 // smoothed load.d average seen so far.
7677
housekeepingInterval time.Duration
7778
maxHousekeepingInterval time.Duration
7879
allowDynamicHousekeeping bool
@@ -441,6 +442,7 @@ func newContainerData(containerName string, memoryCache *memory.InMemoryCache, h
441442
allowDynamicHousekeeping: allowDynamicHousekeeping,
442443
logUsage: logUsage,
443444
loadAvg: -1.0, // negative value indicates uninitialized.
445+
loadDAvg: -1.0, // negative value indicates uninitialized.
444446
stop: make(chan struct{}),
445447
collectorManager: collectorManager,
446448
onDemandChan: make(chan chan struct{}, 100),
@@ -633,6 +635,14 @@ func (cd *containerData) updateLoad(newLoad uint64) {
633635
}
634636
}
635637

638+
func (cd *containerData) updateLoadD(newLoad uint64) {
639+
if cd.loadDAvg < 0 {
640+
cd.loadDAvg = float64(newLoad) // initialize to the first seen sample for faster stabilization.
641+
} else {
642+
cd.loadDAvg = cd.loadDAvg*cd.loadDecay + float64(newLoad)*(1.0-cd.loadDecay)
643+
}
644+
}
645+
636646
func (cd *containerData) updateStats() error {
637647
stats, statsErr := cd.handler.GetStats()
638648
if statsErr != nil {
@@ -659,6 +669,10 @@ func (cd *containerData) updateStats() error {
659669
cd.updateLoad(loadStats.NrRunning)
660670
// convert to 'milliLoad' to avoid floats and preserve precision.
661671
stats.Cpu.LoadAverage = int32(cd.loadAvg * 1000)
672+
673+
cd.updateLoadD(loadStats.NrUninterruptible)
674+
// convert to 'milliLoad' to avoid floats and preserve precision.
675+
stats.Cpu.LoadDAverage = int32(cd.loadDAvg * 1000)
662676
}
663677
}
664678
if cd.summaryReader != nil {

‎metrics/prometheus.go

+7
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
270270
getValues: func(s *info.ContainerStats) metricValues {
271271
return metricValues{{value: float64(s.Cpu.LoadAverage), timestamp: s.Timestamp}}
272272
},
273+
}, {
274+
name: "container_cpu_load_d_average_10s",
275+
help: "Value of container cpu load.d average over the last 10 seconds.",
276+
valueType: prometheus.GaugeValue,
277+
getValues: func(s *info.ContainerStats) metricValues {
278+
return metricValues{{value: float64(s.Cpu.LoadDAverage), timestamp: s.Timestamp}}
279+
},
273280
}, {
274281
name: "container_tasks_state",
275282
help: "Number of tasks in given state",

0 commit comments

Comments
 (0)