Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
31381401
Commit
31381401
authored
Jan 22, 2020
by
Janos Guljas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add libp2p metrics for connections and streams
parent
72bd3f60
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
5 deletions
+59
-5
start.go
cmd/bee/cmd/start.go
+1
-0
libp2p.go
pkg/p2p/libp2p/libp2p.go
+17
-5
metrics.go
pkg/p2p/libp2p/metrics.go
+41
-0
No files found.
cmd/bee/cmd/start.go
View file @
31381401
...
@@ -99,6 +99,7 @@ func (c *command) initStartCmd() (err error) {
...
@@ -99,6 +99,7 @@ func (c *command) initStartCmd() (err error) {
// Debug API server
// Debug API server
debugAPIService
:=
debugapi
.
New
(
debugapi
.
Options
{})
debugAPIService
:=
debugapi
.
New
(
debugapi
.
Options
{})
// register metrics from components
// register metrics from components
debugAPIService
.
MustRegisterMetrics
(
p2ps
.
Metrics
()
...
)
debugAPIService
.
MustRegisterMetrics
(
pingPong
.
Metrics
()
...
)
debugAPIService
.
MustRegisterMetrics
(
pingPong
.
Metrics
()
...
)
debugAPIService
.
MustRegisterMetrics
(
apiService
.
Metrics
()
...
)
debugAPIService
.
MustRegisterMetrics
(
apiService
.
Metrics
()
...
)
...
...
pkg/p2p/libp2p/libp2p.go
View file @
31381401
...
@@ -27,6 +27,7 @@ var _ p2p.Service = new(Service)
...
@@ -27,6 +27,7 @@ var _ p2p.Service = new(Service)
type
Service
struct
{
type
Service
struct
{
host
host
.
Host
host
host
.
Host
metrics
metrics
}
}
type
Options
struct
{
type
Options
struct
{
...
@@ -129,7 +130,10 @@ func New(ctx context.Context, o Options) (*Service, error) {
...
@@ -129,7 +130,10 @@ func New(ctx context.Context, o Options) (*Service, error) {
return
nil
,
fmt
.
Errorf
(
"autonat: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"autonat: %w"
,
err
)
}
}
s
:=
&
Service
{
host
:
h
}
s
:=
&
Service
{
host
:
h
,
metrics
:
newMetrics
(),
}
// TODO: be more resilient on connection errors and connect in parallel
// TODO: be more resilient on connection errors and connect in parallel
for
_
,
a
:=
range
o
.
Bootnodes
{
for
_
,
a
:=
range
o
.
Bootnodes
{
...
@@ -143,6 +147,10 @@ func New(ctx context.Context, o Options) (*Service, error) {
...
@@ -143,6 +147,10 @@ func New(ctx context.Context, o Options) (*Service, error) {
}
}
}
}
h
.
Network
()
.
SetConnHandler
(
func
(
_
network
.
Conn
)
{
s
.
metrics
.
HandledConnectionCount
.
Inc
()
})
return
s
,
nil
return
s
,
nil
}
}
...
@@ -153,10 +161,11 @@ func (s *Service) AddProtocol(p p2p.ProtocolSpec) (err error) {
...
@@ -153,10 +161,11 @@ func (s *Service) AddProtocol(p p2p.ProtocolSpec) (err error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"match semver %s: %w"
,
id
,
err
)
return
fmt
.
Errorf
(
"match semver %s: %w"
,
id
,
err
)
}
}
s
.
host
.
SetStreamHandlerMatch
(
id
,
matcher
,
func
(
s
network
.
Stream
)
{
s
.
host
.
SetStreamHandlerMatch
(
id
,
matcher
,
func
(
stream
network
.
Stream
)
{
s
.
metrics
.
HandledStreamCount
.
Inc
()
ss
.
Handler
(
p2p
.
Peer
{
ss
.
Handler
(
p2p
.
Peer
{
Addr
:
s
.
Conn
()
.
RemoteMultiaddr
(),
Addr
:
s
tream
.
Conn
()
.
RemoteMultiaddr
(),
Stream
:
s
,
Stream
:
s
tream
,
})
})
})
})
}
}
...
@@ -189,6 +198,8 @@ func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (peerID string
...
@@ -189,6 +198,8 @@ func (s *Service) Connect(ctx context.Context, addr ma.Multiaddr) (peerID string
return
""
,
err
return
""
,
err
}
}
s
.
metrics
.
CreatedConnectionCount
.
Inc
()
return
info
.
ID
.
String
(),
nil
return
info
.
ID
.
String
(),
nil
}
}
...
@@ -205,6 +216,7 @@ func (s *Service) NewStream(ctx context.Context, peerID, protocolName, streamNam
...
@@ -205,6 +216,7 @@ func (s *Service) NewStream(ctx context.Context, peerID, protocolName, streamNam
}
}
return
nil
,
fmt
.
Errorf
(
"create stream %q to %q: %w"
,
swarmStreamName
,
peerID
,
err
)
return
nil
,
fmt
.
Errorf
(
"create stream %q to %q: %w"
,
swarmStreamName
,
peerID
,
err
)
}
}
s
.
metrics
.
CreatedStreamCount
.
Inc
()
return
st
,
nil
return
st
,
nil
}
}
...
...
pkg/p2p/libp2p/metrics.go
0 → 100644
View file @
31381401
package
libp2p
import
(
m
"github.com/janos/bee/pkg/metrics"
"github.com/prometheus/client_golang/prometheus"
)
type
metrics
struct
{
// all metrics fields must be exported
// to be able to return them by Metrics()
// using reflection
CreatedConnectionCount
prometheus
.
Counter
HandledConnectionCount
prometheus
.
Counter
CreatedStreamCount
prometheus
.
Counter
HandledStreamCount
prometheus
.
Counter
}
func
newMetrics
()
(
m
metrics
)
{
return
metrics
{
CreatedConnectionCount
:
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"libp2p_created_connection_count"
,
Help
:
"Number of initiated outgoing libp2p connections."
,
}),
HandledConnectionCount
:
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"libp2p_handled_connection_count"
,
Help
:
"Number of handled incoming libp2p connections."
,
}),
CreatedStreamCount
:
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"libp2p_created_stream_count"
,
Help
:
"Number of initiated outgoing libp2p streams."
,
}),
HandledStreamCount
:
prometheus
.
NewCounter
(
prometheus
.
CounterOpts
{
Name
:
"libp2p_handled_stream_count"
,
Help
:
"Number of handled incoming libp2p streams."
,
}),
}
}
func
(
s
*
Service
)
Metrics
()
[]
prometheus
.
Collector
{
return
m
.
PrometheusCollectorsFromFields
(
s
.
metrics
)
}
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