/
metrics.go
executable file
·83 lines (77 loc) · 2.76 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package libp2p
import (
"github.com/prometheus/client_golang/prometheus"
m "github.com/yanhuangpai/ifi-bee/pkg/metrics"
)
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
BlocklistedPeerCount prometheus.Counter
BlocklistedPeerErrCount prometheus.Counter
DisconnectCount prometheus.Counter
ConnectBreakerCount prometheus.Counter
}
func newMetrics() metrics {
subsystem := "libp2p"
return metrics{
CreatedConnectionCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "created_connection_count",
Help: "Number of initiated outgoing libp2p connections.",
}),
HandledConnectionCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "handled_connection_count",
Help: "Number of handled incoming libp2p connections.",
}),
CreatedStreamCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "created_stream_count",
Help: "Number of initiated outgoing libp2p streams.",
}),
HandledStreamCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "handled_stream_count",
Help: "Number of handled incoming libp2p streams.",
}),
BlocklistedPeerCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "blocklisted_peer_count",
Help: "Number of peers we've blocklisted.",
}),
BlocklistedPeerErrCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "blocklisted_peer_err_count",
Help: "Number of peers we've been unable to blocklist.",
}),
DisconnectCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "disconnect_count",
Help: "Number of peers we've disconnected from (initiated locally).",
}),
ConnectBreakerCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "connect_breaker_count",
Help: "Number of times we got a closed breaker while connecting to another peer.",
}),
}
}
func (s *Service) Metrics() []prometheus.Collector {
return m.PrometheusCollectorsFromFields(s.metrics)
}