metrics.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/pkg/types"
  18. "github.com/coreos/etcd/raft/raftpb"
  19. "github.com/prometheus/client_golang/prometheus"
  20. )
  21. var (
  22. msgSentDuration = prometheus.NewSummaryVec(
  23. prometheus.SummaryOpts{
  24. Namespace: "etcd",
  25. Subsystem: "rafthttp",
  26. Name: "message_sent_latency_microseconds",
  27. Help: "message sent latency distributions.",
  28. },
  29. []string{"sendingType", "remoteID", "msgType"},
  30. )
  31. msgSentFailed = prometheus.NewCounterVec(prometheus.CounterOpts{
  32. Namespace: "etcd",
  33. Subsystem: "rafthttp",
  34. Name: "message_sent_failed_total",
  35. Help: "The total number of failed messages sent.",
  36. },
  37. []string{"sendingType", "remoteID", "msgType"},
  38. )
  39. )
  40. func init() {
  41. prometheus.MustRegister(msgSentDuration)
  42. prometheus.MustRegister(msgSentFailed)
  43. }
  44. func reportSentDuration(sendingType string, m raftpb.Message, duration time.Duration) {
  45. typ := m.Type.String()
  46. if isLinkHeartbeatMessage(m) {
  47. typ = "MsgLinkHeartbeat"
  48. }
  49. msgSentDuration.WithLabelValues(sendingType, types.ID(m.To).String(), typ).Observe(float64(duration.Nanoseconds() / int64(time.Microsecond)))
  50. }
  51. func reportSentFailure(sendingType string, m raftpb.Message) {
  52. typ := m.Type.String()
  53. if isLinkHeartbeatMessage(m) {
  54. typ = "MsgLinkHeartbeat"
  55. }
  56. msgSentFailed.WithLabelValues(sendingType, types.ID(m.To).String(), typ).Inc()
  57. }