Skip to content

Commit f163691

Browse files
authored
Merge pull request #3555 from j4ckstraw/add-load-d-metrics
Add uninterruptible metric load d
2 parents fe54aa3 + 80e7063 commit f163691

6 files changed

+31
-1
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",

metrics/prometheus_fake.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ func (p testSubcontainersInfoProvider) GetRequestedContainersInfo(string, v2.Req
326326
RunqueueTime: 479424566378,
327327
RunPeriods: 984285,
328328
},
329-
LoadAverage: 2,
329+
LoadAverage: 2,
330+
LoadDAverage: 2,
330331
},
331332
Memory: info.MemoryStats{
332333
Usage: 8,

metrics/testdata/prometheus_metrics

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ container_cpu_cfs_throttled_seconds_total{container_env_foo_env="prod",container
2121
# HELP container_cpu_load_average_10s Value of container cpu load average over the last 10 seconds.
2222
# TYPE container_cpu_load_average_10s gauge
2323
container_cpu_load_average_10s{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 2 1395066363000
24+
# HELP container_cpu_load_d_average_10s Value of container cpu load.d average over the last 10 seconds.
25+
# TYPE container_cpu_load_d_average_10s gauge
26+
container_cpu_load_d_average_10s{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 2 1395066363000
2427
# HELP container_cpu_schedstat_run_periods_total Number of times processes of the cgroup have run on the cpu
2528
# TYPE container_cpu_schedstat_run_periods_total counter
2629
container_cpu_schedstat_run_periods_total{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 984285 1395066363000

metrics/testdata/prometheus_metrics_whitelist_filtered

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ container_cpu_cfs_throttled_seconds_total{container_env_foo_env="prod",id="testc
2121
# HELP container_cpu_load_average_10s Value of container cpu load average over the last 10 seconds.
2222
# TYPE container_cpu_load_average_10s gauge
2323
container_cpu_load_average_10s{container_env_foo_env="prod",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 2 1395066363000
24+
# HELP container_cpu_load_d_average_10s Value of container cpu load.d average over the last 10 seconds.
25+
# TYPE container_cpu_load_d_average_10s gauge
26+
container_cpu_load_d_average_10s{container_env_foo_env="prod",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 2 1395066363000
2427
# HELP container_cpu_schedstat_run_periods_total Number of times processes of the cgroup have run on the cpu
2528
# TYPE container_cpu_schedstat_run_periods_total counter
2629
container_cpu_schedstat_run_periods_total{container_env_foo_env="prod",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 984285 1395066363000

0 commit comments

Comments
 (0)