1
16
17
18 package monitor
19
20 import (
21 "sync"
22
23 "k8s.io/component-base/metrics"
24 "k8s.io/component-base/metrics/legacyregistry"
25 )
26
27 const (
28
29 hpaControllerSubsystem = "horizontal_pod_autoscaler_controller"
30 )
31
32 var (
33 reconciliationsTotal = metrics.NewCounterVec(
34 &metrics.CounterOpts{
35 Subsystem: hpaControllerSubsystem,
36 Name: "reconciliations_total",
37 Help: "Number of reconciliations of HPA controller. The label 'action' should be either 'scale_down', 'scale_up', or 'none'. Also, the label 'error' should be either 'spec', 'internal', or 'none'. Note that if both spec and internal errors happen during a reconciliation, the first one to occur is reported in `error` label.",
38 StabilityLevel: metrics.ALPHA,
39 }, []string{"action", "error"})
40
41 reconciliationsDuration = metrics.NewHistogramVec(
42 &metrics.HistogramOpts{
43 Subsystem: hpaControllerSubsystem,
44 Name: "reconciliation_duration_seconds",
45 Help: "The time(seconds) that the HPA controller takes to reconcile once. The label 'action' should be either 'scale_down', 'scale_up', or 'none'. Also, the label 'error' should be either 'spec', 'internal', or 'none'. Note that if both spec and internal errors happen during a reconciliation, the first one to occur is reported in `error` label.",
46 Buckets: metrics.ExponentialBuckets(0.001, 2, 15),
47 StabilityLevel: metrics.ALPHA,
48 }, []string{"action", "error"})
49 metricComputationTotal = metrics.NewCounterVec(
50 &metrics.CounterOpts{
51 Subsystem: hpaControllerSubsystem,
52 Name: "metric_computation_total",
53 Help: "Number of metric computations. The label 'action' should be either 'scale_down', 'scale_up', or 'none'. Also, the label 'error' should be either 'spec', 'internal', or 'none'. The label 'metric_type' corresponds to HPA.spec.metrics[*].type",
54 StabilityLevel: metrics.ALPHA,
55 }, []string{"action", "error", "metric_type"})
56 metricComputationDuration = metrics.NewHistogramVec(
57 &metrics.HistogramOpts{
58 Subsystem: hpaControllerSubsystem,
59 Name: "metric_computation_duration_seconds",
60 Help: "The time(seconds) that the HPA controller takes to calculate one metric. The label 'action' should be either 'scale_down', 'scale_up', or 'none'. The label 'error' should be either 'spec', 'internal', or 'none'. The label 'metric_type' corresponds to HPA.spec.metrics[*].type",
61 Buckets: metrics.ExponentialBuckets(0.001, 2, 15),
62 StabilityLevel: metrics.ALPHA,
63 }, []string{"action", "error", "metric_type"})
64
65 metricsList = []metrics.Registerable{
66 reconciliationsTotal,
67 reconciliationsDuration,
68 metricComputationTotal,
69 metricComputationDuration,
70 }
71 )
72
73 var register sync.Once
74
75
76 func Register() {
77
78 register.Do(func() {
79 registerMetrics(metricsList...)
80 })
81 }
82
83
84 func registerMetrics(extraMetrics ...metrics.Registerable) {
85 for _, metric := range extraMetrics {
86 legacyregistry.MustRegister(metric)
87 }
88 }
89
View as plain text