This repository has been archived by the owner on Feb 8, 2021. It is now read-only.
forked from kata-containers/runtime
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
containerd-shim-kata-v2: add the service Stats support
Add the Stats api support to get the container's resouces statistic. Signed-off-by: ZeroMagic <[email protected]>
- Loading branch information
Showing
2 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) 2018 HyperHQ Inc. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
package containerdshim | ||
|
||
import ( | ||
"github.com/containerd/cgroups" | ||
"github.com/containerd/typeurl" | ||
|
||
google_protobuf "github.com/gogo/protobuf/types" | ||
) | ||
|
||
func marshalMetrics(s *service, containerID string) (*google_protobuf.Any, error) { | ||
stats, err := s.sandbox.StatsContainer(containerID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
cgStats := stats.CgroupStats | ||
|
||
var hugetlb []*cgroups.HugetlbStat | ||
for _, v := range cgStats.HugetlbStats { | ||
hugetlb = append( | ||
hugetlb, | ||
&cgroups.HugetlbStat{ | ||
Usage: v.Usage, | ||
Max: v.MaxUsage, | ||
Failcnt: v.Failcnt, | ||
}) | ||
} | ||
|
||
var perCPU []uint64 | ||
for _, v := range cgStats.CPUStats.CPUUsage.PercpuUsage { | ||
perCPU = append(perCPU, v) | ||
} | ||
|
||
metrics := &cgroups.Metrics{ | ||
Hugetlb: hugetlb, | ||
Pids: &cgroups.PidsStat{ | ||
Current: cgStats.PidsStats.Current, | ||
Limit: cgStats.PidsStats.Limit, | ||
}, | ||
CPU: &cgroups.CPUStat{ | ||
Usage: &cgroups.CPUUsage{ | ||
Total: cgStats.CPUStats.CPUUsage.TotalUsage, | ||
PerCPU: perCPU, | ||
}, | ||
}, | ||
Memory: &cgroups.MemoryStat{ | ||
Cache: cgStats.MemoryStats.Cache, | ||
Usage: &cgroups.MemoryEntry{ | ||
Limit: cgStats.MemoryStats.Usage.Limit, | ||
Usage: cgStats.MemoryStats.Usage.Usage, | ||
}, | ||
}, | ||
} | ||
|
||
data, err := typeurl.MarshalAny(metrics) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return data, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters