2017-08-04 11:13:19 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2017-11-09 10:10:35 +00:00
|
|
|
"time"
|
2017-08-04 11:13:19 +00:00
|
|
|
|
2018-01-07 22:16:46 +00:00
|
|
|
"github.com/kubernetes-incubator/cri-o/lib"
|
|
|
|
"github.com/sirupsen/logrus"
|
2017-08-04 11:13:19 +00:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ListContainerStats returns stats of all running containers.
|
2017-11-09 10:10:35 +00:00
|
|
|
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)
|
|
|
|
}()
|
2018-01-07 22:16:46 +00:00
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
2018-01-31 18:28:01 +00:00
|
|
|
ctrList, err = s.filterContainerList(cFilter, ctrList)
|
2018-01-07 22:16:46 +00:00
|
|
|
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
|
2017-08-04 11:13:19 +00:00
|
|
|
}
|