Commit 83e113fb authored by John Chase's avatar John Chase Committed by GitHub

op-node: Use RefMetrics and Event from op-service/metrics package (#7329)

* fix issue 6735

* delete NewEventLight

* deduplicate refmetrics, ensure only initialized metrics exist

---------
Co-authored-by: default avatarprotolambda <proto@protolambda.com>
parent ef469a9a
package metrics
import (
"fmt"
"time"
"github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/prometheus/client_golang/prometheus"
)
type EventMetrics struct {
Total prometheus.Counter
LastTime prometheus.Gauge
}
func (e *EventMetrics) RecordEvent() {
e.Total.Inc()
e.LastTime.Set(float64(time.Now().Unix()))
}
func NewEventMetrics(factory metrics.Factory, ns string, name string, displayName string) *EventMetrics {
return &EventMetrics{
Total: factory.NewCounter(prometheus.CounterOpts{
Namespace: ns,
Name: fmt.Sprintf("%s_total", name),
Help: fmt.Sprintf("Count of %s events", displayName),
}),
LastTime: factory.NewGauge(prometheus.GaugeOpts{
Namespace: ns,
Name: fmt.Sprintf("last_%s_unix", name),
Help: fmt.Sprintf("Timestamp of last %s event", displayName),
}),
}
}
This diff is collapsed.
...@@ -16,8 +16,8 @@ func (e *Event) Record() { ...@@ -16,8 +16,8 @@ func (e *Event) Record() {
e.LastTime.SetToCurrentTime() e.LastTime.SetToCurrentTime()
} }
func NewEvent(factory Factory, ns string, subsystem string, name string, displayName string) Event { func NewEvent(factory Factory, ns string, subsystem string, name string, displayName string) *Event {
return Event{ return &Event{
Total: factory.NewCounter(prometheus.CounterOpts{ Total: factory.NewCounter(prometheus.CounterOpts{
Namespace: ns, Namespace: ns,
Name: fmt.Sprintf("%s_total", name), Name: fmt.Sprintf("%s_total", name),
......
...@@ -27,7 +27,7 @@ type TxMetrics struct { ...@@ -27,7 +27,7 @@ type TxMetrics struct {
currentNonce prometheus.Gauge currentNonce prometheus.Gauge
pendingTxs prometheus.Gauge pendingTxs prometheus.Gauge
txPublishError *prometheus.CounterVec txPublishError *prometheus.CounterVec
publishEvent metrics.Event publishEvent *metrics.Event
confirmEvent metrics.EventVec confirmEvent metrics.EventVec
rpcError prometheus.Counter rpcError prometheus.Counter
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment