-
Notifications
You must be signed in to change notification settings - Fork 533
/
metrics.go
39 lines (33 loc) · 1014 Bytes
/
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
package txpool
import (
"github.com/go-kit/kit/metrics"
"github.com/go-kit/kit/metrics/discard"
prometheus "github.com/go-kit/kit/metrics/prometheus"
stdprometheus "github.com/prometheus/client_golang/prometheus"
)
// Metrics represents the txpool metrics
type Metrics struct {
// Pending transactions
PendingTxs metrics.Gauge
}
// GetPrometheusMetrics return the txpool metrics instance
func GetPrometheusMetrics(namespace string, labelsWithValues ...string) *Metrics {
labels := []string{}
for i := 0; i < len(labelsWithValues); i += 2 {
labels = append(labels, labelsWithValues[i])
}
return &Metrics{
PendingTxs: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
Namespace: namespace,
Subsystem: "txpool",
Name: "pending_transactions",
Help: "Pending transactions in the pool",
}, labels).With(labelsWithValues...),
}
}
// NilMetrics will return the non operational txpool metrics
func NilMetrics() *Metrics {
return &Metrics{
PendingTxs: discard.NewGauge(),
}
}