metrics.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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/coreos/etcd/version"
  19. "github.com/prometheus/client_golang/prometheus"
  20. )
  21. var (
  22. hasLeader = prometheus.NewGauge(prometheus.GaugeOpts{
  23. Namespace: "etcd",
  24. Subsystem: "server",
  25. Name: "has_leader",
  26. Help: "Whether or not a leader exists. 1 is existence, 0 is not.",
  27. })
  28. isLeader = prometheus.NewGauge(prometheus.GaugeOpts{
  29. Namespace: "etcd",
  30. Subsystem: "server",
  31. Name: "is_leader",
  32. Help: "Whether or not this member is a leader. 1 if is, 0 otherwise.",
  33. })
  34. leaderChanges = prometheus.NewCounter(prometheus.CounterOpts{
  35. Namespace: "etcd",
  36. Subsystem: "server",
  37. Name: "leader_changes_seen_total",
  38. Help: "The number of leader changes seen.",
  39. })
  40. heartbeatSendFailures = prometheus.NewCounter(prometheus.CounterOpts{
  41. Namespace: "etcd",
  42. Subsystem: "server",
  43. Name: "heartbeat_send_failures_total",
  44. Help: "The total number of leader heartbeat send failures (likely overloaded from slow disk).",
  45. })
  46. slowApplies = prometheus.NewCounter(prometheus.CounterOpts{
  47. Namespace: "etcd",
  48. Subsystem: "server",
  49. Name: "slow_apply_total",
  50. Help: "The total number of slow apply requests (likely overloaded from slow disk).",
  51. })
  52. proposalsCommitted = prometheus.NewGauge(prometheus.GaugeOpts{
  53. Namespace: "etcd",
  54. Subsystem: "server",
  55. Name: "proposals_committed_total",
  56. Help: "The total number of consensus proposals committed.",
  57. })
  58. proposalsApplied = prometheus.NewGauge(prometheus.GaugeOpts{
  59. Namespace: "etcd",
  60. Subsystem: "server",
  61. Name: "proposals_applied_total",
  62. Help: "The total number of consensus proposals applied.",
  63. })
  64. proposalsPending = prometheus.NewGauge(prometheus.GaugeOpts{
  65. Namespace: "etcd",
  66. Subsystem: "server",
  67. Name: "proposals_pending",
  68. Help: "The current number of pending proposals to commit.",
  69. })
  70. proposalsFailed = prometheus.NewCounter(prometheus.CounterOpts{
  71. Namespace: "etcd",
  72. Subsystem: "server",
  73. Name: "proposals_failed_total",
  74. Help: "The total number of failed proposals seen.",
  75. })
  76. leaseExpired = prometheus.NewCounter(prometheus.CounterOpts{
  77. Namespace: "etcd_debugging",
  78. Subsystem: "server",
  79. Name: "lease_expired_total",
  80. Help: "The total number of expired leases.",
  81. })
  82. quotaBackendBytes = prometheus.NewGauge(prometheus.GaugeOpts{
  83. Namespace: "etcd",
  84. Subsystem: "server",
  85. Name: "quota_backend_bytes",
  86. Help: "Current backend storage quota size in bytes.",
  87. })
  88. currentVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{
  89. Namespace: "etcd",
  90. Subsystem: "server",
  91. Name: "version",
  92. Help: "Which version is running. 1 for 'server_version' label with current version.",
  93. },
  94. []string{"server_version"})
  95. )
  96. func init() {
  97. prometheus.MustRegister(hasLeader)
  98. prometheus.MustRegister(isLeader)
  99. prometheus.MustRegister(leaderChanges)
  100. prometheus.MustRegister(heartbeatSendFailures)
  101. prometheus.MustRegister(slowApplies)
  102. prometheus.MustRegister(proposalsCommitted)
  103. prometheus.MustRegister(proposalsApplied)
  104. prometheus.MustRegister(proposalsPending)
  105. prometheus.MustRegister(proposalsFailed)
  106. prometheus.MustRegister(leaseExpired)
  107. prometheus.MustRegister(quotaBackendBytes)
  108. prometheus.MustRegister(currentVersion)
  109. currentVersion.With(prometheus.Labels{
  110. "server_version": version.Version,
  111. }).Set(1)
  112. }
  113. func monitorFileDescriptor(done <-chan struct{}) {
  114. ticker := time.NewTicker(5 * time.Second)
  115. defer ticker.Stop()
  116. for {
  117. used, err := runtime.FDUsage()
  118. if err != nil {
  119. plog.Errorf("cannot monitor file descriptor usage (%v)", err)
  120. return
  121. }
  122. limit, err := runtime.FDLimit()
  123. if err != nil {
  124. plog.Errorf("cannot monitor file descriptor usage (%v)", err)
  125. return
  126. }
  127. if used >= limit/5*4 {
  128. plog.Warningf("80%% of the file descriptor limit is used [used = %d, limit = %d]", used, limit)
  129. }
  130. select {
  131. case <-ticker.C:
  132. case <-done:
  133. return
  134. }
  135. }
  136. }