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
f0146103
Commit
f0146103
authored
May 18, 2016
by
Jeromy Johnson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2728 from ipfs/peers-total-by-transport
metrics: add transport label to p2p_peers_total
parents
cc822af1
05cb7a1b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
11 deletions
+25
-11
core/corehttp/metrics.go
core/corehttp/metrics.go
+19
-8
core/corehttp/metrics_test.go
core/corehttp/metrics_test.go
+6
-3
No files found.
core/corehttp/metrics.go
View file @
f0146103
...
@@ -29,7 +29,7 @@ func MetricsCollectionOption(handlerName string) ServeOption {
...
@@ -29,7 +29,7 @@ func MetricsCollectionOption(handlerName string) ServeOption {
var
(
var
(
peersTotalMetric
=
prometheus
.
NewDesc
(
peersTotalMetric
=
prometheus
.
NewDesc
(
prometheus
.
BuildFQName
(
"ipfs"
,
"p2p"
,
"peers_total"
),
prometheus
.
BuildFQName
(
"ipfs"
,
"p2p"
,
"peers_total"
),
"Number of connected peers"
,
nil
,
nil
)
"Number of connected peers"
,
[]
string
{
"transport"
}
,
nil
)
)
)
type
IpfsNodeCollector
struct
{
type
IpfsNodeCollector
struct
{
...
@@ -41,13 +41,24 @@ func (_ IpfsNodeCollector) Describe(ch chan<- *prometheus.Desc) {
...
@@ -41,13 +41,24 @@ func (_ IpfsNodeCollector) Describe(ch chan<- *prometheus.Desc) {
}
}
func
(
c
IpfsNodeCollector
)
Collect
(
ch
chan
<-
prometheus
.
Metric
)
{
func
(
c
IpfsNodeCollector
)
Collect
(
ch
chan
<-
prometheus
.
Metric
)
{
ch
<-
prometheus
.
MustNewConstMetric
(
for
tr
,
val
:=
range
c
.
PeersTotalValues
()
{
peersTotalMetric
,
ch
<-
prometheus
.
MustNewConstMetric
(
prometheus
.
GaugeValue
,
peersTotalMetric
,
c
.
PeersTotalValue
(),
prometheus
.
GaugeValue
,
)
val
,
tr
,
)
}
}
}
func
(
c
IpfsNodeCollector
)
PeersTotalValue
()
float64
{
func
(
c
IpfsNodeCollector
)
PeersTotalValues
()
map
[
string
]
float64
{
return
float64
(
len
(
c
.
Node
.
PeerHost
.
Network
()
.
Conns
()))
vals
:=
make
(
map
[
string
]
float64
)
for
_
,
conn
:=
range
c
.
Node
.
PeerHost
.
Network
()
.
Conns
()
{
tr
:=
""
for
_
,
proto
:=
range
conn
.
RemoteMultiaddr
()
.
Protocols
()
{
tr
=
tr
+
"/"
+
proto
.
Name
}
vals
[
tr
]
=
vals
[
tr
]
+
1
}
return
vals
}
}
core/corehttp/metrics_test.go
View file @
f0146103
...
@@ -39,8 +39,11 @@ func TestPeersTotal(t *testing.T) {
...
@@ -39,8 +39,11 @@ func TestPeersTotal(t *testing.T) {
node
:=
&
core
.
IpfsNode
{
PeerHost
:
hosts
[
0
]}
node
:=
&
core
.
IpfsNode
{
PeerHost
:
hosts
[
0
]}
collector
:=
IpfsNodeCollector
{
Node
:
node
}
collector
:=
IpfsNodeCollector
{
Node
:
node
}
actual
:=
collector
.
PeersTotalValue
()
actual
:=
collector
.
PeersTotalValues
()
if
actual
!=
3
{
if
len
(
actual
)
!=
1
{
t
.
Fatalf
(
"expected 3 peers, got %d"
,
int
(
actual
))
t
.
Fatalf
(
"expected 1 peers transport, got %d"
,
len
(
actual
))
}
if
actual
[
"/ip4/tcp"
]
!=
float64
(
3
)
{
t
.
Fatalf
(
"expected 3 peers, got %s"
,
actual
[
"/ip4/tcp"
])
}
}
}
}
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