sigs.k8s.io/controller-runtime@v0.18.2/pkg/internal/controller/metrics/metrics.go (about) 1 /* 2 Copyright 2018 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 "github.com/prometheus/client_golang/prometheus" 21 "github.com/prometheus/client_golang/prometheus/collectors" 22 "sigs.k8s.io/controller-runtime/pkg/metrics" 23 ) 24 25 var ( 26 // ReconcileTotal is a prometheus counter metrics which holds the total 27 // number of reconciliations per controller. It has two labels. controller label refers 28 // to the controller name and result label refers to the reconcile result i.e 29 // success, error, requeue, requeue_after. 30 ReconcileTotal = prometheus.NewCounterVec(prometheus.CounterOpts{ 31 Name: "controller_runtime_reconcile_total", 32 Help: "Total number of reconciliations per controller", 33 }, []string{"controller", "result"}) 34 35 // ReconcileErrors is a prometheus counter metrics which holds the total 36 // number of errors from the Reconciler. 37 ReconcileErrors = prometheus.NewCounterVec(prometheus.CounterOpts{ 38 Name: "controller_runtime_reconcile_errors_total", 39 Help: "Total number of reconciliation errors per controller", 40 }, []string{"controller"}) 41 42 // TerminalReconcileErrors is a prometheus counter metrics which holds the total 43 // number of terminal errors from the Reconciler. 44 TerminalReconcileErrors = prometheus.NewCounterVec(prometheus.CounterOpts{ 45 Name: "controller_runtime_terminal_reconcile_errors_total", 46 Help: "Total number of terminal reconciliation errors per controller", 47 }, []string{"controller"}) 48 49 // ReconcileTime is a prometheus metric which keeps track of the duration 50 // of reconciliations. 51 ReconcileTime = prometheus.NewHistogramVec(prometheus.HistogramOpts{ 52 Name: "controller_runtime_reconcile_time_seconds", 53 Help: "Length of time per reconciliation per controller", 54 Buckets: []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 55 1.25, 1.5, 1.75, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30, 40, 50, 60}, 56 }, []string{"controller"}) 57 58 // WorkerCount is a prometheus metric which holds the number of 59 // concurrent reconciles per controller. 60 WorkerCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 61 Name: "controller_runtime_max_concurrent_reconciles", 62 Help: "Maximum number of concurrent reconciles per controller", 63 }, []string{"controller"}) 64 65 // ActiveWorkers is a prometheus metric which holds the number 66 // of active workers per controller. 67 ActiveWorkers = prometheus.NewGaugeVec(prometheus.GaugeOpts{ 68 Name: "controller_runtime_active_workers", 69 Help: "Number of currently used workers per controller", 70 }, []string{"controller"}) 71 ) 72 73 func init() { 74 metrics.Registry.MustRegister( 75 ReconcileTotal, 76 ReconcileErrors, 77 TerminalReconcileErrors, 78 ReconcileTime, 79 WorkerCount, 80 ActiveWorkers, 81 // expose process metrics like CPU, Memory, file descriptor usage etc. 82 collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}), 83 // expose Go runtime metrics like GC stats, memory stats etc. 84 collectors.NewGoCollector(), 85 ) 86 }