metrics.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. Copyright 2015 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 metrics
  14. import (
  15. "sync"
  16. "time"
  17. "github.com/prometheus/client_golang/prometheus"
  18. )
  19. const schedulerSubsystem = "scheduler"
  20. var BindingSaturationReportInterval = 1 * time.Second
  21. var (
  22. E2eSchedulingLatency = prometheus.NewHistogram(
  23. prometheus.HistogramOpts{
  24. Subsystem: schedulerSubsystem,
  25. Name: "e2e_scheduling_latency_microseconds",
  26. Help: "E2e scheduling latency (scheduling algorithm + binding)",
  27. Buckets: prometheus.ExponentialBuckets(1000, 2, 15),
  28. },
  29. )
  30. SchedulingAlgorithmLatency = prometheus.NewHistogram(
  31. prometheus.HistogramOpts{
  32. Subsystem: schedulerSubsystem,
  33. Name: "scheduling_algorithm_latency_microseconds",
  34. Help: "Scheduling algorithm latency",
  35. Buckets: prometheus.ExponentialBuckets(1000, 2, 15),
  36. },
  37. )
  38. BindingLatency = prometheus.NewHistogram(
  39. prometheus.HistogramOpts{
  40. Subsystem: schedulerSubsystem,
  41. Name: "binding_latency_microseconds",
  42. Help: "Binding latency",
  43. Buckets: prometheus.ExponentialBuckets(1000, 2, 15),
  44. },
  45. )
  46. )
  47. var registerMetrics sync.Once
  48. // Register all metrics.
  49. func Register() {
  50. // Register the metrics.
  51. registerMetrics.Do(func() {
  52. prometheus.MustRegister(E2eSchedulingLatency)
  53. prometheus.MustRegister(SchedulingAlgorithmLatency)
  54. prometheus.MustRegister(BindingLatency)
  55. })
  56. }
  57. // Gets the time since the specified start in microseconds.
  58. func SinceInMicroseconds(start time.Time) float64 {
  59. return float64(time.Since(start).Nanoseconds() / time.Microsecond.Nanoseconds())
  60. }