mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Calling hcsshim instead of docker api to get stats for windows to greatly reduce latency
This commit is contained in:
parent
e8f12692df
commit
999fdfaddf
@ -78,6 +78,7 @@ go_library(
|
|||||||
"@io_bazel_rules_go//go/platform:windows": [
|
"@io_bazel_rules_go//go/platform:windows": [
|
||||||
"//pkg/kubelet/apis:go_default_library",
|
"//pkg/kubelet/apis:go_default_library",
|
||||||
"//pkg/kubelet/winstats:go_default_library",
|
"//pkg/kubelet/winstats:go_default_library",
|
||||||
|
"//vendor/github.com/Microsoft/hcsshim:go_default_library",
|
||||||
"//vendor/golang.org/x/sys/windows/registry:go_default_library",
|
"//vendor/golang.org/x/sys/windows/registry:go_default_library",
|
||||||
],
|
],
|
||||||
"//conditions:default": [],
|
"//conditions:default": [],
|
||||||
|
@ -22,7 +22,9 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Microsoft/hcsshim"
|
||||||
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
|
"k8s.io/klog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ds *dockerService) getContainerStats(containerID string) (*runtimeapi.ContainerStats, error) {
|
func (ds *dockerService) getContainerStats(containerID string) (*runtimeapi.ContainerStats, error) {
|
||||||
@ -31,7 +33,18 @@ func (ds *dockerService) getContainerStats(containerID string) (*runtimeapi.Cont
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
statsJSON, err := ds.client.GetContainerStats(containerID)
|
hcsshim_container, err := hcsshim.OpenContainer(containerID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer func() {
|
||||||
|
closeErr := hcsshim_container.Close()
|
||||||
|
if closeErr != nil {
|
||||||
|
klog.Errorf("Error closing container '%s': %v", containerID, closeErr)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
stats, err := hcsshim_container.Statistics()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -47,7 +60,6 @@ func (ds *dockerService) getContainerStats(containerID string) (*runtimeapi.Cont
|
|||||||
}
|
}
|
||||||
status := statusResp.GetStatus()
|
status := statusResp.GetStatus()
|
||||||
|
|
||||||
dockerStats := statsJSON.Stats
|
|
||||||
timestamp := time.Now().UnixNano()
|
timestamp := time.Now().UnixNano()
|
||||||
containerStats := &runtimeapi.ContainerStats{
|
containerStats := &runtimeapi.ContainerStats{
|
||||||
Attributes: &runtimeapi.ContainerAttributes{
|
Attributes: &runtimeapi.ContainerAttributes{
|
||||||
@ -58,13 +70,12 @@ func (ds *dockerService) getContainerStats(containerID string) (*runtimeapi.Cont
|
|||||||
},
|
},
|
||||||
Cpu: &runtimeapi.CpuUsage{
|
Cpu: &runtimeapi.CpuUsage{
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
// have to multiply cpu usage by 100 since docker stats units is in 100's of nano seconds for Windows
|
// have to multiply cpu usage by 100 since stats units is in 100's of nano seconds for Windows
|
||||||
// see https://github.com/moby/moby/blob/v1.13.1/api/types/stats.go#L22
|
UsageCoreNanoSeconds: &runtimeapi.UInt64Value{Value: stats.Processor.TotalRuntime100ns * 100},
|
||||||
UsageCoreNanoSeconds: &runtimeapi.UInt64Value{Value: dockerStats.CPUStats.CPUUsage.TotalUsage * 100},
|
|
||||||
},
|
},
|
||||||
Memory: &runtimeapi.MemoryUsage{
|
Memory: &runtimeapi.MemoryUsage{
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
WorkingSetBytes: &runtimeapi.UInt64Value{Value: dockerStats.MemoryStats.PrivateWorkingSet},
|
WorkingSetBytes: &runtimeapi.UInt64Value{Value: stats.Memory.UsagePrivateWorkingSetBytes},
|
||||||
},
|
},
|
||||||
WritableLayer: &runtimeapi.FilesystemUsage{
|
WritableLayer: &runtimeapi.FilesystemUsage{
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
|
Loading…
Reference in New Issue
Block a user