-
Notifications
You must be signed in to change notification settings - Fork 338
/
metrics.go
69 lines (63 loc) · 2.34 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
// 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 accounting
import (
m "github.com/ethersphere/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
TotalDebitedAmount prometheus.Counter
TotalCreditedAmount prometheus.Counter
DebitEventsCount prometheus.Counter
CreditEventsCount prometheus.Counter
AccountingDisconnectsCount prometheus.Counter
AccountingBlocksCount prometheus.Counter
}
func newMetrics() metrics {
subsystem := "accounting"
return metrics{
TotalDebitedAmount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_debited_amount",
Help: "Amount of BZZ debited to peers (potential income of the node)",
}),
TotalCreditedAmount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "total_credited_amount",
Help: "Amount of BZZ credited to peers (potential cost of the node)",
}),
DebitEventsCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "debit_events_count",
Help: "Number of occurrences of BZZ debit events towards peers",
}),
CreditEventsCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "credit_events_count",
Help: "Number of occurrences of BZZ credit events towards peers",
}),
AccountingDisconnectsCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "accounting_disconnects_count",
Help: "Number of occurrences of peers disconnected based on payment thresholds",
}),
AccountingBlocksCount: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: m.Namespace,
Subsystem: subsystem,
Name: "accounting_blocks_count",
Help: "Number of occurrences of temporarily skipping a peer to avoid crossing their disconnect thresholds",
}),
}
}
func (a *Accounting) Metrics() []prometheus.Collector {
return m.PrometheusCollectorsFromFields(a.metrics)
}