metrics.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. )
  30. func init() {
  31. prometheus.MustRegister(msgWriteDuration)
  32. }
  33. func reportSendingDuration(channel string, m raftpb.Message, duration time.Duration) {
  34. typ := m.Type.String()
  35. if isLinkHeartbeatMessage(m) {
  36. typ = "MsgLinkHeartbeat"
  37. }
  38. msgWriteDuration.WithLabelValues(channel, types.ID(m.To).String(), typ).Observe(float64(duration.Nanoseconds() / int64(time.Microsecond)))
  39. }