Merge pull request #1055 from guoshimin/icanhazrss

Expose rss and cache via API and /metrics
This commit is contained in:
Vish Kannan 2016-01-15 10:35:26 -08:00
commit b0a5bfaf8c
6 changed files with 35 additions and 0 deletions

View File

@ -378,6 +378,8 @@ func toContainerStats1(s *cgroups.Stats, ret *info.ContainerStats) {
func toContainerStats2(s *cgroups.Stats, ret *info.ContainerStats) { func toContainerStats2(s *cgroups.Stats, ret *info.ContainerStats) {
ret.Memory.Usage = s.MemoryStats.Usage.Usage ret.Memory.Usage = s.MemoryStats.Usage.Usage
ret.Memory.Failcnt = s.MemoryStats.Usage.Failcnt ret.Memory.Failcnt = s.MemoryStats.Usage.Failcnt
ret.Memory.Cache = s.MemoryStats.Stats["cache"]
ret.Memory.RSS = s.MemoryStats.Stats["rss"]
if v, ok := s.MemoryStats.Stats["pgfault"]; ok { if v, ok := s.MemoryStats.Stats["pgfault"]; ok {
ret.Memory.ContainerData.Pgfault = v ret.Memory.ContainerData.Pgfault = v
ret.Memory.HierarchicalData.Pgfault = v ret.Memory.HierarchicalData.Pgfault = v

View File

@ -308,6 +308,15 @@ type MemoryStats struct {
// Units: Bytes. // Units: Bytes.
Usage uint64 `json:"usage"` Usage uint64 `json:"usage"`
// Number of bytes of page cache memory.
// Units: Bytes.
Cache uint64 `json:"cache"`
// The amount of anonymous and swap cache memory (includes transparent
// hugepages).
// Units: Bytes.
RSS uint64 `json:"rss"`
// The amount of working set memory, this includes recently accessed memory, // The amount of working set memory, this includes recently accessed memory,
// dirty memory, and kernel memory. Working set is <= "usage". // dirty memory, and kernel memory. Working set is <= "usage".
// Units: Bytes. // Units: Bytes.

View File

@ -44,6 +44,8 @@ func GenerateRandomStats(numStats, numCores int, duration time.Duration) []*info
stats.Cpu.Usage.User = stats.Cpu.Usage.Total stats.Cpu.Usage.User = stats.Cpu.Usage.Total
stats.Cpu.Usage.System = 0 stats.Cpu.Usage.System = 0
stats.Memory.Usage = uint64(rand.Int63n(4096)) stats.Memory.Usage = uint64(rand.Int63n(4096))
stats.Memory.Cache = uint64(rand.Int63n(4096))
stats.Memory.RSS = uint64(rand.Int63n(4096))
ret[i] = stats ret[i] = stats
} }
return ret return ret

View File

@ -127,6 +127,20 @@ func NewPrometheusCollector(infoProvider infoProvider, f ContainerNameToLabelsFu
} }
return values return values
}, },
}, {
name: "container_memory_cache",
help: "Number of bytes of page cache memory.",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Memory.Cache)}}
},
}, {
name: "container_memory_rss",
help: "Size of RSS in bytes.",
valueType: prometheus.GaugeValue,
getValues: func(s *info.ContainerStats) metricValues {
return metricValues{{value: float64(s.Memory.RSS)}}
},
}, { }, {
name: "container_memory_failcnt", name: "container_memory_failcnt",
help: "Number of memory usage hits limits", help: "Number of memory usage hits limits",

View File

@ -85,6 +85,8 @@ func (p testSubcontainersInfoProvider) SubcontainersInfo(string, *info.Container
Pgfault: 12, Pgfault: 12,
Pgmajfault: 13, Pgmajfault: 13,
}, },
Cache: 14,
RSS: 15,
}, },
Network: info.NetworkStats{ Network: info.NetworkStats{
InterfaceStats: info.InterfaceStats{ InterfaceStats: info.InterfaceStats{

View File

@ -68,6 +68,9 @@ container_fs_writes_total{device="sda2",foo_env="prod",foo_label="bar",id="testc
# HELP container_last_seen Last time a container was seen by the exporter # HELP container_last_seen Last time a container was seen by the exporter
# TYPE container_last_seen gauge # TYPE container_last_seen gauge
container_last_seen{foo_env="prod",foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 1.426203694e+09 container_last_seen{foo_env="prod",foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 1.426203694e+09
# HELP container_memory_cache Number of bytes of page cache memory.
# TYPE container_memory_cache gauge
container_memory_cache{foo_env="prod",foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 14
# HELP container_memory_failcnt Number of memory usage hits limits # HELP container_memory_failcnt Number of memory usage hits limits
# TYPE container_memory_failcnt counter # TYPE container_memory_failcnt counter
container_memory_failcnt{foo_env="prod",foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 0 container_memory_failcnt{foo_env="prod",foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 0
@ -77,6 +80,9 @@ container_memory_failures_total{foo_env="prod",foo_label="bar",id="testcontainer
container_memory_failures_total{foo_env="prod",foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",scope="container",type="pgmajfault",zone_name="hello"} 11 container_memory_failures_total{foo_env="prod",foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",scope="container",type="pgmajfault",zone_name="hello"} 11
container_memory_failures_total{foo_env="prod",foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",scope="hierarchy",type="pgfault",zone_name="hello"} 12 container_memory_failures_total{foo_env="prod",foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",scope="hierarchy",type="pgfault",zone_name="hello"} 12
container_memory_failures_total{foo_env="prod",foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",scope="hierarchy",type="pgmajfault",zone_name="hello"} 13 container_memory_failures_total{foo_env="prod",foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",scope="hierarchy",type="pgmajfault",zone_name="hello"} 13
# HELP container_memory_rss Size of RSS in bytes.
# TYPE container_memory_rss gauge
container_memory_rss{foo_env="prod",foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 15
# HELP container_memory_usage_bytes Current memory usage in bytes. # HELP container_memory_usage_bytes Current memory usage in bytes.
# TYPE container_memory_usage_bytes gauge # TYPE container_memory_usage_bytes gauge
container_memory_usage_bytes{foo_env="prod",foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 8 container_memory_usage_bytes{foo_env="prod",foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 8