Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
8b164f9e
Commit
8b164f9e
authored
9 years ago
by
Lars Gierth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
swarm: export ipfs_p2p_peers_total metric
License: MIT Signed-off-by:
Lars Gierth
<
larsg@systemli.org
>
parent
ed8d3ae3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
0 deletions
+31
-0
p2p/net/swarm/swarm.go
p2p/net/swarm/swarm.go
+31
-0
No files found.
p2p/net/swarm/swarm.go
View file @
8b164f9e
...
...
@@ -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
()})
}
This diff is collapsed.
Click to expand it.
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