
We should not touch the dockershim ahead of removal and therefore default to `v1alpha2` CRI instead of `v1`. Partially reverts changes from https://github.com/kubernetes/kubernetes/pull/106501 Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
64 lines
1.9 KiB
Go
64 lines
1.9 KiB
Go
//go:build linux && !dockerless
|
|
// +build linux,!dockerless
|
|
|
|
/*
|
|
Copyright 2017 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package dockershim
|
|
|
|
import (
|
|
"time"
|
|
|
|
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
|
)
|
|
|
|
func (ds *dockerService) getContainerStats(c *runtimeapi.Container) (*runtimeapi.ContainerStats, error) {
|
|
statsJSON, err := ds.client.GetContainerStats(c.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
containerJSON, err := ds.client.InspectContainerWithSize(c.Id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
dockerStats := statsJSON.Stats
|
|
timestamp := time.Now().UnixNano()
|
|
containerStats := &runtimeapi.ContainerStats{
|
|
Attributes: &runtimeapi.ContainerAttributes{
|
|
Id: c.Id,
|
|
Metadata: c.Metadata,
|
|
Labels: c.Labels,
|
|
Annotations: c.Annotations,
|
|
},
|
|
Cpu: &runtimeapi.CpuUsage{
|
|
Timestamp: timestamp,
|
|
UsageCoreNanoSeconds: &runtimeapi.UInt64Value{Value: dockerStats.CPUStats.CPUUsage.TotalUsage},
|
|
},
|
|
Memory: &runtimeapi.MemoryUsage{
|
|
Timestamp: timestamp,
|
|
WorkingSetBytes: &runtimeapi.UInt64Value{Value: dockerStats.MemoryStats.PrivateWorkingSet},
|
|
},
|
|
WritableLayer: &runtimeapi.FilesystemUsage{
|
|
Timestamp: timestamp,
|
|
FsId: &runtimeapi.FilesystemIdentifier{Mountpoint: ds.dockerRootDir},
|
|
UsedBytes: &runtimeapi.UInt64Value{Value: uint64(*containerJSON.SizeRw)},
|
|
},
|
|
}
|
|
return containerStats, nil
|
|
}
|