mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-06 07:57:35 +00:00
Use the default interface for reporting network stats.
This commit is contained in:
@@ -27,6 +27,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm"
|
||||
"k8s.io/kubernetes/pkg/kubelet/dockertools"
|
||||
"k8s.io/kubernetes/pkg/kubelet/leaky"
|
||||
"k8s.io/kubernetes/pkg/kubelet/network"
|
||||
"k8s.io/kubernetes/pkg/types"
|
||||
|
||||
"github.com/golang/glog"
|
||||
@@ -107,7 +108,7 @@ func (sb *summaryBuilder) build() (*stats.Summary, error) {
|
||||
NodeName: sb.node.Name,
|
||||
CPU: rootStats.CPU,
|
||||
Memory: rootStats.Memory,
|
||||
Network: sb.containerInfoV2ToNetworkStats(&rootInfo),
|
||||
Network: sb.containerInfoV2ToNetworkStats("node:"+sb.node.Name, &rootInfo),
|
||||
Fs: &stats.FsStats{
|
||||
AvailableBytes: &sb.rootFsInfo.Available,
|
||||
CapacityBytes: &sb.rootFsInfo.Capacity,
|
||||
@@ -201,7 +202,7 @@ func (sb *summaryBuilder) buildSummaryPods() []stats.PodStats {
|
||||
containerName := dockertools.GetContainerName(cinfo.Spec.Labels)
|
||||
if containerName == leaky.PodInfraContainerName {
|
||||
// Special case for infrastructure container which is hidden from the user and has network stats
|
||||
podStats.Network = sb.containerInfoV2ToNetworkStats(&cinfo)
|
||||
podStats.Network = sb.containerInfoV2ToNetworkStats("pod:"+ref.Namespace+"_"+ref.Name, &cinfo)
|
||||
podStats.StartTime = unversioned.NewTime(cinfo.Spec.CreationTime)
|
||||
} else {
|
||||
podStats.Containers = append(podStats.Containers, sb.containerInfoV2ToStats(containerName, &cinfo))
|
||||
@@ -281,7 +282,7 @@ func (sb *summaryBuilder) containerInfoV2ToStats(
|
||||
return cStats
|
||||
}
|
||||
|
||||
func (sb *summaryBuilder) containerInfoV2ToNetworkStats(info *cadvisorapiv2.ContainerInfo) *stats.NetworkStats {
|
||||
func (sb *summaryBuilder) containerInfoV2ToNetworkStats(name string, info *cadvisorapiv2.ContainerInfo) *stats.NetworkStats {
|
||||
if !info.Spec.HasNetwork {
|
||||
return nil
|
||||
}
|
||||
@@ -289,26 +290,19 @@ func (sb *summaryBuilder) containerInfoV2ToNetworkStats(info *cadvisorapiv2.Cont
|
||||
if !found {
|
||||
return nil
|
||||
}
|
||||
var (
|
||||
rxBytes uint64
|
||||
rxErrors uint64
|
||||
txBytes uint64
|
||||
txErrors uint64
|
||||
)
|
||||
// TODO(stclair): check for overflow
|
||||
for _, inter := range cstat.Network.Interfaces {
|
||||
rxBytes += inter.RxBytes
|
||||
rxErrors += inter.RxErrors
|
||||
txBytes += inter.TxBytes
|
||||
txErrors += inter.TxErrors
|
||||
}
|
||||
return &stats.NetworkStats{
|
||||
Time: unversioned.NewTime(cstat.Timestamp),
|
||||
RxBytes: &rxBytes,
|
||||
RxErrors: &rxErrors,
|
||||
TxBytes: &txBytes,
|
||||
TxErrors: &txErrors,
|
||||
if inter.Name == network.DefaultInterfaceName {
|
||||
return &stats.NetworkStats{
|
||||
Time: unversioned.NewTime(cstat.Timestamp),
|
||||
RxBytes: &inter.RxBytes,
|
||||
RxErrors: &inter.RxErrors,
|
||||
TxBytes: &inter.TxBytes,
|
||||
TxErrors: &inter.TxErrors,
|
||||
}
|
||||
}
|
||||
}
|
||||
glog.Warningf("Missing default interface %q for s", network.DefaultInterfaceName, name)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sb *summaryBuilder) containerInfoV2ToUserDefinedMetrics(info *cadvisorapiv2.ContainerInfo) []stats.UserDefinedMetric {
|
||||
|
||||
Reference in New Issue
Block a user