mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Remove ManagedPod,ManagedContainer metrics
This replaces the generic ManagedPod and ManagedContainer kubelet metrics with a gauge to track only ephemeral container usage.
This commit is contained in:
parent
29178fff1c
commit
30d2ad576a
@ -84,14 +84,15 @@ const (
|
||||
RunPodSandboxDurationKey = "run_podsandbox_duration_seconds"
|
||||
RunPodSandboxErrorsKey = "run_podsandbox_errors_total"
|
||||
|
||||
// Metrics to keep track of objects under management
|
||||
ManagedPodsKey = "managed_pods"
|
||||
ManagedContainersKey = "managed_containers"
|
||||
// Metrics to keep track of total number of Pods and Containers started
|
||||
StartedPodsTotalKey = "started_pods_total"
|
||||
StartedPodsErrorsTotalKey = "started_pods_errors_total"
|
||||
StartedContainersTotalKey = "started_containers_total"
|
||||
StartedContainersErrorsTotalKey = "started_containers_errors_total"
|
||||
|
||||
// Metrics to track ephemeral container usage by this kubelet
|
||||
ManagedEphemeralContainersKey = "managed_ephemeral_containers"
|
||||
|
||||
// Values used in metric labels
|
||||
Container = "container"
|
||||
InitContainer = "init_container"
|
||||
@ -483,25 +484,15 @@ var (
|
||||
},
|
||||
[]string{"container_type", "code"},
|
||||
)
|
||||
// ManagedPods is a gauge that tracks how many pods are managed by this kubelet
|
||||
ManagedPods = metrics.NewGauge(
|
||||
// ManagedEphemeralContainers is a gauge that indicates how many ephemeral containers are managed by this kubelet.
|
||||
ManagedEphemeralContainers = metrics.NewGauge(
|
||||
&metrics.GaugeOpts{
|
||||
Subsystem: KubeletSubsystem,
|
||||
Name: ManagedPodsKey,
|
||||
Help: "Number of pods managed by this kubelet",
|
||||
Name: ManagedEphemeralContainersKey,
|
||||
Help: "Current number of ephemeral containers in pods managed by this kubelet. Ephemeral containers will be ignored if disabled by the EphemeralContainers feature gate, and this number will be 0.",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
)
|
||||
// ManagedContainers is a gauge that tracks how many containers are managed by this kubelet
|
||||
ManagedContainers = metrics.NewGaugeVec(
|
||||
&metrics.GaugeOpts{
|
||||
Subsystem: KubeletSubsystem,
|
||||
Name: ManagedContainersKey,
|
||||
Help: "Number of containers managed by this kubelet",
|
||||
StabilityLevel: metrics.ALPHA,
|
||||
},
|
||||
[]string{"container_type"},
|
||||
)
|
||||
)
|
||||
|
||||
var registerMetrics sync.Once
|
||||
@ -530,8 +521,7 @@ func Register(collectors ...metrics.StableCollector) {
|
||||
legacyregistry.MustRegister(DevicePluginAllocationDuration)
|
||||
legacyregistry.MustRegister(RunningContainerCount)
|
||||
legacyregistry.MustRegister(RunningPodCount)
|
||||
legacyregistry.MustRegister(ManagedPods)
|
||||
legacyregistry.MustRegister(ManagedContainers)
|
||||
legacyregistry.MustRegister(ManagedEphemeralContainers)
|
||||
legacyregistry.MustRegister(StartedPodsTotal)
|
||||
legacyregistry.MustRegister(StartedPodsErrorsTotal)
|
||||
legacyregistry.MustRegister(StartedContainersTotal)
|
||||
|
@ -162,42 +162,22 @@ func isPodInTerminatedState(pod *v1.Pod) bool {
|
||||
return pod.Status.Phase == v1.PodFailed || pod.Status.Phase == v1.PodSucceeded
|
||||
}
|
||||
|
||||
// updateMetrics updates the gauge metrics that track how many pods and containers this kubelet manages.
|
||||
// oldPod or newPod may be nil to signify creation or deletion, respectively.
|
||||
// updateMetrics updates the metrics surfaced by the pod manager.
|
||||
// oldPod or newPod may be nil to signify creation or deletion.
|
||||
func updateMetrics(oldPod, newPod *v1.Pod) {
|
||||
var numC, numIC, numEC int
|
||||
countEC := utilfeature.DefaultFeatureGate.Enabled(features.EphemeralContainers)
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.EphemeralContainers) {
|
||||
return
|
||||
}
|
||||
|
||||
var numEC int
|
||||
if oldPod != nil {
|
||||
if newPod == nil {
|
||||
metrics.ManagedPods.Dec()
|
||||
}
|
||||
numC -= len(oldPod.Spec.Containers)
|
||||
numIC -= len(oldPod.Spec.InitContainers)
|
||||
if countEC {
|
||||
numEC -= len(oldPod.Spec.EphemeralContainers)
|
||||
}
|
||||
numEC -= len(oldPod.Spec.EphemeralContainers)
|
||||
}
|
||||
|
||||
if newPod != nil {
|
||||
if oldPod == nil {
|
||||
metrics.ManagedPods.Inc()
|
||||
}
|
||||
numC += len(newPod.Spec.Containers)
|
||||
numIC += len(newPod.Spec.InitContainers)
|
||||
if countEC {
|
||||
numEC += len(newPod.Spec.EphemeralContainers)
|
||||
}
|
||||
numEC += len(newPod.Spec.EphemeralContainers)
|
||||
}
|
||||
|
||||
if numC != 0 {
|
||||
metrics.ManagedContainers.WithLabelValues(metrics.Container).Add(float64(numC))
|
||||
}
|
||||
if numIC != 0 {
|
||||
metrics.ManagedContainers.WithLabelValues(metrics.InitContainer).Add(float64(numIC))
|
||||
}
|
||||
if countEC && numEC != 0 {
|
||||
metrics.ManagedContainers.WithLabelValues(metrics.EphemeralContainer).Add(float64(numEC))
|
||||
if numEC != 0 {
|
||||
metrics.ManagedEphemeralContainers.Add(float64(numEC))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user