metrics.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. hasLeader = prometheus.NewGauge(prometheus.GaugeOpts{
  22. Namespace: "etcd",
  23. Subsystem: "server",
  24. Name: "has_leader",
  25. Help: "Whether or not a leader exists. 1 is existence, 0 is not.",
  26. })
  27. leaderChanges = prometheus.NewCounter(prometheus.CounterOpts{
  28. Namespace: "etcd",
  29. Subsystem: "server",
  30. Name: "leader_changes_seen_total",
  31. Help: "The number of leader changes seen.",
  32. })
  33. proposalsCommitted = prometheus.NewGauge(prometheus.GaugeOpts{
  34. Namespace: "etcd",
  35. Subsystem: "server",
  36. Name: "proposals_committed_total",
  37. Help: "The total number of consensus proposals committed.",
  38. })
  39. proposalsApplied = prometheus.NewGauge(prometheus.GaugeOpts{
  40. Namespace: "etcd",
  41. Subsystem: "server",
  42. Name: "proposals_applied_total",
  43. Help: "The total number of consensus proposals applied.",
  44. })
  45. proposalsPending = prometheus.NewGauge(prometheus.GaugeOpts{
  46. Namespace: "etcd",
  47. Subsystem: "server",
  48. Name: "proposals_pending",
  49. Help: "The current number of pending proposals to commit.",
  50. })
  51. proposalsFailed = prometheus.NewCounter(prometheus.CounterOpts{
  52. Namespace: "etcd",
  53. Subsystem: "server",
  54. Name: "proposals_failed_total",
  55. Help: "The total number of failed proposals seen.",
  56. })
  57. leaseExpired = prometheus.NewCounter(prometheus.CounterOpts{
  58. Namespace: "etcd_debugging",
  59. Subsystem: "server",
  60. Name: "lease_expired_total",
  61. Help: "The total number of expired leases.",
  62. })
  63. )
  64. func init() {
  65. prometheus.MustRegister(hasLeader)
  66. prometheus.MustRegister(leaderChanges)
  67. prometheus.MustRegister(proposalsCommitted)
  68. prometheus.MustRegister(proposalsApplied)
  69. prometheus.MustRegister(proposalsPending)
  70. prometheus.MustRegister(proposalsFailed)
  71. prometheus.MustRegister(leaseExpired)
  72. }
  73. func monitorFileDescriptor(done <-chan struct{}) {
  74. ticker := time.NewTicker(5 * time.Second)
  75. defer ticker.Stop()
  76. for {
  77. used, err := runtime.FDUsage()
  78. if err != nil {
  79. plog.Errorf("cannot monitor file descriptor usage (%v)", err)
  80. return
  81. }
  82. limit, err := runtime.FDLimit()
  83. if err != nil {
  84. plog.Errorf("cannot monitor file descriptor usage (%v)", err)
  85. return
  86. }
  87. if used >= limit/5*4 {
  88. plog.Warningf("80%% of the file descriptor limit is used [used = %d, limit = %d]", used, limit)
  89. }
  90. select {
  91. case <-ticker.C:
  92. case <-done:
  93. return
  94. }
  95. }
  96. }