metrics.go 2.1 KB

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