Add cgroups v2 task metrics.

Signed-off-by: Shishir Mahajan <smahajan@roblox.com>
This commit is contained in:
Shishir Mahajan 2020-06-15 14:01:12 -07:00
parent 3ce882e1be
commit 8d4f59c474
No known key found for this signature in database
GPG Key ID: D41782E7688DEC4A
2 changed files with 22 additions and 10 deletions

View File

@ -211,20 +211,13 @@ func (h *taskHandle) handleStats(ch chan *drivers.TaskResourceUsage, ctx, ctxCon
return return
} }
var (
data *v1.Metrics
data2 *v2.Metrics
)
var taskResourceUsage *drivers.TaskResourceUsage var taskResourceUsage *drivers.TaskResourceUsage
switch v := anydata.(type) { switch data := anydata.(type) {
case *v1.Metrics: case *v1.Metrics:
data = v
taskResourceUsage = h.getV1TaskResourceUsage(data) taskResourceUsage = h.getV1TaskResourceUsage(data)
case *v2.Metrics: case *v2.Metrics:
data2 = v taskResourceUsage = h.getV2TaskResourceUsage(data)
taskResourceUsage = h.getV2TaskResourceUsage(data2)
default: default:
h.logger.Error("Cannot convert metric data to cgroups.Metrics") h.logger.Error("Cannot convert metric data to cgroups.Metrics")
return return
@ -263,7 +256,25 @@ func (h *taskHandle) getV1TaskResourceUsage(metrics *v1.Metrics) *drivers.TaskRe
// Convert containerd V2 task metrics to TaskResourceUsage. // Convert containerd V2 task metrics to TaskResourceUsage.
func (h *taskHandle) getV2TaskResourceUsage(metrics *v2.Metrics) *drivers.TaskResourceUsage { func (h *taskHandle) getV2TaskResourceUsage(metrics *v2.Metrics) *drivers.TaskResourceUsage {
return nil cs := &drivers.CpuStats{
SystemMode: float64(metrics.CPU.SystemUsec),
UserMode: float64(metrics.CPU.UserUsec),
TotalTicks: float64(metrics.CPU.UsageUsec),
}
ms := &drivers.MemoryStats{
Usage: metrics.Memory.Usage,
Swap: metrics.Memory.SwapUsage,
}
ts := time.Now().UTC().UnixNano()
return &drivers.TaskResourceUsage{
ResourceUsage: &drivers.ResourceUsage{
CpuStats: cs,
MemoryStats: ms,
},
Timestamp: ts,
}
} }
func (h *taskHandle) signal(ctxContainerd context.Context, sig os.Signal) error { func (h *taskHandle) signal(ctxContainerd context.Context, sig os.Signal) error {
return h.task.Kill(ctxContainerd, sig.(syscall.Signal)) return h.task.Kill(ctxContainerd, sig.(syscall.Signal))

View File

@ -98,6 +98,7 @@ setup() {
sudo systemctl stop containerd sudo systemctl stop containerd
sudo apt-get purge -y docker-ce docker-ce-cli containerd.io sudo apt-get purge -y docker-ce docker-ce-cli containerd.io
sudo apt-get update
sudo apt-get install -y apt-utils curl runc unzip make build-essential sudo apt-get install -y apt-utils curl runc unzip make build-essential
# Change $(pwd) to /tmp # Change $(pwd) to /tmp