This uses the previously unusued lib/stats.go code to return data about container stats to the CRI API. Helpers have been built around filtering based on the OCI API, and CPU stat reporting has been fixed. No data on filesystem layer usage is returned at this time. Fixes one-half of #1248 Signed-off-by: Yann Ramin <atrus@stackworks.net>
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package server
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/kubernetes-incubator/cri-o/lib"
|
|
"github.com/sirupsen/logrus"
|
|
"golang.org/x/net/context"
|
|
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
|
)
|
|
|
|
// ListContainerStats returns stats of all running containers.
|
|
func (s *Server) ListContainerStats(ctx context.Context, req *pb.ListContainerStatsRequest) (resp *pb.ListContainerStatsResponse, err error) {
|
|
const operation = "list_container_stats"
|
|
defer func() {
|
|
recordOperation(operation, time.Now())
|
|
recordError(operation, err)
|
|
}()
|
|
|
|
ctrList, err := s.ContainerServer.ListContainers()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
filter := req.GetFilter()
|
|
if filter != nil {
|
|
cFilter := &pb.ContainerFilter{
|
|
Id: req.Filter.Id,
|
|
PodSandboxId: req.Filter.PodSandboxId,
|
|
LabelSelector: req.Filter.LabelSelector,
|
|
}
|
|
ctrList, err = s.filterContainerList(cFilter)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
var allStats []*pb.ContainerStats
|
|
|
|
for _, container := range ctrList {
|
|
stats, err := s.GetContainerStats(container, &lib.ContainerStats{})
|
|
if err != nil {
|
|
logrus.Warn("unable to get stats for container %s", container.ID())
|
|
continue
|
|
}
|
|
response := buildContainerStats(stats, container)
|
|
allStats = append(allStats, response)
|
|
}
|
|
|
|
return &pb.ListContainerStatsResponse{
|
|
Stats: allStats,
|
|
}, nil
|
|
}
|