forked from cri-o/cri-o
-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_stats_list.go
49 lines (42 loc) · 1.27 KB
/
container_stats_list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package server
import (
"time"
"github.com/kubernetes-sigs/cri-o/lib"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/runtime/v1alpha2"
)
// 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 = s.filterContainerList(cFilter, ctrList)
}
var allStats []*pb.ContainerStats
for _, container := range ctrList {
stats, err := s.GetContainerStats(container, &lib.ContainerStats{})
if err != nil {
logrus.Warnf("unable to get stats for container %s", container.ID())
continue
}
response := buildContainerStats(stats, container)
allStats = append(allStats, response)
}
return &pb.ListContainerStatsResponse{
Stats: allStats,
}, nil
}