forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cgroupv2_memory.go
93 lines (76 loc) · 2.75 KB
/
cgroupv2_memory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
//go:build linux
// +build linux
package cgroups
func (c *cgroupV2) GetMemoryStats(stats *MemoryStats) error {
if stats == nil {
return &InvalidInputError{Desc: "input stats cannot be nil"}
}
if !c.controllerActivated("memory") {
return &ControllerNotFoundError{Controller: "memory"}
}
var kernelStack, slab *uint64
if err := parse2ColumnStatsWithMapping(c.fr, c.pathFor("memory.stat"), 0, 1, map[string]**uint64{
"file": &stats.Cache,
"anon": &stats.RSS,
"anon_thp": &stats.RSSHuge,
"file_mapped": &stats.MappedFile,
"pgfault": &stats.Pgfault,
"pgmajfault": &stats.Pgmajfault,
"inactive_anon": &stats.InactiveAnon,
"active_anon": &stats.ActiveAnon,
"inactive_file": &stats.InactiveFile,
"active_file": &stats.ActiveFile,
"unevictable": &stats.Unevictable,
"kernel_stack": &kernelStack,
"slab": &slab,
}); err != nil {
reportError(err)
}
if kernelStack != nil && slab != nil {
stats.KernelMemory = uint64Ptr(*kernelStack + *slab)
}
if err := parseSingleUnsignedStat(c.fr, c.pathFor("memory.current"), &stats.UsageTotal); err != nil {
reportError(err)
}
if err := parseSingleUnsignedStat(c.fr, c.pathFor("memory.min"), &stats.MinThreshold); err != nil {
reportError(err)
}
nilIfZero(&stats.MinThreshold)
if err := parseSingleUnsignedStat(c.fr, c.pathFor("memory.low"), &stats.LowThreshold); err != nil {
reportError(err)
}
nilIfZero(&stats.LowThreshold)
if err := parseSingleUnsignedStat(c.fr, c.pathFor("memory.high"), &stats.HighThreshold); err != nil {
reportError(err)
}
nilIfZero(&stats.HighThreshold)
if err := parseSingleUnsignedStat(c.fr, c.pathFor("memory.max"), &stats.Limit); err != nil {
reportError(err)
}
nilIfZero(&stats.Limit)
if err := parseSingleUnsignedStat(c.fr, c.pathFor("memory.swap.current"), &stats.Swap); err != nil {
reportError(err)
}
if err := parseSingleUnsignedStat(c.fr, c.pathFor("memory.swap.high"), &stats.SwapHighThreshold); err != nil {
reportError(err)
}
nilIfZero(&stats.SwapHighThreshold)
if err := parseSingleUnsignedStat(c.fr, c.pathFor("memory.swap.max"), &stats.SwapLimit); err != nil {
reportError(err)
}
nilIfZero(&stats.SwapLimit)
if err := parse2ColumnStatsWithMapping(c.fr, c.pathFor("memory.events"), 0, 1, map[string]**uint64{
"oom": &stats.OOMEvents,
"oom_kill": &stats.OOMKiilEvents,
}); err != nil {
reportError(err)
}
if err := parsePSI(c.fr, c.pathFor("memory.pressure"), &stats.PSISome, &stats.PSIFull); err != nil {
reportError(err)
}
return nil
}