metrics.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2015 CoreOS, Inc.
  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/Godeps/_workspace/src/github.com/prometheus/client_golang/prometheus"
  18. "github.com/coreos/etcd/pkg/runtime"
  19. )
  20. var (
  21. // TODO: with label in v3?
  22. proposeDurations = prometheus.NewSummary(prometheus.SummaryOpts{
  23. Namespace: "etcd",
  24. Subsystem: "server",
  25. Name: "proposal_durations_milliseconds",
  26. Help: "The latency distributions of committing proposal.",
  27. })
  28. proposePending = prometheus.NewGauge(prometheus.GaugeOpts{
  29. Namespace: "etcd",
  30. Subsystem: "server",
  31. Name: "pending_proposal_total",
  32. Help: "The total number of pending proposals.",
  33. })
  34. // This is number of proposal failed in client's view.
  35. // The proposal might be later got committed in raft.
  36. proposeFailed = prometheus.NewCounter(prometheus.CounterOpts{
  37. Namespace: "etcd",
  38. Subsystem: "server",
  39. Name: "proposal_failed_total",
  40. Help: "The total number of failed proposals.",
  41. })
  42. fileDescriptorUsed = prometheus.NewGauge(prometheus.GaugeOpts{
  43. Namespace: "etcd",
  44. Subsystem: "server",
  45. Name: "file_descriptors_used_total",
  46. Help: "The total number of file descriptors used.",
  47. })
  48. )
  49. func init() {
  50. prometheus.MustRegister(proposeDurations)
  51. prometheus.MustRegister(proposePending)
  52. prometheus.MustRegister(proposeFailed)
  53. prometheus.MustRegister(fileDescriptorUsed)
  54. }
  55. func monitorFileDescriptor(done <-chan struct{}) {
  56. ticker := time.NewTicker(5 * time.Second)
  57. defer ticker.Stop()
  58. for {
  59. used, err := runtime.FDUsage()
  60. if err != nil {
  61. plog.Errorf("cannot monitor file descriptor usage (%v)", err)
  62. return
  63. }
  64. fileDescriptorUsed.Set(float64(used))
  65. limit, err := runtime.FDLimit()
  66. if err != nil {
  67. plog.Errorf("cannot monitor file descriptor usage (%v)", err)
  68. return
  69. }
  70. if used >= limit/5*4 {
  71. plog.Warningf("80%% of the file descriptor limit is used [used = %d, limit = %d]", used, limit)
  72. }
  73. select {
  74. case <-ticker.C:
  75. case <-done:
  76. return
  77. }
  78. }
  79. }