-
Notifications
You must be signed in to change notification settings - Fork 2
/
metrics.go
139 lines (133 loc) · 5.25 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright 2021 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 kademlia
import (
m "github.com/ethsana/sana/pkg/metrics"
"github.com/prometheus/client_golang/prometheus"
)
// metrics groups kademlia related prometheus counters.
type metrics struct {
PickCalls prometheus.Counter
PickCallsFalse prometheus.Counter
CurrentDepth prometheus.Gauge
CurrentRadius prometheus.Gauge
CurrentlyKnownPeers prometheus.Gauge
CurrentlyConnectedPeers prometheus.Gauge
InternalMetricsFlushTime prometheus.Histogram
InternalMetricsFlushTotalErrors prometheus.Counter
TotalBeforeExpireWaits prometheus.Counter
TotalInboundConnections prometheus.Counter
TotalInboundDisconnections prometheus.Counter
TotalOutboundConnections prometheus.Counter
TotalOutboundConnectionAttempts prometheus.Counter
TotalOutboundConnectionFailedAttempts prometheus.Counter
TotalBootNodesConnectionAttempts prometheus.Counter
StartAddAddressBookOverlaysTime prometheus.Histogram
}
// newMetrics is a convenient constructor for creating new metrics.
func newMetrics() metrics {
const subsystem = "kademlia"
return metrics{
PickCalls: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "pick_calls",
Help: "The number of pick method call made.",
}),
PickCallsFalse: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "pick_calls_false",
Help: "The number of pick method call made which returned false.",
}),
CurrentDepth: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "current_depth",
Help: "The current value of depth.",
}),
CurrentRadius: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "current_radius",
Help: "The current value of radius.",
}),
CurrentlyKnownPeers: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "currently_known_peers",
Help: "Number of currently known peers.",
}),
CurrentlyConnectedPeers: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "currently_connected_peers",
Help: "Number of currently connected peers.",
}),
InternalMetricsFlushTime: prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "internal_metrics_flush_time",
Help: "The time spent flushing the internal metrics about peers to the state-store.",
}),
InternalMetricsFlushTotalErrors: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "internal_metrics_flush_total_errors",
Help: "Number of total errors occurred during flushing the internal metrics to the state-store.",
}),
TotalBeforeExpireWaits: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_before_expire_waits",
Help: "Total before expire waits made.",
}),
TotalInboundConnections: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_inbound_connections",
Help: "Total inbound connections made.",
}),
TotalInboundDisconnections: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_inbound_disconnections",
Help: "Total inbound disconnections made.",
}),
TotalOutboundConnections: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_outbound_connections",
Help: "Total outbound connections made.",
}),
TotalOutboundConnectionAttempts: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_outbound_connection_attempts",
Help: "Total outbound connection attempts made.",
}),
TotalOutboundConnectionFailedAttempts: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_outbound_connection_failed_attempts",
Help: "Total outbound connection failed attempts made.",
}),
TotalBootNodesConnectionAttempts: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_bootnodes_connection_attempts",
Help: "Total boot-nodes connection attempts made.",
}),
StartAddAddressBookOverlaysTime: prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "start_add_addressbook_overlays_time",
Help: "The time spent adding overlays peers from addressbook on kademlia start.",
}),
}
}
// Metrics returns set of prometheus collectors.
func (k *Kad) Metrics() []prometheus.Collector {
return m.PrometheusCollectorsFromFields(k.metrics)
}