...

Source file src/k8s.io/component-base/metrics/prometheus/workqueue/metrics.go

Documentation: k8s.io/component-base/metrics/prometheus/workqueue

     1  /*
     2  Copyright 2019 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 workqueue
    18  
    19  import (
    20  	"k8s.io/client-go/util/workqueue"
    21  	k8smetrics "k8s.io/component-base/metrics"
    22  	"k8s.io/component-base/metrics/legacyregistry"
    23  )
    24  
    25  // Package prometheus sets the workqueue DefaultMetricsFactory to produce
    26  // prometheus metrics. To use this package, you just have to import it.
    27  
    28  // Metrics subsystem and keys used by the workqueue.
    29  const (
    30  	WorkQueueSubsystem         = "workqueue"
    31  	DepthKey                   = "depth"
    32  	AddsKey                    = "adds_total"
    33  	QueueLatencyKey            = "queue_duration_seconds"
    34  	WorkDurationKey            = "work_duration_seconds"
    35  	UnfinishedWorkKey          = "unfinished_work_seconds"
    36  	LongestRunningProcessorKey = "longest_running_processor_seconds"
    37  	RetriesKey                 = "retries_total"
    38  )
    39  
    40  var (
    41  	depth = k8smetrics.NewGaugeVec(&k8smetrics.GaugeOpts{
    42  		Subsystem:      WorkQueueSubsystem,
    43  		Name:           DepthKey,
    44  		StabilityLevel: k8smetrics.ALPHA,
    45  		Help:           "Current depth of workqueue",
    46  	}, []string{"name"})
    47  
    48  	adds = k8smetrics.NewCounterVec(&k8smetrics.CounterOpts{
    49  		Subsystem:      WorkQueueSubsystem,
    50  		Name:           AddsKey,
    51  		StabilityLevel: k8smetrics.ALPHA,
    52  		Help:           "Total number of adds handled by workqueue",
    53  	}, []string{"name"})
    54  
    55  	latency = k8smetrics.NewHistogramVec(&k8smetrics.HistogramOpts{
    56  		Subsystem:      WorkQueueSubsystem,
    57  		Name:           QueueLatencyKey,
    58  		StabilityLevel: k8smetrics.ALPHA,
    59  		Help:           "How long in seconds an item stays in workqueue before being requested.",
    60  		Buckets:        k8smetrics.ExponentialBuckets(10e-9, 10, 10),
    61  	}, []string{"name"})
    62  
    63  	workDuration = k8smetrics.NewHistogramVec(&k8smetrics.HistogramOpts{
    64  		Subsystem:      WorkQueueSubsystem,
    65  		Name:           WorkDurationKey,
    66  		StabilityLevel: k8smetrics.ALPHA,
    67  		Help:           "How long in seconds processing an item from workqueue takes.",
    68  		Buckets:        k8smetrics.ExponentialBuckets(10e-9, 10, 10),
    69  	}, []string{"name"})
    70  
    71  	unfinished = k8smetrics.NewGaugeVec(&k8smetrics.GaugeOpts{
    72  		Subsystem:      WorkQueueSubsystem,
    73  		Name:           UnfinishedWorkKey,
    74  		StabilityLevel: k8smetrics.ALPHA,
    75  		Help: "How many seconds of work has done that " +
    76  			"is in progress and hasn't been observed by work_duration. Large " +
    77  			"values indicate stuck threads. One can deduce the number of stuck " +
    78  			"threads by observing the rate at which this increases.",
    79  	}, []string{"name"})
    80  
    81  	longestRunningProcessor = k8smetrics.NewGaugeVec(&k8smetrics.GaugeOpts{
    82  		Subsystem:      WorkQueueSubsystem,
    83  		Name:           LongestRunningProcessorKey,
    84  		StabilityLevel: k8smetrics.ALPHA,
    85  		Help: "How many seconds has the longest running " +
    86  			"processor for workqueue been running.",
    87  	}, []string{"name"})
    88  
    89  	retries = k8smetrics.NewCounterVec(&k8smetrics.CounterOpts{
    90  		Subsystem:      WorkQueueSubsystem,
    91  		Name:           RetriesKey,
    92  		StabilityLevel: k8smetrics.ALPHA,
    93  		Help:           "Total number of retries handled by workqueue",
    94  	}, []string{"name"})
    95  
    96  	metrics = []k8smetrics.Registerable{
    97  		depth, adds, latency, workDuration, unfinished, longestRunningProcessor, retries,
    98  	}
    99  )
   100  
   101  type prometheusMetricsProvider struct {
   102  }
   103  
   104  func init() {
   105  	for _, m := range metrics {
   106  		legacyregistry.MustRegister(m)
   107  	}
   108  	workqueue.SetProvider(prometheusMetricsProvider{})
   109  }
   110  
   111  func (prometheusMetricsProvider) NewDepthMetric(name string) workqueue.GaugeMetric {
   112  	return depth.WithLabelValues(name)
   113  }
   114  
   115  func (prometheusMetricsProvider) NewAddsMetric(name string) workqueue.CounterMetric {
   116  	return adds.WithLabelValues(name)
   117  }
   118  
   119  func (prometheusMetricsProvider) NewLatencyMetric(name string) workqueue.HistogramMetric {
   120  	return latency.WithLabelValues(name)
   121  }
   122  
   123  func (prometheusMetricsProvider) NewWorkDurationMetric(name string) workqueue.HistogramMetric {
   124  	return workDuration.WithLabelValues(name)
   125  }
   126  
   127  func (prometheusMetricsProvider) NewUnfinishedWorkSecondsMetric(name string) workqueue.SettableGaugeMetric {
   128  	return unfinished.WithLabelValues(name)
   129  }
   130  
   131  func (prometheusMetricsProvider) NewLongestRunningProcessorSecondsMetric(name string) workqueue.SettableGaugeMetric {
   132  	return longestRunningProcessor.WithLabelValues(name)
   133  }
   134  
   135  func (prometheusMetricsProvider) NewRetriesMetric(name string) workqueue.CounterMetric {
   136  	return retries.WithLabelValues(name)
   137  }
   138  

View as plain text