Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions v2/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,12 @@ func (c *Manager) Stat() (*stats.Metrics, error) {
Pglazyfreed: out["pglazyfreed"].(uint64),
ThpFaultAlloc: out["thp_fault_alloc"].(uint64),
ThpCollapseAlloc: out["thp_collapse_alloc"].(uint64),
Usage: getStatFileContentUint64(filepath.Join(c.path, "memory.current")),
UsageLimit: getStatFileContentUint64(filepath.Join(c.path, "memory.max")),
SwapUsage: getStatFileContentUint64(filepath.Join(c.path, "memory.swap.current")),
SwapLimit: getStatFileContentUint64(filepath.Join(c.path, "memory.swap.max")),
}

return &metrics, nil
}

Expand Down
232 changes: 179 additions & 53 deletions v2/stats/metrics.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions v2/stats/metrics.pb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,34 @@ file {
type: TYPE_UINT64
json_name: "thpCollapseAlloc"
}
field {
name: "usage"
number: 32
label: LABEL_OPTIONAL
type: TYPE_UINT64
json_name: "usage"
}
field {
name: "usage_limit"
number: 33
label: LABEL_OPTIONAL
type: TYPE_UINT64
json_name: "usageLimit"
}
field {
name: "swap_usage"
number: 34
label: LABEL_OPTIONAL
type: TYPE_UINT64
json_name: "swapUsage"
}
field {
name: "swap_limit"
number: 35
label: LABEL_OPTIONAL
type: TYPE_UINT64
json_name: "swapLimit"
}
}
syntax: "proto3"
}
4 changes: 4 additions & 0 deletions v2/stats/metrics.proto
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ message MemoryStat {
uint64 pglazyfreed = 29;
uint64 thp_fault_alloc = 30;
uint64 thp_collapse_alloc = 31;
uint64 usage = 32;
uint64 usage_limit = 33;
uint64 swap_usage = 34;
uint64 swap_limit = 35;
}

// iostat
Expand Down
23 changes: 23 additions & 0 deletions v2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ import (
"fmt"
"io"
"io/ioutil"
"math"
"os"
"strconv"
"strings"
"time"

"github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -216,3 +218,24 @@ func ToResources(spec *specs.LinuxResources) *Resources {
}
return &resources
}

// Gets uint64 parsed content of single value cgroup stat file
func getStatFileContentUint64(filePath string) uint64 {
contents, err := ioutil.ReadFile(filePath)
if err != nil {
logrus.Error(err)
return 0
}
trimmed := strings.TrimSpace(string(contents))
if trimmed == "max" {
return math.MaxUint64
}

res, err := parseUint(trimmed, 10, 64)
if err != nil {
logrus.Errorf("unable to parse %q as a uint from Cgroup file %q", string(contents), filePath)
return res
}

return res
}