Skip to content

Commit

Permalink
etcdserver/api/rafthttp: add "etcd_network_active_peers/disconnected_…
Browse files Browse the repository at this point in the history
…peers_total"

Signed-off-by: Gyuho Lee <[email protected]>
  • Loading branch information
gyuho committed May 23, 2018
1 parent 1a102fb commit cb59c38
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions etcdserver/api/rafthttp/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -68,6 +86,8 @@ var (
)

func init() {
prometheus.MustRegister(activePeers)
prometheus.MustRegister(disconnectedPeers)
prometheus.MustRegister(sentBytes)
prometheus.MustRegister(receivedBytes)
prometheus.MustRegister(sentFailures)
Expand Down
6 changes: 6 additions & 0 deletions etcdserver/api/rafthttp/peer_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func (s *peerStatus) activate() {
}
s.active = true
s.since = time.Now()

activePeers.WithLabelValues(s.id.String()).Inc()
}
}

Expand All @@ -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)))
}
Expand Down

0 comments on commit cb59c38

Please sign in to comment.