metrics.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright 2015 The etcd Authors
  2. //
  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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package etcdserver
  15. import (
  16. "time"
  17. "github.com/coreos/etcd/pkg/runtime"
  18. "github.com/prometheus/client_golang/prometheus"
  19. )
  20. var (
  21. // TODO: with label in v3?
  22. proposeDurations = prometheus.NewHistogram(prometheus.HistogramOpts{
  23. Namespace: "etcd_debugging",
  24. Subsystem: "server",
  25. Name: "proposal_duration_seconds",
  26. Help: "The latency distributions of committing proposal.",
  27. Buckets: prometheus.ExponentialBuckets(0.001, 2, 14),
  28. })
  29. proposePending = prometheus.NewGauge(prometheus.GaugeOpts{
  30. Namespace: "etcd_debugging",
  31. Subsystem: "server",
  32. Name: "proposals_pending",
  33. Help: "The current number of pending proposals.",
  34. })
  35. // This is number of proposal failed in client's view.
  36. // The proposal might be later got committed in raft.
  37. proposeFailed = prometheus.NewCounter(prometheus.CounterOpts{
  38. Namespace: "etcd_debugging",
  39. Subsystem: "server",
  40. Name: "proposals_failed_total",
  41. Help: "The total number of failed proposals.",
  42. })
  43. // stable metrics for monitoring
  44. hasLeader = prometheus.NewGauge(prometheus.GaugeOpts{
  45. Namespace: "etcd",
  46. Subsystem: "server",
  47. Name: "has_leader",
  48. Help: "Whether or not a leader exists. 1 is existence, 0 is not.",
  49. })
  50. leaderChanges = prometheus.NewCounter(prometheus.CounterOpts{
  51. Namespace: "etcd",
  52. Subsystem: "server",
  53. Name: "leader_changes_seen_total",
  54. Help: "The number of leader changes seen.",
  55. })
  56. proposalsCommitted = prometheus.NewGauge(prometheus.GaugeOpts{
  57. Namespace: "etcd",
  58. Subsystem: "server",
  59. Name: "proposals_committed_total",
  60. Help: "The total number of consensus proposals committed.",
  61. })
  62. )
  63. func init() {
  64. prometheus.MustRegister(proposeDurations)
  65. prometheus.MustRegister(proposePending)
  66. prometheus.MustRegister(proposeFailed)
  67. prometheus.MustRegister(hasLeader)
  68. prometheus.MustRegister(leaderChanges)
  69. prometheus.MustRegister(proposalsCommitted)
  70. }
  71. func monitorFileDescriptor(done <-chan struct{}) {
  72. ticker := time.NewTicker(5 * time.Second)
  73. defer ticker.Stop()
  74. for {
  75. used, err := runtime.FDUsage()
  76. if err != nil {
  77. plog.Errorf("cannot monitor file descriptor usage (%v)", err)
  78. return
  79. }
  80. limit, err := runtime.FDLimit()
  81. if err != nil {
  82. plog.Errorf("cannot monitor file descriptor usage (%v)", err)
  83. return
  84. }
  85. if used >= limit/5*4 {
  86. plog.Warningf("80%% of the file descriptor limit is used [used = %d, limit = %d]", used, limit)
  87. }
  88. select {
  89. case <-ticker.C:
  90. case <-done:
  91. return
  92. }
  93. }
  94. }