From 9e175e9ea917e17cc1078a9836f19ff14276613c Mon Sep 17 00:00:00 2001 From: Gijs Kunze Date: Thu, 9 Aug 2018 15:14:46 +0200 Subject: [PATCH 1/2] Adds mapped_file metric --- container/libcontainer/handler.go | 2 ++ info/v1/container.go | 3 +++ info/v1/test/datagen.go | 1 + metrics/prometheus.go | 7 +++++++ metrics/prometheus_test.go | 7 ++++--- metrics/testdata/prometheus_metrics | 3 +++ storage/statsd/statsd.go | 5 +++++ 7 files changed, 25 insertions(+), 3 deletions(-) diff --git a/container/libcontainer/handler.go b/container/libcontainer/handler.go index 9a8956c3..8cd8025a 100644 --- a/container/libcontainer/handler.go +++ b/container/libcontainer/handler.go @@ -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 diff --git a/info/v1/container.go b/info/v1/container.go index 0d7b895b..41f7ae53 100644 --- a/info/v1/container.go +++ b/info/v1/container.go @@ -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. diff --git a/info/v1/test/datagen.go b/info/v1/test/datagen.go index 42a0526d..8b02cd8c 100644 --- a/info/v1/test/datagen.go +++ b/info/v1/test/datagen.go @@ -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 diff --git a/metrics/prometheus.go b/metrics/prometheus.go index d34176ff..37e09b38 100644 --- a/metrics/prometheus.go +++ b/metrics/prometheus.go @@ -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.", diff --git a/metrics/prometheus_test.go b/metrics/prometheus_test.go index 8d5aa830..c6af3a19 100644 --- a/metrics/prometheus_test.go +++ b/metrics/prometheus_test.go @@ -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{ diff --git a/metrics/testdata/prometheus_metrics b/metrics/testdata/prometheus_metrics index b919c4c7..e4adcb5c 100644 --- a/metrics/testdata/prometheus_metrics +++ b/metrics/testdata/prometheus_metrics @@ -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 diff --git a/storage/statsd/statsd.go b/storage/statsd/statsd.go index b9dd3bfb..db665bda 100644 --- a/storage/statsd/statsd.go +++ b/storage/statsd/statsd.go @@ -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 From 8a789bb1cda8e2b577c2b19a89e1d1dcb6acbf8b Mon Sep 17 00:00:00 2001 From: Gijs Kunze Date: Wed, 29 Aug 2018 10:05:28 +0200 Subject: [PATCH 2/2] Adds missing documentation for container_memory_mapped_files --- docs/storage/prometheus.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/storage/prometheus.md b/docs/storage/prometheus.md index c06d84f2..adc0e342 100644 --- a/docs/storage/prometheus.md +++ b/docs/storage/prometheus.md @@ -53,6 +53,7 @@ Metric name | Type | Description | Unit (where applicable) `container_memory_max_usage_bytes` | Gauge | Maximum memory usage recorded | bytes `container_memory_rss` | Gauge | Size of RSS | bytes `container_memory_swap` | Gauge | Container swap usage | bytes +`container_memory_mapped_file` | Gauge | Size of memory mapped files | bytes `container_memory_usage_bytes` | Gauge | Current memory usage, including all memory regardless of when it was accessed | bytes `container_memory_working_set_bytes` | Gauge | Current working set | bytes `container_network_receive_bytes_total` | Counter | Cumulative count of bytes received | bytes