Skip to content

Commit a640594

Browse files
committed
Add Misc cgroup support to Prometheus metrics
1 parent 8a37537 commit a640594

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

docs/storage/prometheus.md

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Metric name | Type | Description | Unit (where applicable) | option parameter |
5050
`container_hugetlb_failcnt` | Counter | Number of hugepage usage hits limits | | hugetlb |
5151
`container_hugetlb_max_usage_bytes` | Gauge | Maximum hugepage usages recorded | bytes | hugetlb |
5252
`container_hugetlb_usage_bytes` | Gauge | Current hugepage usage | bytes | hugetlb |
53+
`container_misc_usage` | Gauge | Current usage of the resource | | misc |
54+
`container_misc_events` | Counter | Number of times the usage for the resource was about to go over the max boundary | | misc |
5355
`container_last_seen` | Gauge | Last time a container was seen by the exporter | timestamp | - |
5456
`container_llc_occupancy_bytes` | Gauge | Last level cache usage statistics for container counted with RDT Memory Bandwidth Monitoring (MBM). | bytes | resctrl |
5557
`container_memory_bandwidth_bytes` | Gauge | Total memory bandwidth usage statistics for container counted with RDT Memory Bandwidth Monitoring (MBM). | bytes | resctrl |

metrics/prometheus.go

+37
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,43 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
361361
},
362362
}...)
363363
}
364+
if includedMetrics.Has(container.MiscMetrics) {
365+
c.containerMetrics = append(c.containerMetrics, []containerMetric{
366+
{
367+
name: "container_misc_usage",
368+
help: "Current usage of the resource",
369+
valueType: prometheus.GaugeValue,
370+
extraLabels: []string{"resource"},
371+
getValues: func(s *info.ContainerStats) metricValues {
372+
values := make(metricValues, 0, len(s.Misc))
373+
for k, v := range s.Misc {
374+
values = append(values, metricValue{
375+
value: float64(v.Usage),
376+
labels: []string{k},
377+
timestamp: s.Timestamp,
378+
})
379+
}
380+
return values
381+
},
382+
}, {
383+
name: "container_misc_events",
384+
help: "Number of times the usage for the resource was about to go over the max boundary",
385+
valueType: prometheus.CounterValue,
386+
extraLabels: []string{"resource"},
387+
getValues: func(s *info.ContainerStats) metricValues {
388+
values := make(metricValues, 0, len(s.Misc))
389+
for k, v := range s.Misc {
390+
values = append(values, metricValue{
391+
value: float64(v.Events),
392+
labels: []string{k},
393+
timestamp: s.Timestamp,
394+
})
395+
}
396+
return values
397+
},
398+
},
399+
}...)
400+
}
364401
if includedMetrics.Has(container.MemoryUsageMetrics) {
365402
c.containerMetrics = append(c.containerMetrics, []containerMetric{
366403
{

metrics/prometheus_fake.go

+10
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,16 @@ func (p testSubcontainersInfoProvider) GetRequestedContainersInfo(string, v2.Req
368368
Failcnt: 0,
369369
},
370370
},
371+
Misc: map[string]info.MiscStats{
372+
"res_a": {
373+
Usage: 1,
374+
Events: 42,
375+
},
376+
"res_b": {
377+
Usage: 2,
378+
Events: 42,
379+
},
380+
},
371381
Network: info.NetworkStats{
372382
InterfaceStats: info.InterfaceStats{
373383
Name: "eth0",

metrics/testdata/prometheus_metrics

+8
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ container_hugetlb_max_usage_bytes{container_env_foo_env="prod",container_label_f
133133
# TYPE container_hugetlb_usage_bytes gauge
134134
container_hugetlb_usage_bytes{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",pagesize="1Gi",zone_name="hello"} 0 1395066363000
135135
container_hugetlb_usage_bytes{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",pagesize="2Mi",zone_name="hello"} 4 1395066363000
136+
# HELP container_misc_usage Current usage of the resource
137+
# TYPE container_misc_usage gauge
138+
container_misc_usage{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",resource="res_a",zone_name="hello"} 1 1395066363000
139+
container_misc_usage{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",resource="res_b",zone_name="hello"} 2 1395066363000
140+
# HELP container_misc_events Number of times the usage for the resource was about to go over the max boundary
141+
# TYPE container_misc_events counter
142+
container_misc_events{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",resource="res_a",zone_name="hello"} 42 1395066363000
143+
container_misc_events{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",resource="res_b",zone_name="hello"} 42 1395066363000
136144
# HELP container_last_seen Last time a container was seen by the exporter
137145
# TYPE container_last_seen gauge
138146
container_last_seen{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 1.395066363e+09 1395066363000

metrics/testdata/prometheus_metrics_whitelist_filtered

+8
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ container_hugetlb_max_usage_bytes{container_env_foo_env="prod",id="testcontainer
133133
# TYPE container_hugetlb_usage_bytes gauge
134134
container_hugetlb_usage_bytes{container_env_foo_env="prod",id="testcontainer",image="test",name="testcontaineralias",pagesize="1Gi",zone_name="hello"} 0 1395066363000
135135
container_hugetlb_usage_bytes{container_env_foo_env="prod",id="testcontainer",image="test",name="testcontaineralias",pagesize="2Mi",zone_name="hello"} 4 1395066363000
136+
# HELP container_misc_usage Current usage of the resource
137+
# TYPE container_misc_usage gauge
138+
container_misc_usage{container_env_foo_env="prod",id="testcontainer",image="test",name="testcontaineralias",resource="res_a",zone_name="hello"} 1 1395066363000
139+
container_misc_usage{container_env_foo_env="prod",id="testcontainer",image="test",name="testcontaineralias",resource="res_b",zone_name="hello"} 2 1395066363000
140+
# HELP container_misc_events Number of times the usage for the resource was about to go over the max boundary
141+
# TYPE container_misc_events counter
142+
container_misc_events{container_env_foo_env="prod",id="testcontainer",image="test",name="testcontaineralias",resource="res_a",zone_name="hello"} 42 1395066363000
143+
container_misc_events{container_env_foo_env="prod",id="testcontainer",image="test",name="testcontaineralias",resource="res_b",zone_name="hello"} 42 1395066363000
136144
# HELP container_last_seen Last time a container was seen by the exporter
137145
# TYPE container_last_seen gauge
138146
container_last_seen{container_env_foo_env="prod",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 1.395066363e+09 1395066363000

0 commit comments

Comments
 (0)