-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathmetrics.go
50 lines (41 loc) · 1.29 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
package metrics
import (
"github.com/ethereum-optimism/optimism/op-service/metrics"
opmetrics "github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/prometheus/client_golang/prometheus"
)
type BlockIdType string
var (
MetricsNamespace = "blob_api"
BlockIdTypeHash BlockIdType = "hash"
BlockIdTypeBeacon BlockIdType = "beacon"
BlockIdTypeInvalid BlockIdType = "invalid"
)
type Metricer interface {
Registry() *prometheus.Registry
RecordBlockIdType(t BlockIdType)
}
type metricsRecorder struct {
// blockIdType records the type of block id used to request a block. This could be a hash (BlockIdTypeHash), or a
// beacon block identifier (BlockIdTypeBeacon).
blockIdType *prometheus.CounterVec
registry *prometheus.Registry
}
func NewMetrics() Metricer {
registry := opmetrics.NewRegistry()
factory := metrics.With(registry)
return &metricsRecorder{
registry: registry,
blockIdType: factory.NewCounterVec(prometheus.CounterOpts{
Namespace: MetricsNamespace,
Name: "block_id_type",
Help: "The type of block id used to request a block",
}, []string{"type"}),
}
}
func (m *metricsRecorder) RecordBlockIdType(t BlockIdType) {
m.blockIdType.WithLabelValues(string(t)).Inc()
}
func (m *metricsRecorder) Registry() *prometheus.Registry {
return m.registry
}