Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
910ebfe9
Commit
910ebfe9
authored
Jun 23, 2015
by
Lars Gierth
Browse files
swarm: export ipfs_p2p_peers_total metric
License: MIT Signed-off-by:
Lars Gierth
<
larsg@systemli.org
>
parent
dae8ff49
Changes
1
Hide whitespace changes
Inline
Side-by-side
net/swarm/swarm.go
View file @
910ebfe9
...
...
@@ -19,6 +19,7 @@ import (
ps
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-peerstream"
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"
prom
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/prometheus/client_golang/prometheus"
context
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
)
...
...
@@ -26,6 +27,13 @@ var log = eventlog.Logger("swarm2")
var
PSTransport
pst
.
Transport
var
peersTotal
=
prom
.
NewGaugeVec
(
prom
.
GaugeOpts
{
Namespace
:
"ipfs"
,
Subsystem
:
"p2p"
,
Name
:
"peers_total"
,
Help
:
"Number of connected peers"
,
},
[]
string
{
"peer_id"
})
func
init
()
{
tpt
:=
*
psy
.
DefaultTransport
tpt
.
MaxStreamWindowSize
=
512
*
1024
...
...
@@ -82,6 +90,10 @@ func NewSwarm(ctx context.Context, listenAddrs []ma.Multiaddr,
s
.
cg
.
SetTeardown
(
s
.
teardown
)
s
.
SetConnHandler
(
nil
)
// make sure to setup our own conn handler.
// setup swarm metrics
prom
.
MustRegisterOrGet
(
peersTotal
)
s
.
Notify
((
*
metricsNotifiee
)(
s
))
return
s
,
s
.
listen
(
listenAddrs
)
}
...
...
@@ -273,3 +285,22 @@ func (n *ps2netNotifee) OpenedStream(s *ps.Stream) {
func
(
n
*
ps2netNotifee
)
ClosedStream
(
s
*
ps
.
Stream
)
{
n
.
not
.
ClosedStream
(
n
.
net
,
inet
.
Stream
((
*
Stream
)(
s
)))
}
type
metricsNotifiee
Swarm
func
(
nn
*
metricsNotifiee
)
Connected
(
n
inet
.
Network
,
v
inet
.
Conn
)
{
peersTotalGauge
(
n
.
LocalPeer
())
.
Inc
()
}
func
(
nn
*
metricsNotifiee
)
Disconnected
(
n
inet
.
Network
,
v
inet
.
Conn
)
{
peersTotalGauge
(
n
.
LocalPeer
())
.
Dec
()
}
func
(
nn
*
metricsNotifiee
)
OpenedStream
(
n
inet
.
Network
,
v
inet
.
Stream
)
{}
func
(
nn
*
metricsNotifiee
)
ClosedStream
(
n
inet
.
Network
,
v
inet
.
Stream
)
{}
func
(
nn
*
metricsNotifiee
)
Listen
(
n
inet
.
Network
,
a
ma
.
Multiaddr
)
{}
func
(
nn
*
metricsNotifiee
)
ListenClose
(
n
inet
.
Network
,
a
ma
.
Multiaddr
)
{}
func
peersTotalGauge
(
id
peer
.
ID
)
prom
.
Gauge
{
return
peersTotal
.
With
(
prom
.
Labels
{
"peer_id"
:
id
.
Pretty
()})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment