-
Notifications
You must be signed in to change notification settings - Fork 21
/
prometheus.go
78 lines (64 loc) · 2.31 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 metrics
import (
"strconv"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
sdk "github.com/wormhole-foundation/wormhole/sdk/vaa"
)
type PrometheusMetrics struct {
destinationTrxCount *prometheus.CounterVec
lastBlock *prometheus.GaugeVec
currentBlock *prometheus.GaugeVec
requestsTotal *prometheus.CounterVec
}
// NewPrometheusMetrics returns a new instance of PrometheusMetrics.
func NewPrometheusMetrics(environment string) *PrometheusMetrics {
constLabels := map[string]string{
"environment": environment,
"service": serviceName,
}
destinationTrxCount := promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "destination_tx_count_by_chain",
Help: "Total number of destination trx by chain",
ConstLabels: constLabels,
}, []string{"chain"})
lastBlock := promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "last_block_by_chain",
Help: "Last block number by chain",
ConstLabels: constLabels,
}, []string{"chain"})
currentBlock := promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "current_block_by_chain",
Help: "Current block number by chain",
ConstLabels: constLabels,
}, []string{"chain"})
requestsTotal := promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "rpc_requests_total_by_chain",
Help: "Count all http requests by status code, method and path.",
ConstLabels: constLabels,
},
[]string{"client", "operation", "status_code"},
)
return &PrometheusMetrics{
lastBlock: lastBlock,
currentBlock: currentBlock,
destinationTrxCount: destinationTrxCount,
requestsTotal: requestsTotal,
}
}
func (m *PrometheusMetrics) SetLastBlock(chain sdk.ChainID, block uint64) {
m.lastBlock.WithLabelValues(chain.String()).Set(float64(block))
}
func (m *PrometheusMetrics) SetCurrentBlock(chain sdk.ChainID, block uint64) {
m.currentBlock.WithLabelValues(chain.String()).Set(float64(block))
}
func (m *PrometheusMetrics) IncDestinationTrxSaved(chain sdk.ChainID) {
m.destinationTrxCount.WithLabelValues(chain.String()).Inc()
}
func (m *PrometheusMetrics) IncRpcRequest(client string, operation string, statusCode int) {
m.requestsTotal.WithLabelValues(client, operation, strconv.Itoa(statusCode)).Inc()
}