metrics.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. goruntime "runtime"
  17. "time"
  18. "github.com/coreos/etcd/pkg/runtime"
  19. "github.com/coreos/etcd/version"
  20. "github.com/prometheus/client_golang/prometheus"
  21. )
  22. var (
  23. hasLeader = prometheus.NewGauge(prometheus.GaugeOpts{
  24. Namespace: "etcd",
  25. Subsystem: "server",
  26. Name: "has_leader",
  27. Help: "Whether or not a leader exists. 1 is existence, 0 is not.",
  28. })
  29. isLeader = prometheus.NewGauge(prometheus.GaugeOpts{
  30. Namespace: "etcd",
  31. Subsystem: "server",
  32. Name: "is_leader",
  33. Help: "Whether or not this member is a leader. 1 if is, 0 otherwise.",
  34. })
  35. leaderChanges = prometheus.NewCounter(prometheus.CounterOpts{
  36. Namespace: "etcd",
  37. Subsystem: "server",
  38. Name: "leader_changes_seen_total",
  39. Help: "The number of leader changes seen.",
  40. })
  41. heartbeatSendFailures = prometheus.NewCounter(prometheus.CounterOpts{
  42. Namespace: "etcd",
  43. Subsystem: "server",
  44. Name: "heartbeat_send_failures_total",
  45. Help: "The total number of leader heartbeat send failures (likely overloaded from slow disk).",
  46. })
  47. slowApplies = prometheus.NewCounter(prometheus.CounterOpts{
  48. Namespace: "etcd",
  49. Subsystem: "server",
  50. Name: "slow_apply_total",
  51. Help: "The total number of slow apply requests (likely overloaded from slow disk).",
  52. })
  53. applySnapshotInProgress = prometheus.NewGauge(prometheus.GaugeOpts{
  54. Namespace: "etcd",
  55. Subsystem: "server",
  56. Name: "snapshot_apply_in_progress_total",
  57. Help: "1 if the server is applying the incoming snapshot. 0 if none.",
  58. })
  59. proposalsCommitted = prometheus.NewGauge(prometheus.GaugeOpts{
  60. Namespace: "etcd",
  61. Subsystem: "server",
  62. Name: "proposals_committed_total",
  63. Help: "The total number of consensus proposals committed.",
  64. })
  65. proposalsApplied = prometheus.NewGauge(prometheus.GaugeOpts{
  66. Namespace: "etcd",
  67. Subsystem: "server",
  68. Name: "proposals_applied_total",
  69. Help: "The total number of consensus proposals applied.",
  70. })
  71. proposalsPending = prometheus.NewGauge(prometheus.GaugeOpts{
  72. Namespace: "etcd",
  73. Subsystem: "server",
  74. Name: "proposals_pending",
  75. Help: "The current number of pending proposals to commit.",
  76. })
  77. proposalsFailed = prometheus.NewCounter(prometheus.CounterOpts{
  78. Namespace: "etcd",
  79. Subsystem: "server",
  80. Name: "proposals_failed_total",
  81. Help: "The total number of failed proposals seen.",
  82. })
  83. leaseExpired = prometheus.NewCounter(prometheus.CounterOpts{
  84. Namespace: "etcd_debugging",
  85. Subsystem: "server",
  86. Name: "lease_expired_total",
  87. Help: "The total number of expired leases.",
  88. })
  89. slowReadIndex = prometheus.NewCounter(prometheus.CounterOpts{
  90. Namespace: "etcd",
  91. Subsystem: "server",
  92. Name: "slow_read_indexes_total",
  93. Help: "The total number of pending read indexes not in sync with leader's or timed out read index requests.",
  94. })
  95. readIndexFailed = prometheus.NewCounter(prometheus.CounterOpts{
  96. Namespace: "etcd",
  97. Subsystem: "server",
  98. Name: "read_indexes_failed_total",
  99. Help: "The total number of failed read indexes seen.",
  100. })
  101. quotaBackendBytes = prometheus.NewGauge(prometheus.GaugeOpts{
  102. Namespace: "etcd",
  103. Subsystem: "server",
  104. Name: "quota_backend_bytes",
  105. Help: "Current backend storage quota size in bytes.",
  106. })
  107. currentVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{
  108. Namespace: "etcd",
  109. Subsystem: "server",
  110. Name: "version",
  111. Help: "Which version is running. 1 for 'server_version' label with current version.",
  112. },
  113. []string{"server_version"})
  114. currentGoVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{
  115. Namespace: "etcd",
  116. Subsystem: "server",
  117. Name: "go_version",
  118. Help: "Which Go version server is running with. 1 for 'server_go_version' label with current version.",
  119. },
  120. []string{"server_go_version"})
  121. serverID = prometheus.NewGaugeVec(prometheus.GaugeOpts{
  122. Namespace: "etcd",
  123. Subsystem: "server",
  124. Name: "id",
  125. Help: "Server or member ID in hexadecimal format. 1 for 'server_id' label with current ID.",
  126. },
  127. []string{"server_id"})
  128. )
  129. func init() {
  130. prometheus.MustRegister(hasLeader)
  131. prometheus.MustRegister(isLeader)
  132. prometheus.MustRegister(leaderChanges)
  133. prometheus.MustRegister(heartbeatSendFailures)
  134. prometheus.MustRegister(slowApplies)
  135. prometheus.MustRegister(applySnapshotInProgress)
  136. prometheus.MustRegister(proposalsCommitted)
  137. prometheus.MustRegister(proposalsApplied)
  138. prometheus.MustRegister(proposalsPending)
  139. prometheus.MustRegister(proposalsFailed)
  140. prometheus.MustRegister(leaseExpired)
  141. prometheus.MustRegister(slowReadIndex)
  142. prometheus.MustRegister(readIndexFailed)
  143. prometheus.MustRegister(quotaBackendBytes)
  144. prometheus.MustRegister(currentVersion)
  145. prometheus.MustRegister(currentGoVersion)
  146. prometheus.MustRegister(serverID)
  147. currentVersion.With(prometheus.Labels{
  148. "server_version": version.Version,
  149. }).Set(1)
  150. currentGoVersion.With(prometheus.Labels{
  151. "server_go_version": goruntime.Version(),
  152. }).Set(1)
  153. }
  154. func monitorFileDescriptor(done <-chan struct{}) {
  155. ticker := time.NewTicker(5 * time.Second)
  156. defer ticker.Stop()
  157. for {
  158. used, err := runtime.FDUsage()
  159. if err != nil {
  160. plog.Errorf("cannot monitor file descriptor usage (%v)", err)
  161. return
  162. }
  163. limit, err := runtime.FDLimit()
  164. if err != nil {
  165. plog.Errorf("cannot monitor file descriptor usage (%v)", err)
  166. return
  167. }
  168. if used >= limit/5*4 {
  169. plog.Warningf("80%% of the file descriptor limit is used [used = %d, limit = %d]", used, limit)
  170. }
  171. select {
  172. case <-ticker.C:
  173. case <-done:
  174. return
  175. }
  176. }
  177. }