metrics.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. proposalsCommitted = prometheus.NewGauge(prometheus.GaugeOpts{
  54. Namespace: "etcd",
  55. Subsystem: "server",
  56. Name: "proposals_committed_total",
  57. Help: "The total number of consensus proposals committed.",
  58. })
  59. proposalsApplied = prometheus.NewGauge(prometheus.GaugeOpts{
  60. Namespace: "etcd",
  61. Subsystem: "server",
  62. Name: "proposals_applied_total",
  63. Help: "The total number of consensus proposals applied.",
  64. })
  65. proposalsPending = prometheus.NewGauge(prometheus.GaugeOpts{
  66. Namespace: "etcd",
  67. Subsystem: "server",
  68. Name: "proposals_pending",
  69. Help: "The current number of pending proposals to commit.",
  70. })
  71. proposalsFailed = prometheus.NewCounter(prometheus.CounterOpts{
  72. Namespace: "etcd",
  73. Subsystem: "server",
  74. Name: "proposals_failed_total",
  75. Help: "The total number of failed proposals seen.",
  76. })
  77. slowReadIndex = prometheus.NewCounter(prometheus.CounterOpts{
  78. Namespace: "etcd",
  79. Subsystem: "server",
  80. Name: "slow_read_indexes_total",
  81. Help: "The total number of pending read indexes not in sync with leader's or timed out read index requests.",
  82. })
  83. readIndexFailed = prometheus.NewCounter(prometheus.CounterOpts{
  84. Namespace: "etcd",
  85. Subsystem: "server",
  86. Name: "read_indexes_failed_total",
  87. Help: "The total number of failed read indexes seen.",
  88. })
  89. quotaBackendBytes = prometheus.NewGauge(prometheus.GaugeOpts{
  90. Namespace: "etcd",
  91. Subsystem: "server",
  92. Name: "quota_backend_bytes",
  93. Help: "Current backend storage quota size in bytes.",
  94. })
  95. currentVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{
  96. Namespace: "etcd",
  97. Subsystem: "server",
  98. Name: "version",
  99. Help: "Which version is running. 1 for 'server_version' label with current version.",
  100. },
  101. []string{"server_version"})
  102. currentGoVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{
  103. Namespace: "etcd",
  104. Subsystem: "server",
  105. Name: "go_version",
  106. Help: "Which Go version server is running with. 1 for 'server_go_version' label with current version.",
  107. },
  108. []string{"server_go_version"})
  109. serverID = prometheus.NewGaugeVec(prometheus.GaugeOpts{
  110. Namespace: "etcd",
  111. Subsystem: "server",
  112. Name: "id",
  113. Help: "Server or member ID in hexadecimal format. 1 for 'server_id' label with current ID.",
  114. },
  115. []string{"server_id"})
  116. )
  117. func init() {
  118. prometheus.MustRegister(hasLeader)
  119. prometheus.MustRegister(isLeader)
  120. prometheus.MustRegister(leaderChanges)
  121. prometheus.MustRegister(heartbeatSendFailures)
  122. prometheus.MustRegister(slowApplies)
  123. prometheus.MustRegister(proposalsCommitted)
  124. prometheus.MustRegister(proposalsApplied)
  125. prometheus.MustRegister(proposalsPending)
  126. prometheus.MustRegister(proposalsFailed)
  127. prometheus.MustRegister(slowReadIndex)
  128. prometheus.MustRegister(readIndexFailed)
  129. prometheus.MustRegister(quotaBackendBytes)
  130. prometheus.MustRegister(currentVersion)
  131. prometheus.MustRegister(currentGoVersion)
  132. prometheus.MustRegister(serverID)
  133. currentVersion.With(prometheus.Labels{
  134. "server_version": version.Version,
  135. }).Set(1)
  136. currentGoVersion.With(prometheus.Labels{
  137. "server_go_version": goruntime.Version(),
  138. }).Set(1)
  139. }
  140. func monitorFileDescriptor(done <-chan struct{}) {
  141. ticker := time.NewTicker(5 * time.Second)
  142. defer ticker.Stop()
  143. for {
  144. used, err := runtime.FDUsage()
  145. if err != nil {
  146. plog.Errorf("cannot monitor file descriptor usage (%v)", err)
  147. return
  148. }
  149. limit, err := runtime.FDLimit()
  150. if err != nil {
  151. plog.Errorf("cannot monitor file descriptor usage (%v)", err)
  152. return
  153. }
  154. if used >= limit/5*4 {
  155. plog.Warningf("80%% of the file descriptor limit is used [used = %d, limit = %d]", used, limit)
  156. }
  157. select {
  158. case <-ticker.C:
  159. case <-done:
  160. return
  161. }
  162. }
  163. }