Skip to content

Commit

Permalink
swarm: export ipfs_p2p_peers_total metric
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Gierth committed Jun 25, 2015
1 parent 4dd5f7f commit f7b373f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions p2p/net/swarm/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,20 @@ import (
pst "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport"
psy "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream/transport/yamux"
context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
prom "github.com/prometheus/client_golang/prometheus"
)

var log = eventlog.Logger("swarm2")

var PSTransport pst.Transport

var peersTotal = prom.NewGauge(prom.GaugeOpts{
Namespace: "ipfs",
Subsystem: "p2p",
Name: "peers_total",
Help: "Number of connected peers",
})

func init() {
tpt := *psy.DefaultTransport
tpt.MaxStreamWindowSize = 512 * 1024
Expand Down Expand Up @@ -82,6 +90,8 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
s.cg.SetTeardown(s.teardown)
s.SetConnHandler(nil) // make sure to setup our own conn handler.

prom.MustRegister(peersTotal)

return s, s.listen(listenAddrs)
}

Expand Down Expand Up @@ -260,10 +270,12 @@ type ps2netNotifee struct {

func (n *ps2netNotifee) Connected(c *ps.Conn) {
n.not.Connected(n.net, inet.Conn((*Conn)(c)))
peersTotal.Inc()
}

func (n *ps2netNotifee) Disconnected(c *ps.Conn) {
n.not.Disconnected(n.net, inet.Conn((*Conn)(c)))
peersTotal.Dec()
}

func (n *ps2netNotifee) OpenedStream(s *ps.Stream) {
Expand Down

0 comments on commit f7b373f

Please sign in to comment.