metrics.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 rafthttp
  15. import (
  16. "time"
  17. "github.com/coreos/etcd/Godeps/_workspace/src/github.com/prometheus/client_golang/prometheus"
  18. "github.com/coreos/etcd/pkg/types"
  19. "github.com/coreos/etcd/raft/raftpb"
  20. )
  21. var (
  22. // TODO: create a separate histogram for recording
  23. // snapshot sending metric. snapshot can be large and
  24. // take a long time to send. So it needs a different
  25. // time range than other type of messages.
  26. msgSentDuration = prometheus.NewHistogramVec(
  27. prometheus.HistogramOpts{
  28. Namespace: "etcd",
  29. Subsystem: "rafthttp",
  30. Name: "message_sent_latency_seconds",
  31. Help: "message sent latency distributions.",
  32. Buckets: prometheus.ExponentialBuckets(0.0005, 2, 13),
  33. },
  34. []string{"sendingType", "remoteID", "msgType"},
  35. )
  36. msgSentFailed = prometheus.NewCounterVec(prometheus.CounterOpts{
  37. Namespace: "etcd",
  38. Subsystem: "rafthttp",
  39. Name: "message_sent_failed_total",
  40. Help: "The total number of failed messages sent.",
  41. },
  42. []string{"sendingType", "remoteID", "msgType"},
  43. )
  44. )
  45. func init() {
  46. prometheus.MustRegister(msgSentDuration)
  47. prometheus.MustRegister(msgSentFailed)
  48. }
  49. func reportSentDuration(sendingType string, m raftpb.Message, duration time.Duration) {
  50. typ := m.Type.String()
  51. if isLinkHeartbeatMessage(m) {
  52. typ = "MsgLinkHeartbeat"
  53. }
  54. msgSentDuration.WithLabelValues(sendingType, types.ID(m.To).String(), typ).Observe(float64(duration) / float64(time.Second))
  55. }
  56. func reportSentFailure(sendingType string, m raftpb.Message) {
  57. typ := m.Type.String()
  58. if isLinkHeartbeatMessage(m) {
  59. typ = "MsgLinkHeartbeat"
  60. }
  61. msgSentFailed.WithLabelValues(sendingType, types.ID(m.To).String(), typ).Inc()
  62. }