Thanks to visit codestin.com
Credit goes to github.com

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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ require (
github.com/BurntSushi/toml v0.3.1
github.com/Microsoft/go-winio v0.4.17-0.20210211115548-6eac466e5fa3
github.com/blang/semver v3.5.1+incompatible
github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68
github.com/containerd/containerd v1.5.0-beta.4
github.com/containerd/ttrpc v1.0.2
github.com/containerd/typeurl v1.0.1
github.com/containernetworking/cni v0.8.1
github.com/containernetworking/plugins v0.9.1
github.com/containers/buildah v1.20.0
Expand Down
50 changes: 0 additions & 50 deletions internal/oci/oci_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,56 +111,6 @@ func (r *runtimeOCI) containerStats(ctr *Container, cgroup string) (*ContainerSt
return stats, nil
}

func metricsToCtrStats(c *Container, m *cgroups.Metrics) *ContainerStats {
var (
cpu float64
cpuNano uint64
memUsage uint64
memLimit uint64
memPerc float64
netInput uint64
netOutput uint64
blockInput uint64
blockOutput uint64
pids uint64
)

if m != nil {
pids = m.Pids.Current

cpuNano = m.CPU.Usage.Total
cpu = genericCalculateCPUPercent(cpuNano, m.CPU.Usage.PerCPU)

memUsage = m.Memory.Usage.Usage
memLimit = getMemLimit(m.Memory.Usage.Limit)
memPerc = float64(memUsage) / float64(memLimit)

for _, entry := range m.Blkio.IoServiceBytesRecursive {
switch strings.ToLower(entry.Op) {
case "read":
blockInput += entry.Value
case "write":
blockOutput += entry.Value
}
}
}

return &ContainerStats{
Container: c.ID(),
CPU: cpu,
CPUNano: cpuNano,
SystemNano: time.Now().UnixNano(),
MemUsage: memUsage,
MemLimit: memLimit,
MemPerc: memPerc,
NetInput: netInput,
NetOutput: netOutput,
BlockInput: blockInput,
BlockOutput: blockOutput,
PIDs: pids,
}
}

// getTotalInactiveFile returns the value if inactive_file as integer
// from cgroup's memory.stat. Returns an error if the file does not exists,
// not parsable, or the value is not found.
Expand Down
64 changes: 62 additions & 2 deletions internal/oci/runtime_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import (
"syscall"
"time"

cgroups "github.com/containerd/cgroups/stats/v1"
tasktypes "github.com/containerd/containerd/api/types/task"
"github.com/containerd/containerd/namespaces"
client "github.com/containerd/containerd/runtime/v2/shim"
"github.com/containerd/containerd/runtime/v2/task"
"github.com/containerd/ttrpc"
"github.com/containers/podman/v3/pkg/cgroups"
"github.com/containerd/typeurl"
"github.com/cri-o/cri-o/internal/log"
"github.com/cri-o/cri-o/server/metrics"
"github.com/cri-o/cri-o/utils"
"github.com/cri-o/cri-o/utils/errdefs"
"github.com/cri-o/cri-o/utils/fifo"
cio "github.com/cri-o/cri-o/utils/io"
cioutil "github.com/cri-o/cri-o/utils/ioutil"
"github.com/cri-o/cri-o/utils/typeurl"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -746,6 +746,66 @@ func (r *runtimeVM) ContainerStats(ctx context.Context, c *Container, _ string)
return metricsToCtrStats(c, m), nil
}

func metricsToCtrStats(c *Container, m *cgroups.Metrics) *ContainerStats {
var (
blockInput uint64
blockOutput uint64
cpu float64
cpuNano uint64
memLimit uint64
memPerc float64
memUsage uint64
netInput uint64
netOutput uint64
pids uint64
workingSetBytes uint64
)

if m != nil {
pids = m.Pids.Current

cpuNano = m.CPU.Usage.Total
cpu = genericCalculateCPUPercent(cpuNano, m.CPU.Usage.PerCPU)

memUsage = m.Memory.Usage.Usage
memLimit = getMemLimit(m.Memory.Usage.Limit)
memPerc = float64(memUsage) / float64(memLimit)
if memUsage > m.Memory.TotalInactiveFile {
workingSetBytes = memUsage - m.Memory.TotalInactiveFile
} else {
logrus.Debugf(
"unable to account working set stats: total_inactive_file (%d) > memory usage (%d)",
m.Memory.TotalInactiveFile, memUsage,
)
}

for _, entry := range m.Blkio.IoServiceBytesRecursive {
switch strings.ToLower(entry.Op) {
case "read":
blockInput += entry.Value
case "write":
blockOutput += entry.Value
}
}
}

return &ContainerStats{
BlockInput: blockInput,
BlockOutput: blockOutput,
Container: c.ID(),
CPU: cpu,
CPUNano: cpuNano,
MemLimit: memLimit,
MemUsage: memUsage,
MemPerc: memPerc,
NetInput: netInput,
NetOutput: netOutput,
PIDs: pids,
SystemNano: time.Now().UnixNano(),
WorkingSetBytes: workingSetBytes,
}
}

// SignalContainer sends a signal to a container process.
func (r *runtimeVM) SignalContainer(ctx context.Context, c *Container, sig syscall.Signal) error {
log.Debugf(ctx, "runtimeVM.SignalContainer() start")
Expand Down
158 changes: 0 additions & 158 deletions utils/typeurl/types.go

This file was deleted.

2 changes: 2 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ github.com/cilium/ebpf/internal
github.com/cilium/ebpf/internal/btf
github.com/cilium/ebpf/internal/unix
# github.com/containerd/cgroups v0.0.0-20210114181951-8a68de567b68
## explicit
github.com/containerd/cgroups/stats/v1
# github.com/containerd/console v1.0.1
github.com/containerd/console
Expand Down Expand Up @@ -93,6 +94,7 @@ github.com/containerd/go-runc
## explicit
github.com/containerd/ttrpc
# github.com/containerd/typeurl v1.0.1
## explicit
github.com/containerd/typeurl
# github.com/containernetworking/cni v0.8.1
## explicit
Expand Down