Added failcnt stats

Signed-off-by: Boris Popovschi <zyqsempai@mail.ru>
This commit is contained in:
Boris Popovschi 2020-03-10 15:19:44 +02:00
parent 7f37afa892
commit d804611d05
1 changed files with 17 additions and 8 deletions

View File

@ -3,10 +3,13 @@
package fs2 package fs2
import ( import (
"fmt" "io/ioutil"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
"github.com/pkg/errors"
"github.com/opencontainers/runc/libcontainer/cgroups" "github.com/opencontainers/runc/libcontainer/cgroups"
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon" "github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
"github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/configs"
@ -24,20 +27,26 @@ func setHugeTlb(dirPath string, cgroup *configs.Cgroup) error {
func statHugeTlb(dirPath string, stats *cgroups.Stats, cgroup *configs.Cgroup) error { func statHugeTlb(dirPath string, stats *cgroups.Stats, cgroup *configs.Cgroup) error {
hugetlbStats := cgroups.HugetlbStats{} hugetlbStats := cgroups.HugetlbStats{}
for _, entry := range cgroup.Resources.HugetlbLimit { for _, entry := range cgroup.Resources.HugetlbLimit {
max := strings.Join([]string{"hugetlb", entry.Pagesize, "max"}, ".") usage := strings.Join([]string{"hugetlb", entry.Pagesize, "current"}, ".")
value, err := fscommon.GetCgroupParamUint(dirPath, max) value, err := fscommon.GetCgroupParamUint(dirPath, usage)
if err != nil { if err != nil {
return fmt.Errorf("failed to parse %s - %v", max, err) return errors.Wrapf(err, "failed to parse hugetlb.%s.current file", entry.Pagesize)
} }
hugetlbStats.Usage = value hugetlbStats.Usage = value
usage := strings.Join([]string{"hugetlb", entry.Pagesize, "current"}, ".") fileName := strings.Join([]string{"hugetlb", entry.Pagesize, "events"}, ".")
value, err = fscommon.GetCgroupParamUint(dirPath, usage) filePath := filepath.Join(dirPath, fileName)
contents, err := ioutil.ReadFile(filePath)
if err != nil { if err != nil {
return fmt.Errorf("failed to parse %s - %v", usage, err) return errors.Wrapf(err, "failed to parse hugetlb.%s.events file", entry.Pagesize)
} }
hugetlbStats.Usage = value _, value, err = fscommon.GetCgroupParamKeyValue(string(contents))
if err != nil {
return errors.Wrapf(err, "failed to parse hugetlb.%s.events file", entry.Pagesize)
}
hugetlbStats.Failcnt = value
stats.HugetlbStats[entry.Pagesize] = hugetlbStats stats.HugetlbStats[entry.Pagesize] = hugetlbStats
} }