-
Notifications
You must be signed in to change notification settings - Fork 0
/
prometheus.go
78 lines (70 loc) · 2.07 KB
/
prometheus.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
package main
import (
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
const (
// Label keys and values.
httpCode = "code"
httpBody = "body"
outcome = "outcome"
success = "success"
// Our Prometheus namespace.
ns = "tokenizer"
)
// metrics contains Prometheus metrics for the components we use in production,
// i.e., the Web receiver, the IP address aggregator, the Crypto-PAn tokenizer,
// and the Kafka forwarder.
type metrics struct {
// The number of addresses and wallets that our address aggregator is
// currently waiting to flush.
numWallets prometheus.Gauge
numAddrs prometheus.Gauge
webResponses *prometheus.CounterVec
numForwarded *prometheus.CounterVec
numTokenized *prometheus.CounterVec
}
// failBecause turns the given error into a string that's ready to be used as a
// Prometheus label value, e.g., "foo crashed" is turned into "fail (foo
// crashed)".
func failBecause(err error) string {
return fmt.Sprintf("fail (%s)", err.Error())
}
// init initializes our Prometheus metrics.
func init() {
m.numWallets = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "num_wallets",
Help: "The number of wallets that the address aggregator currently stores",
})
m.numAddrs = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: "num_addrs",
Help: "The number of addresses that the address aggregator currently stores",
})
m.webResponses = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: ns,
Name: "web_responses",
Help: "HTTP responses of the Web receiver",
},
[]string{httpCode, httpBody},
)
m.numForwarded = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: ns,
Name: "num_forwarded",
Help: "(Un)successfully forwarded tokens using Kafka",
},
[]string{outcome},
)
m.numTokenized = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: ns,
Name: "num_tokenized",
Help: "Crypto-PAn's (un)successfully tokenize'd blobs",
},
[]string{outcome},
)
}