metrics.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. msgWriteDuration = prometheus.NewSummaryVec(
  23. prometheus.SummaryOpts{
  24. Name: "rafthttp_message_sending_latency_microseconds",
  25. Help: "message sending latency distributions.",
  26. },
  27. []string{"channel", "remoteID", "msgType"},
  28. )
  29. msgWriteFailed = prometheus.NewCounterVec(prometheus.CounterOpts{
  30. Name: "rafthttp_message_sent_failed_total",
  31. Help: "The total number of failed messages sent.",
  32. },
  33. []string{"channel", "remoteID", "msgType"},
  34. )
  35. )
  36. func init() {
  37. prometheus.MustRegister(msgWriteDuration)
  38. prometheus.MustRegister(msgWriteFailed)
  39. }
  40. func reportSendingDuration(channel string, m raftpb.Message, duration time.Duration) {
  41. typ := m.Type.String()
  42. if isLinkHeartbeatMessage(m) {
  43. typ = "MsgLinkHeartbeat"
  44. }
  45. msgWriteDuration.WithLabelValues(channel, types.ID(m.To).String(), typ).Observe(float64(duration.Nanoseconds() / int64(time.Microsecond)))
  46. }
  47. func reportMessageFailure(channel string, m raftpb.Message) {
  48. typ := m.Type.String()
  49. if isLinkHeartbeatMessage(m) {
  50. typ = "MsgLinkHeartbeat"
  51. }
  52. msgWriteFailed.WithLabelValues(channel, types.ID(m.To).String(), typ).Inc()
  53. }