Skip to content

Commit

Permalink
Adds mapped_file metric
Browse files Browse the repository at this point in the history
  • Loading branch information
Gijs Kunze committed Aug 9, 2018
1 parent 18afaa9 commit 9e175e9
Showing 7 changed files with 25 additions and 3 deletions.
2 changes: 2 additions & 0 deletions container/libcontainer/handler.go
Original file line number Diff line number Diff line change
@@ -503,9 +503,11 @@ func setMemoryStats(s *cgroups.Stats, ret *info.ContainerStats) {
if s.MemoryStats.UseHierarchy {
ret.Memory.RSS = s.MemoryStats.Stats["total_rss"]
ret.Memory.Swap = s.MemoryStats.Stats["total_swap"]
ret.Memory.MappedFile = s.MemoryStats.Stats["total_mapped_file"]
} else {
ret.Memory.RSS = s.MemoryStats.Stats["rss"]
ret.Memory.Swap = s.MemoryStats.Stats["swap"]
ret.Memory.MappedFile = s.MemoryStats.Stats["mapped_file"]
}
if v, ok := s.MemoryStats.Stats["pgfault"]; ok {
ret.Memory.ContainerData.Pgfault = v
3 changes: 3 additions & 0 deletions info/v1/container.go
Original file line number Diff line number Diff line change
@@ -358,6 +358,9 @@ type MemoryStats struct {
// Units: Bytes.
Swap uint64 `json:"swap"`

// The amount of memory used for mapped files (includes tmpfs/shmem)
MappedFile uint64 `json:"mapped_file"`

// The amount of working set memory, this includes recently accessed memory,
// dirty memory, and kernel memory. Working set is <= "usage".
// Units: Bytes.
1 change: 1 addition & 0 deletions info/v1/test/datagen.go
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ func GenerateRandomStats(numStats, numCores int, duration time.Duration) []*info
stats.Memory.Usage = uint64(rand.Int63n(4096))
stats.Memory.Cache = uint64(rand.Int63n(4096))
stats.Memory.RSS = uint64(rand.Int63n(4096))
stats.Memory.MappedFile = uint64(rand.Int63n(4096))
ret[i] = stats
}
return ret
7 changes: 7 additions & 0 deletions metrics/prometheus.go
Original file line number Diff line number Diff line change
@@ -289,6 +289,13 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Memory.RSS)}}
},
}, {
name: "container_memory_mapped_file",
help: "Size of memory mapped files in bytes.",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Memory.MappedFile)}}
},
}, {
name: "container_memory_swap",
help: "Container swap usage in bytes.",
7 changes: 4 additions & 3 deletions metrics/prometheus_test.go
Original file line number Diff line number Diff line change
@@ -124,9 +124,10 @@ func (p testSubcontainersInfoProvider) SubcontainersInfo(string, *info.Container
Pgfault: 12,
Pgmajfault: 13,
},
Cache: 14,
RSS: 15,
Swap: 8192,
Cache: 14,
RSS: 15,
MappedFile: 16,
Swap: 8192,
},
Network: info.NetworkStats{
InterfaceStats: info.InterfaceStats{
3 changes: 3 additions & 0 deletions metrics/testdata/prometheus_metrics
Original file line number Diff line number Diff line change
@@ -121,6 +121,9 @@ container_memory_failures_total{container_env_foo_env="prod",container_label_foo
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
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
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
# HELP container_memory_mapped_file Size of memory mapped files in bytes.
# TYPE container_memory_mapped_file gauge
container_memory_mapped_file{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 16
# HELP container_memory_max_usage_bytes Maximum memory usage recorded in bytes
# TYPE container_memory_max_usage_bytes gauge
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
5 changes: 5 additions & 0 deletions storage/statsd/statsd.go
Original file line number Diff line number Diff line change
@@ -43,6 +43,8 @@ const (
colMemoryWorkingSet string = "memory_working_set"
// Resident set size
colMemoryRSS string = "memory_rss"
// Mapped files size
colMemoryMappedFile string = "memory_mapped_file"
// Cumulative count of bytes received.
colRxBytes string = "rx_bytes"
// Cumulative count of receive errors encountered.
@@ -85,6 +87,9 @@ func (self *statsdStorage) containerStatsToValues(
// Resident set size
series[colMemoryRSS] = stats.Memory.RSS

// Mapped files size
series[colMemoryMappedFile] = stats.Memory.MappedFile

// Network stats.
series[colRxBytes] = stats.Network.RxBytes
series[colRxErrors] = stats.Network.RxErrors

0 comments on commit 9e175e9

Please sign in to comment.