k8s.io/kubernetes@v1.29.3/pkg/controller/podgc/metrics/metrics.go (about)

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package metrics
    18  
    19  import (
    20  	"sync"
    21  
    22  	"k8s.io/component-base/metrics"
    23  	"k8s.io/component-base/metrics/legacyregistry"
    24  )
    25  
    26  const (
    27  	podGCController = "pod_gc_collector"
    28  )
    29  
    30  var (
    31  	DeletingPodsTotal = metrics.NewCounterVec(
    32  		&metrics.CounterOpts{
    33  			Subsystem:      podGCController,
    34  			Name:           "force_delete_pods_total",
    35  			Help:           "Number of pods that are being forcefully deleted since the Pod GC Controller started.",
    36  			StabilityLevel: metrics.ALPHA,
    37  		},
    38  		[]string{"namespace", "reason"},
    39  	)
    40  	DeletingPodsErrorTotal = metrics.NewCounterVec(
    41  		&metrics.CounterOpts{
    42  			Subsystem:      podGCController,
    43  			Name:           "force_delete_pod_errors_total",
    44  			Help:           "Number of errors encountered when forcefully deleting the pods since the Pod GC Controller started.",
    45  			StabilityLevel: metrics.ALPHA,
    46  		},
    47  		[]string{"namespace", "reason"},
    48  	)
    49  )
    50  
    51  const (
    52  	// Possible values for the "reason" label in the above metrics.
    53  
    54  	// PodGCReasonTerminated is used when the pod is terminated.
    55  	PodGCReasonTerminated = "terminated"
    56  	// PodGCReasonCompleted is used when the pod is terminating and the corresponding node
    57  	// is not ready and has `node.kubernetes.io/out-of-service` taint.
    58  	PodGCReasonTerminatingOutOfService = "out-of-service"
    59  	// PodGCReasonOrphaned is used when the pod is orphaned which means the corresponding node
    60  	// has been deleted.
    61  	PodGCReasonOrphaned = "orphaned"
    62  	// PodGCReasonUnscheduled is used when the pod is terminating and unscheduled.
    63  	PodGCReasonTerminatingUnscheduled = "unscheduled"
    64  )
    65  
    66  var registerMetrics sync.Once
    67  
    68  // Register the metrics that are to be monitored.
    69  func RegisterMetrics() {
    70  	registerMetrics.Do(func() {
    71  		legacyregistry.MustRegister(DeletingPodsTotal)
    72  		legacyregistry.MustRegister(DeletingPodsErrorTotal)
    73  	})
    74  }