From cb59c38964af480676f5ed1af032e3d0d9cee833 Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Wed, 23 May 2018 14:13:26 -0700 Subject: [PATCH] etcdserver/api/rafthttp: add "etcd_network_active_peers/disconnected_peers_total" Signed-off-by: Gyuho Lee --- etcdserver/api/rafthttp/metrics.go | 20 ++++++++++++++++++++ etcdserver/api/rafthttp/peer_status.go | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/etcdserver/api/rafthttp/metrics.go b/etcdserver/api/rafthttp/metrics.go index c63a082f6d5a..327be6232bf2 100644 --- a/etcdserver/api/rafthttp/metrics.go +++ b/etcdserver/api/rafthttp/metrics.go @@ -17,6 +17,24 @@ package rafthttp import "github.com/prometheus/client_golang/prometheus" var ( + activePeers = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: "etcd", + Subsystem: "network", + Name: "active_peers", + Help: "The current number of active peer connections.", + }, + []string{"ID"}, + ) + + disconnectedPeers = prometheus.NewCounterVec(prometheus.CounterOpts{ + Namespace: "etcd", + Subsystem: "network", + Name: "disconnected_peers_total", + Help: "The total number of disconnected peers.", + }, + []string{"ID"}, + ) + sentBytes = prometheus.NewCounterVec(prometheus.CounterOpts{ Namespace: "etcd", Subsystem: "network", @@ -68,6 +86,8 @@ var ( ) func init() { + prometheus.MustRegister(activePeers) + prometheus.MustRegister(disconnectedPeers) prometheus.MustRegister(sentBytes) prometheus.MustRegister(receivedBytes) prometheus.MustRegister(sentFailures) diff --git a/etcdserver/api/rafthttp/peer_status.go b/etcdserver/api/rafthttp/peer_status.go index 68d9ac01b5bb..4374299c6bae 100644 --- a/etcdserver/api/rafthttp/peer_status.go +++ b/etcdserver/api/rafthttp/peer_status.go @@ -53,6 +53,8 @@ func (s *peerStatus) activate() { } s.active = true s.since = time.Now() + + activePeers.WithLabelValues(s.id.String()).Inc() } } @@ -69,8 +71,12 @@ func (s *peerStatus) deactivate(failure failureType, reason string) { } s.active = false s.since = time.Time{} + + activePeers.WithLabelValues(s.id.String()).Dec() + disconnectedPeers.WithLabelValues(s.id.String()).Inc() return } + if s.lg != nil { s.lg.Debug("peer deactivated again", zap.String("peer-id", s.id.String()), zap.Error(errors.New(msg))) }