Skip to content

Commit 2fa6c62

Browse files
authored
Merge pull request #2034 from usabilla/mapped_file
Adds mapped_file metric
2 parents 3e657b4 + 8a789bb commit 2fa6c62

File tree

8 files changed

+26
-3
lines changed

8 files changed

+26
-3
lines changed

container/libcontainer/handler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,12 @@ func setMemoryStats(s *cgroups.Stats, ret *info.ContainerStats) {
503503
ret.Memory.Cache = s.MemoryStats.Stats["total_cache"]
504504
ret.Memory.RSS = s.MemoryStats.Stats["total_rss"]
505505
ret.Memory.Swap = s.MemoryStats.Stats["total_swap"]
506+
ret.Memory.MappedFile = s.MemoryStats.Stats["total_mapped_file"]
506507
} else {
507508
ret.Memory.Cache = s.MemoryStats.Stats["cache"]
508509
ret.Memory.RSS = s.MemoryStats.Stats["rss"]
509510
ret.Memory.Swap = s.MemoryStats.Stats["swap"]
511+
ret.Memory.MappedFile = s.MemoryStats.Stats["mapped_file"]
510512
}
511513
if v, ok := s.MemoryStats.Stats["pgfault"]; ok {
512514
ret.Memory.ContainerData.Pgfault = v

docs/storage/prometheus.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Metric name | Type | Description | Unit (where applicable)
5353
`container_memory_max_usage_bytes` | Gauge | Maximum memory usage recorded | bytes
5454
`container_memory_rss` | Gauge | Size of RSS | bytes
5555
`container_memory_swap` | Gauge | Container swap usage | bytes
56+
`container_memory_mapped_file` | Gauge | Size of memory mapped files | bytes
5657
`container_memory_usage_bytes` | Gauge | Current memory usage, including all memory regardless of when it was accessed | bytes
5758
`container_memory_working_set_bytes` | Gauge | Current working set | bytes
5859
`container_network_receive_bytes_total` | Counter | Cumulative count of bytes received | bytes

info/v1/container.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ type MemoryStats struct {
358358
// Units: Bytes.
359359
Swap uint64 `json:"swap"`
360360

361+
// The amount of memory used for mapped files (includes tmpfs/shmem)
362+
MappedFile uint64 `json:"mapped_file"`
363+
361364
// The amount of working set memory, this includes recently accessed memory,
362365
// dirty memory, and kernel memory. Working set is <= "usage".
363366
// Units: Bytes.

info/v1/test/datagen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func GenerateRandomStats(numStats, numCores int, duration time.Duration) []*info
4646
stats.Memory.Usage = uint64(rand.Int63n(4096))
4747
stats.Memory.Cache = uint64(rand.Int63n(4096))
4848
stats.Memory.RSS = uint64(rand.Int63n(4096))
49+
stats.Memory.MappedFile = uint64(rand.Int63n(4096))
4950
ret[i] = stats
5051
}
5152
return ret

metrics/prometheus.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
289289
getValues: func(s *info.ContainerStats) metricValues {
290290
return metricValues{{value: float64(s.Memory.RSS)}}
291291
},
292+
}, {
293+
name: "container_memory_mapped_file",
294+
help: "Size of memory mapped files in bytes.",
295+
valueType: prometheus.GaugeValue,
296+
getValues: func(s *info.ContainerStats) metricValues {
297+
return metricValues{{value: float64(s.Memory.MappedFile)}}
298+
},
292299
}, {
293300
name: "container_memory_swap",
294301
help: "Container swap usage in bytes.",

metrics/prometheus_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ func (p testSubcontainersInfoProvider) SubcontainersInfo(string, *info.Container
124124
Pgfault: 12,
125125
Pgmajfault: 13,
126126
},
127-
Cache: 14,
128-
RSS: 15,
129-
Swap: 8192,
127+
Cache: 14,
128+
RSS: 15,
129+
MappedFile: 16,
130+
Swap: 8192,
130131
},
131132
Network: info.NetworkStats{
132133
InterfaceStats: info.InterfaceStats{

metrics/testdata/prometheus_metrics

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ container_memory_failures_total{container_env_foo_env="prod",container_label_foo
121121
container_memory_failures_total{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",scope="container",type="pgmajfault",zone_name="hello"} 11
122122
container_memory_failures_total{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",scope="hierarchy",type="pgfault",zone_name="hello"} 12
123123
container_memory_failures_total{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",scope="hierarchy",type="pgmajfault",zone_name="hello"} 13
124+
# HELP container_memory_mapped_file Size of memory mapped files in bytes.
125+
# TYPE container_memory_mapped_file gauge
126+
container_memory_mapped_file{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 16
124127
# HELP container_memory_max_usage_bytes Maximum memory usage recorded in bytes
125128
# TYPE container_memory_max_usage_bytes gauge
126129
container_memory_max_usage_bytes{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 8

storage/statsd/statsd.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const (
4343
colMemoryWorkingSet string = "memory_working_set"
4444
// Resident set size
4545
colMemoryRSS string = "memory_rss"
46+
// Mapped files size
47+
colMemoryMappedFile string = "memory_mapped_file"
4648
// Cumulative count of bytes received.
4749
colRxBytes string = "rx_bytes"
4850
// Cumulative count of receive errors encountered.
@@ -85,6 +87,9 @@ func (self *statsdStorage) containerStatsToValues(
8587
// Resident set size
8688
series[colMemoryRSS] = stats.Memory.RSS
8789

90+
// Mapped files size
91+
series[colMemoryMappedFile] = stats.Memory.MappedFile
92+
8893
// Network stats.
8994
series[colRxBytes] = stats.Network.RxBytes
9095
series[colRxErrors] = stats.Network.RxErrors

0 commit comments

Comments
 (0)