1/*
2Copyright 2017 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package nodelifecycle
18
19import (
20	"sync"
21
22	"k8s.io/component-base/metrics"
23	"k8s.io/component-base/metrics/legacyregistry"
24)
25
26const (
27	nodeControllerSubsystem = "node_collector"
28	zoneHealthStatisticKey  = "zone_health"
29	zoneSizeKey             = "zone_size"
30	zoneNoUnhealthyNodesKey = "unhealthy_nodes_in_zone"
31	evictionsNumberKey      = "evictions_number"
32)
33
34var (
35	zoneHealth = metrics.NewGaugeVec(
36		&metrics.GaugeOpts{
37			Subsystem:      nodeControllerSubsystem,
38			Name:           zoneHealthStatisticKey,
39			Help:           "Gauge measuring percentage of healthy nodes per zone.",
40			StabilityLevel: metrics.ALPHA,
41		},
42		[]string{"zone"},
43	)
44	zoneSize = metrics.NewGaugeVec(
45		&metrics.GaugeOpts{
46			Subsystem:      nodeControllerSubsystem,
47			Name:           zoneSizeKey,
48			Help:           "Gauge measuring number of registered Nodes per zones.",
49			StabilityLevel: metrics.ALPHA,
50		},
51		[]string{"zone"},
52	)
53	unhealthyNodes = metrics.NewGaugeVec(
54		&metrics.GaugeOpts{
55			Subsystem:      nodeControllerSubsystem,
56			Name:           zoneNoUnhealthyNodesKey,
57			Help:           "Gauge measuring number of not Ready Nodes per zones.",
58			StabilityLevel: metrics.ALPHA,
59		},
60		[]string{"zone"},
61	)
62	evictionsNumber = metrics.NewCounterVec(
63		&metrics.CounterOpts{
64			Subsystem:      nodeControllerSubsystem,
65			Name:           evictionsNumberKey,
66			Help:           "Number of Node evictions that happened since current instance of NodeController started.",
67			StabilityLevel: metrics.ALPHA,
68		},
69		[]string{"zone"},
70	)
71)
72
73var registerMetrics sync.Once
74
75// Register the metrics that are to be monitored.
76func Register() {
77	registerMetrics.Do(func() {
78		legacyregistry.MustRegister(zoneHealth)
79		legacyregistry.MustRegister(zoneSize)
80		legacyregistry.MustRegister(unhealthyNodes)
81		legacyregistry.MustRegister(evictionsNumber)
82	})
83}
84