Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
23db9514
Commit
23db9514
authored
Jan 14, 2023
by
Matthew Slipper
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-node: Document metrics
parent
64cc5197
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
241 additions
and
43 deletions
+241
-43
cmd.go
op-node/cmd/doc/cmd.go
+54
-0
main.go
op-node/cmd/main.go
+6
-0
go.mod
op-node/go.mod
+1
-1
caching.go
op-node/metrics/caching.go
+5
-5
events.go
op-node/metrics/events.go
+5
-4
metrics.go
op-node/metrics/metrics.go
+46
-33
factory.go
op-service/metrics/factory.go
+124
-0
No files found.
op-node/cmd/doc/cmd.go
0 → 100644
View file @
23db9514
package
doc
import
(
"encoding/json"
"fmt"
"os"
"strings"
"github.com/ethereum-optimism/optimism/op-node/metrics"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli"
)
var
Subcommands
=
cli
.
Commands
{
{
Name
:
"metrics"
,
Usage
:
"Dumps a list of supported metrics to stdout"
,
Flags
:
[]
cli
.
Flag
{
cli
.
StringFlag
{
Name
:
"format"
,
Value
:
"markdown"
,
Usage
:
"Output format (json|markdown)"
,
},
},
Action
:
func
(
ctx
*
cli
.
Context
)
error
{
m
:=
metrics
.
NewMetrics
(
"default"
)
supportedMetrics
:=
m
.
Document
()
format
:=
ctx
.
String
(
"format"
)
if
format
!=
"markdown"
&&
format
!=
"json"
{
return
fmt
.
Errorf
(
"invalid format: %s"
,
format
)
}
if
format
==
"json"
{
enc
:=
json
.
NewEncoder
(
os
.
Stdout
)
return
enc
.
Encode
(
supportedMetrics
)
}
table
:=
tablewriter
.
NewWriter
(
os
.
Stdout
)
table
.
SetBorders
(
tablewriter
.
Border
{
Left
:
true
,
Top
:
false
,
Right
:
true
,
Bottom
:
false
})
table
.
SetCenterSeparator
(
"|"
)
table
.
SetAutoWrapText
(
false
)
table
.
SetHeader
([]
string
{
"Metric"
,
"Description"
,
"Labels"
,
"Type"
})
var
data
[][]
string
for
_
,
metric
:=
range
supportedMetrics
{
labels
:=
strings
.
Join
(
metric
.
Labels
,
","
)
data
=
append
(
data
,
[]
string
{
metric
.
Name
,
metric
.
Help
,
labels
,
metric
.
Type
})
}
table
.
AppendBulk
(
data
)
table
.
Render
()
return
nil
},
},
}
op-node/cmd/main.go
View file @
23db9514
...
@@ -9,6 +9,8 @@ import (
...
@@ -9,6 +9,8 @@ import (
"syscall"
"syscall"
"time"
"time"
"github.com/ethereum-optimism/optimism/op-node/cmd/doc"
"github.com/urfave/cli"
"github.com/urfave/cli"
opnode
"github.com/ethereum-optimism/optimism/op-node"
opnode
"github.com/ethereum-optimism/optimism/op-node"
...
@@ -68,6 +70,10 @@ func main() {
...
@@ -68,6 +70,10 @@ func main() {
Name
:
"genesis"
,
Name
:
"genesis"
,
Subcommands
:
genesis
.
Subcommands
,
Subcommands
:
genesis
.
Subcommands
,
},
},
{
Name
:
"doc"
,
Subcommands
:
doc
.
Subcommands
,
},
}
}
err
:=
app
.
Run
(
os
.
Args
)
err
:=
app
.
Run
(
os
.
Args
)
...
...
op-node/go.mod
View file @
23db9514
...
@@ -23,6 +23,7 @@ require (
...
@@ -23,6 +23,7 @@ require (
github.com/libp2p/go-libp2p-testing v0.12.0
github.com/libp2p/go-libp2p-testing v0.12.0
github.com/multiformats/go-multiaddr v0.7.0
github.com/multiformats/go-multiaddr v0.7.0
github.com/multiformats/go-multiaddr-dns v0.3.1
github.com/multiformats/go-multiaddr-dns v0.3.1
github.com/olekukonko/tablewriter v0.0.5
github.com/prometheus/client_golang v1.13.0
github.com/prometheus/client_golang v1.13.0
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.1
github.com/urfave/cli v1.22.9
github.com/urfave/cli v1.22.9
...
@@ -115,7 +116,6 @@ require (
...
@@ -115,7 +116,6 @@ require (
github.com/multiformats/go-multistream v0.3.3 // indirect
github.com/multiformats/go-multistream v0.3.3 // indirect
github.com/multiformats/go-varint v0.0.6 // indirect
github.com/multiformats/go-varint v0.0.6 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
...
...
op-node/metrics/caching.go
View file @
23db9514
package
metrics
package
metrics
import
(
import
(
"github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
)
// CacheMetrics implements the Metrics interface in the caching package,
// CacheMetrics implements the Metrics interface in the caching package,
...
@@ -34,16 +34,16 @@ func (m *CacheMetrics) CacheGet(typeLabel string, hit bool) {
...
@@ -34,16 +34,16 @@ func (m *CacheMetrics) CacheGet(typeLabel string, hit bool) {
}
}
}
}
func
NewCacheMetrics
(
registry
prometheus
.
Registerer
,
ns
string
,
name
string
,
displayName
string
)
*
CacheMetrics
{
func
NewCacheMetrics
(
factory
metrics
.
Factory
,
ns
string
,
name
string
,
displayName
string
)
*
CacheMetrics
{
return
&
CacheMetrics
{
return
&
CacheMetrics
{
SizeVec
:
promauto
.
With
(
registry
)
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
SizeVec
:
factory
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
name
+
"_size"
,
Name
:
name
+
"_size"
,
Help
:
displayName
+
" cache size"
,
Help
:
displayName
+
" cache size"
,
},
[]
string
{
},
[]
string
{
"type"
,
"type"
,
}),
}),
GetVec
:
promauto
.
With
(
registry
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
GetVec
:
factory
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
name
+
"_get"
,
Name
:
name
+
"_get"
,
Help
:
displayName
+
" lookups, hitting or not"
,
Help
:
displayName
+
" lookups, hitting or not"
,
...
@@ -51,7 +51,7 @@ func NewCacheMetrics(registry prometheus.Registerer, ns string, name string, dis
...
@@ -51,7 +51,7 @@ func NewCacheMetrics(registry prometheus.Registerer, ns string, name string, dis
"type"
,
"type"
,
"hit"
,
"hit"
,
}),
}),
AddVec
:
promauto
.
With
(
registry
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
AddVec
:
factory
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
name
+
"_add"
,
Name
:
name
+
"_add"
,
Help
:
displayName
+
" additions, evicting previous values or not"
,
Help
:
displayName
+
" additions, evicting previous values or not"
,
...
...
op-node/metrics/events.go
View file @
23db9514
...
@@ -4,8 +4,9 @@ import (
...
@@ -4,8 +4,9 @@ import (
"fmt"
"fmt"
"time"
"time"
"github.com/ethereum-optimism/optimism/op-service/metrics"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
)
type
EventMetrics
struct
{
type
EventMetrics
struct
{
...
@@ -18,14 +19,14 @@ func (e *EventMetrics) RecordEvent() {
...
@@ -18,14 +19,14 @@ func (e *EventMetrics) RecordEvent() {
e
.
LastTime
.
Set
(
float64
(
time
.
Now
()
.
Unix
()))
e
.
LastTime
.
Set
(
float64
(
time
.
Now
()
.
Unix
()))
}
}
func
NewEventMetrics
(
registry
prometheus
.
Registerer
,
ns
string
,
name
string
,
displayName
string
)
*
EventMetrics
{
func
NewEventMetrics
(
factory
metrics
.
Factory
,
ns
string
,
name
string
,
displayName
string
)
*
EventMetrics
{
return
&
EventMetrics
{
return
&
EventMetrics
{
Total
:
promauto
.
With
(
registry
)
.
NewCounter
(
prometheus
.
CounterOpts
{
Total
:
factory
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
fmt
.
Sprintf
(
"%s_total"
,
name
),
Name
:
fmt
.
Sprintf
(
"%s_total"
,
name
),
Help
:
fmt
.
Sprintf
(
"Count of %s events"
,
displayName
),
Help
:
fmt
.
Sprintf
(
"Count of %s events"
,
displayName
),
}),
}),
LastTime
:
promauto
.
With
(
registry
)
.
NewGauge
(
prometheus
.
GaugeOpts
{
LastTime
:
factory
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
fmt
.
Sprintf
(
"last_%s_unix"
,
name
),
Name
:
fmt
.
Sprintf
(
"last_%s_unix"
,
name
),
Help
:
fmt
.
Sprintf
(
"Timestamp of last %s event"
,
displayName
),
Help
:
fmt
.
Sprintf
(
"Timestamp of last %s event"
,
displayName
),
...
...
op-node/metrics/metrics.go
View file @
23db9514
...
@@ -10,11 +10,12 @@ import (
...
@@ -10,11 +10,12 @@ import (
"strconv"
"strconv"
"time"
"time"
"github.com/ethereum-optimism/optimism/op-service/metrics"
pb
"github.com/libp2p/go-libp2p-pubsub/pb"
pb
"github.com/libp2p/go-libp2p-pubsub/pb"
libp2pmetrics
"github.com/libp2p/go-libp2p/core/metrics"
libp2pmetrics
"github.com/libp2p/go-libp2p/core/metrics"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum"
...
@@ -59,6 +60,7 @@ type Metricer interface {
...
@@ -59,6 +60,7 @@ type Metricer interface {
RecordBandwidth
(
ctx
context
.
Context
,
bwc
*
libp2pmetrics
.
BandwidthCounter
)
RecordBandwidth
(
ctx
context
.
Context
,
bwc
*
libp2pmetrics
.
BandwidthCounter
)
RecordSequencerBuildingDiffTime
(
duration
time
.
Duration
)
RecordSequencerBuildingDiffTime
(
duration
time
.
Duration
)
RecordSequencerSealingTime
(
duration
time
.
Duration
)
RecordSequencerSealingTime
(
duration
time
.
Duration
)
Document
()
[]
metrics
.
DocumentedMetric
}
}
type
Metrics
struct
{
type
Metrics
struct
{
...
@@ -111,6 +113,7 @@ type Metrics struct {
...
@@ -111,6 +113,7 @@ type Metrics struct {
BandwidthTotal
*
prometheus
.
GaugeVec
BandwidthTotal
*
prometheus
.
GaugeVec
registry
*
prometheus
.
Registry
registry
*
prometheus
.
Registry
factory
metrics
.
Factory
}
}
var
_
Metricer
=
(
*
Metrics
)(
nil
)
var
_
Metricer
=
(
*
Metrics
)(
nil
)
...
@@ -124,21 +127,22 @@ func NewMetrics(procName string) *Metrics {
...
@@ -124,21 +127,22 @@ func NewMetrics(procName string) *Metrics {
registry
:=
prometheus
.
NewRegistry
()
registry
:=
prometheus
.
NewRegistry
()
registry
.
MustRegister
(
collectors
.
NewProcessCollector
(
collectors
.
ProcessCollectorOpts
{}))
registry
.
MustRegister
(
collectors
.
NewProcessCollector
(
collectors
.
ProcessCollectorOpts
{}))
registry
.
MustRegister
(
collectors
.
NewGoCollector
())
registry
.
MustRegister
(
collectors
.
NewGoCollector
())
factory
:=
metrics
.
With
(
registry
)
return
&
Metrics
{
return
&
Metrics
{
Info
:
promauto
.
With
(
registry
)
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Info
:
factory
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"info"
,
Name
:
"info"
,
Help
:
"Pseudo-metric tracking version and config info"
,
Help
:
"Pseudo-metric tracking version and config info"
,
},
[]
string
{
},
[]
string
{
"version"
,
"version"
,
}),
}),
Up
:
promauto
.
With
(
registry
)
.
NewGauge
(
prometheus
.
GaugeOpts
{
Up
:
factory
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"up"
,
Name
:
"up"
,
Help
:
"1 if the op node has finished starting up"
,
Help
:
"1 if the op node has finished starting up"
,
}),
}),
RPCServerRequestsTotal
:
promauto
.
With
(
registry
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
RPCServerRequestsTotal
:
factory
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Subsystem
:
RPCServerSubsystem
,
Subsystem
:
RPCServerSubsystem
,
Name
:
"requests_total"
,
Name
:
"requests_total"
,
...
@@ -146,7 +150,7 @@ func NewMetrics(procName string) *Metrics {
...
@@ -146,7 +150,7 @@ func NewMetrics(procName string) *Metrics {
},
[]
string
{
},
[]
string
{
"method"
,
"method"
,
}),
}),
RPCServerRequestDurationSeconds
:
promauto
.
With
(
registry
)
.
NewHistogramVec
(
prometheus
.
HistogramOpts
{
RPCServerRequestDurationSeconds
:
factory
.
NewHistogramVec
(
prometheus
.
HistogramOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Subsystem
:
RPCServerSubsystem
,
Subsystem
:
RPCServerSubsystem
,
Name
:
"request_duration_seconds"
,
Name
:
"request_duration_seconds"
,
...
@@ -155,7 +159,7 @@ func NewMetrics(procName string) *Metrics {
...
@@ -155,7 +159,7 @@ func NewMetrics(procName string) *Metrics {
},
[]
string
{
},
[]
string
{
"method"
,
"method"
,
}),
}),
RPCClientRequestsTotal
:
promauto
.
With
(
registry
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
RPCClientRequestsTotal
:
factory
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Subsystem
:
RPCClientSubsystem
,
Subsystem
:
RPCClientSubsystem
,
Name
:
"requests_total"
,
Name
:
"requests_total"
,
...
@@ -163,7 +167,7 @@ func NewMetrics(procName string) *Metrics {
...
@@ -163,7 +167,7 @@ func NewMetrics(procName string) *Metrics {
},
[]
string
{
},
[]
string
{
"method"
,
"method"
,
}),
}),
RPCClientRequestDurationSeconds
:
promauto
.
With
(
registry
)
.
NewHistogramVec
(
prometheus
.
HistogramOpts
{
RPCClientRequestDurationSeconds
:
factory
.
NewHistogramVec
(
prometheus
.
HistogramOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Subsystem
:
RPCClientSubsystem
,
Subsystem
:
RPCClientSubsystem
,
Name
:
"request_duration_seconds"
,
Name
:
"request_duration_seconds"
,
...
@@ -172,7 +176,7 @@ func NewMetrics(procName string) *Metrics {
...
@@ -172,7 +176,7 @@ func NewMetrics(procName string) *Metrics {
},
[]
string
{
},
[]
string
{
"method"
,
"method"
,
}),
}),
RPCClientResponsesTotal
:
promauto
.
With
(
registry
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
RPCClientResponsesTotal
:
factory
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Subsystem
:
RPCClientSubsystem
,
Subsystem
:
RPCClientSubsystem
,
Name
:
"responses_total"
,
Name
:
"responses_total"
,
...
@@ -182,33 +186,33 @@ func NewMetrics(procName string) *Metrics {
...
@@ -182,33 +186,33 @@ func NewMetrics(procName string) *Metrics {
"error"
,
"error"
,
}),
}),
L1SourceCache
:
NewCacheMetrics
(
regist
ry
,
ns
,
"l1_source_cache"
,
"L1 Source cache"
),
L1SourceCache
:
NewCacheMetrics
(
facto
ry
,
ns
,
"l1_source_cache"
,
"L1 Source cache"
),
L2SourceCache
:
NewCacheMetrics
(
regist
ry
,
ns
,
"l2_source_cache"
,
"L2 Source cache"
),
L2SourceCache
:
NewCacheMetrics
(
facto
ry
,
ns
,
"l2_source_cache"
,
"L2 Source cache"
),
DerivationIdle
:
promauto
.
With
(
registry
)
.
NewGauge
(
prometheus
.
GaugeOpts
{
DerivationIdle
:
factory
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"derivation_idle"
,
Name
:
"derivation_idle"
,
Help
:
"1 if the derivation pipeline is idle"
,
Help
:
"1 if the derivation pipeline is idle"
,
}),
}),
PipelineResets
:
NewEventMetrics
(
regist
ry
,
ns
,
"pipeline_resets"
,
"derivation pipeline resets"
),
PipelineResets
:
NewEventMetrics
(
facto
ry
,
ns
,
"pipeline_resets"
,
"derivation pipeline resets"
),
UnsafePayloads
:
NewEventMetrics
(
regist
ry
,
ns
,
"unsafe_payloads"
,
"unsafe payloads"
),
UnsafePayloads
:
NewEventMetrics
(
facto
ry
,
ns
,
"unsafe_payloads"
,
"unsafe payloads"
),
DerivationErrors
:
NewEventMetrics
(
regist
ry
,
ns
,
"derivation_errors"
,
"derivation errors"
),
DerivationErrors
:
NewEventMetrics
(
facto
ry
,
ns
,
"derivation_errors"
,
"derivation errors"
),
SequencingErrors
:
NewEventMetrics
(
regist
ry
,
ns
,
"sequencing_errors"
,
"sequencing errors"
),
SequencingErrors
:
NewEventMetrics
(
facto
ry
,
ns
,
"sequencing_errors"
,
"sequencing errors"
),
PublishingErrors
:
NewEventMetrics
(
regist
ry
,
ns
,
"publishing_errors"
,
"p2p publishing errors"
),
PublishingErrors
:
NewEventMetrics
(
facto
ry
,
ns
,
"publishing_errors"
,
"p2p publishing errors"
),
UnsafePayloadsBufferLen
:
promauto
.
With
(
registry
)
.
NewGauge
(
prometheus
.
GaugeOpts
{
UnsafePayloadsBufferLen
:
factory
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"unsafe_payloads_buffer_len"
,
Name
:
"unsafe_payloads_buffer_len"
,
Help
:
"Number of buffered L2 unsafe payloads"
,
Help
:
"Number of buffered L2 unsafe payloads"
,
}),
}),
UnsafePayloadsBufferMemSize
:
promauto
.
With
(
registry
)
.
NewGauge
(
prometheus
.
GaugeOpts
{
UnsafePayloadsBufferMemSize
:
factory
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"unsafe_payloads_buffer_mem_size"
,
Name
:
"unsafe_payloads_buffer_mem_size"
,
Help
:
"Total estimated memory size of buffered L2 unsafe payloads"
,
Help
:
"Total estimated memory size of buffered L2 unsafe payloads"
,
}),
}),
RefsNumber
:
promauto
.
With
(
registry
)
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
RefsNumber
:
factory
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"refs_number"
,
Name
:
"refs_number"
,
Help
:
"Gauge representing the different L1/L2 reference block numbers"
,
Help
:
"Gauge representing the different L1/L2 reference block numbers"
,
...
@@ -216,7 +220,7 @@ func NewMetrics(procName string) *Metrics {
...
@@ -216,7 +220,7 @@ func NewMetrics(procName string) *Metrics {
"layer"
,
"layer"
,
"type"
,
"type"
,
}),
}),
RefsTime
:
promauto
.
With
(
registry
)
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
RefsTime
:
factory
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"refs_time"
,
Name
:
"refs_time"
,
Help
:
"Gauge representing the different L1/L2 reference block timestamps"
,
Help
:
"Gauge representing the different L1/L2 reference block timestamps"
,
...
@@ -224,7 +228,7 @@ func NewMetrics(procName string) *Metrics {
...
@@ -224,7 +228,7 @@ func NewMetrics(procName string) *Metrics {
"layer"
,
"layer"
,
"type"
,
"type"
,
}),
}),
RefsHash
:
promauto
.
With
(
registry
)
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
RefsHash
:
factory
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"refs_hash"
,
Name
:
"refs_hash"
,
Help
:
"Gauge representing the different L1/L2 reference block hashes truncated to float values"
,
Help
:
"Gauge representing the different L1/L2 reference block hashes truncated to float values"
,
...
@@ -232,14 +236,14 @@ func NewMetrics(procName string) *Metrics {
...
@@ -232,14 +236,14 @@ func NewMetrics(procName string) *Metrics {
"layer"
,
"layer"
,
"type"
,
"type"
,
}),
}),
RefsSeqNr
:
promauto
.
With
(
registry
)
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
RefsSeqNr
:
factory
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"refs_seqnr"
,
Name
:
"refs_seqnr"
,
Help
:
"Gauge representing the different L2 reference sequence numbers"
,
Help
:
"Gauge representing the different L2 reference sequence numbers"
,
},
[]
string
{
},
[]
string
{
"type"
,
"type"
,
}),
}),
RefsLatency
:
promauto
.
With
(
registry
)
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
RefsLatency
:
factory
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"refs_latency"
,
Name
:
"refs_latency"
,
Help
:
"Gauge representing the different L1/L2 reference block timestamps minus current time, in seconds"
,
Help
:
"Gauge representing the different L1/L2 reference block timestamps minus current time, in seconds"
,
...
@@ -249,32 +253,32 @@ func NewMetrics(procName string) *Metrics {
...
@@ -249,32 +253,32 @@ func NewMetrics(procName string) *Metrics {
}),
}),
LatencySeen
:
make
(
map
[
string
]
common
.
Hash
),
LatencySeen
:
make
(
map
[
string
]
common
.
Hash
),
L1ReorgDepth
:
promauto
.
With
(
registry
)
.
NewHistogram
(
prometheus
.
HistogramOpts
{
L1ReorgDepth
:
factory
.
NewHistogram
(
prometheus
.
HistogramOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"l1_reorg_depth"
,
Name
:
"l1_reorg_depth"
,
Buckets
:
[]
float64
{
0.5
,
1.5
,
2.5
,
3.5
,
4.5
,
5.5
,
6.5
,
7.5
,
8.5
,
9.5
,
10.5
,
20.5
,
50.5
,
100.5
},
Buckets
:
[]
float64
{
0.5
,
1.5
,
2.5
,
3.5
,
4.5
,
5.5
,
6.5
,
7.5
,
8.5
,
9.5
,
10.5
,
20.5
,
50.5
,
100.5
},
Help
:
"Histogram of L1 Reorg Depths"
,
Help
:
"Histogram of L1 Reorg Depths"
,
}),
}),
TransactionsSequencedTotal
:
promauto
.
With
(
registry
)
.
NewGauge
(
prometheus
.
GaugeOpts
{
TransactionsSequencedTotal
:
factory
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"transactions_sequenced_total"
,
Name
:
"transactions_sequenced_total"
,
Help
:
"Count of total transactions sequenced"
,
Help
:
"Count of total transactions sequenced"
,
}),
}),
PeerCount
:
promauto
.
With
(
registry
)
.
NewGauge
(
prometheus
.
GaugeOpts
{
PeerCount
:
factory
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Subsystem
:
"p2p"
,
Subsystem
:
"p2p"
,
Name
:
"peer_count"
,
Name
:
"peer_count"
,
Help
:
"Count of currently connected p2p peers"
,
Help
:
"Count of currently connected p2p peers"
,
}),
}),
StreamCount
:
promauto
.
With
(
registry
)
.
NewGauge
(
prometheus
.
GaugeOpts
{
StreamCount
:
factory
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Subsystem
:
"p2p"
,
Subsystem
:
"p2p"
,
Name
:
"stream_count"
,
Name
:
"stream_count"
,
Help
:
"Count of currently connected p2p streams"
,
Help
:
"Count of currently connected p2p streams"
,
}),
}),
GossipEventsTotal
:
promauto
.
With
(
registry
)
.
NewCounterVec
(
prometheus
.
CounterOpts
{
GossipEventsTotal
:
factory
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Subsystem
:
"p2p"
,
Subsystem
:
"p2p"
,
Name
:
"gossip_events_total"
,
Name
:
"gossip_events_total"
,
...
@@ -282,7 +286,7 @@ func NewMetrics(procName string) *Metrics {
...
@@ -282,7 +286,7 @@ func NewMetrics(procName string) *Metrics {
},
[]
string
{
},
[]
string
{
"type"
,
"type"
,
}),
}),
BandwidthTotal
:
promauto
.
With
(
registry
)
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
BandwidthTotal
:
factory
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Subsystem
:
"p2p"
,
Subsystem
:
"p2p"
,
Name
:
"bandwidth_bytes_total"
,
Name
:
"bandwidth_bytes_total"
,
...
@@ -291,7 +295,7 @@ func NewMetrics(procName string) *Metrics {
...
@@ -291,7 +295,7 @@ func NewMetrics(procName string) *Metrics {
"direction"
,
"direction"
,
}),
}),
SequencerBuildingDiffDurationSeconds
:
promauto
.
With
(
registry
)
.
NewHistogram
(
prometheus
.
HistogramOpts
{
SequencerBuildingDiffDurationSeconds
:
factory
.
NewHistogram
(
prometheus
.
HistogramOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"sequencer_building_diff_seconds"
,
Name
:
"sequencer_building_diff_seconds"
,
Buckets
:
[]
float64
{
Buckets
:
[]
float64
{
...
@@ -299,24 +303,25 @@ func NewMetrics(procName string) *Metrics {
...
@@ -299,24 +303,25 @@ func NewMetrics(procName string) *Metrics {
.005
,
.01
,
.025
,
.05
,
.1
,
.25
,
.5
,
1
,
2.5
,
5
,
10
},
.005
,
.01
,
.025
,
.05
,
.1
,
.25
,
.5
,
1
,
2.5
,
5
,
10
},
Help
:
"Histogram of Sequencer building time, minus block time"
,
Help
:
"Histogram of Sequencer building time, minus block time"
,
}),
}),
SequencerBuildingDiffTotal
:
promauto
.
With
(
registry
)
.
NewCounter
(
prometheus
.
CounterOpts
{
SequencerBuildingDiffTotal
:
factory
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"sequencer_building_diff_total"
,
Name
:
"sequencer_building_diff_total"
,
Help
:
"Number of sequencer block building jobs"
,
Help
:
"Number of sequencer block building jobs"
,
}),
}),
SequencerSealingDurationSeconds
:
promauto
.
With
(
registry
)
.
NewHistogram
(
prometheus
.
HistogramOpts
{
SequencerSealingDurationSeconds
:
factory
.
NewHistogram
(
prometheus
.
HistogramOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"sequencer_sealing_seconds"
,
Name
:
"sequencer_sealing_seconds"
,
Buckets
:
[]
float64
{
.005
,
.01
,
.025
,
.05
,
.1
,
.25
,
.5
,
1
,
2.5
,
5
,
10
},
Buckets
:
[]
float64
{
.005
,
.01
,
.025
,
.05
,
.1
,
.25
,
.5
,
1
,
2.5
,
5
,
10
},
Help
:
"Histogram of Sequencer block sealing time"
,
Help
:
"Histogram of Sequencer block sealing time"
,
}),
}),
SequencerSealingTotal
:
promauto
.
With
(
registry
)
.
NewCounter
(
prometheus
.
CounterOpts
{
SequencerSealingTotal
:
factory
.
NewCounter
(
prometheus
.
CounterOpts
{
Namespace
:
ns
,
Namespace
:
ns
,
Name
:
"sequencer_sealing_total"
,
Name
:
"sequencer_sealing_total"
,
Help
:
"Number of sequencer block sealing jobs"
,
Help
:
"Number of sequencer block sealing jobs"
,
}),
}),
registry
:
registry
,
registry
:
registry
,
factory
:
factory
,
}
}
}
}
...
@@ -515,6 +520,10 @@ func (m *Metrics) Serve(ctx context.Context, hostname string, port int) error {
...
@@ -515,6 +520,10 @@ func (m *Metrics) Serve(ctx context.Context, hostname string, port int) error {
return
server
.
ListenAndServe
()
return
server
.
ListenAndServe
()
}
}
func
(
m
*
Metrics
)
Document
()
[]
metrics
.
DocumentedMetric
{
return
m
.
factory
.
Document
()
}
type
noopMetricer
struct
{}
type
noopMetricer
struct
{}
var
NoopMetrics
Metricer
=
new
(
noopMetricer
)
var
NoopMetrics
Metricer
=
new
(
noopMetricer
)
...
@@ -595,3 +604,7 @@ func (n *noopMetricer) RecordSequencerBuildingDiffTime(duration time.Duration) {
...
@@ -595,3 +604,7 @@ func (n *noopMetricer) RecordSequencerBuildingDiffTime(duration time.Duration) {
func
(
n
*
noopMetricer
)
RecordSequencerSealingTime
(
duration
time
.
Duration
)
{
func
(
n
*
noopMetricer
)
RecordSequencerSealingTime
(
duration
time
.
Duration
)
{
}
}
func
(
n
*
noopMetricer
)
Document
()
[]
metrics
.
DocumentedMetric
{
return
nil
}
op-service/metrics/factory.go
0 → 100644
View file @
23db9514
package
metrics
import
(
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
type
Factory
interface
{
NewCounter
(
opts
prometheus
.
CounterOpts
)
prometheus
.
Counter
NewCounterVec
(
opts
prometheus
.
CounterOpts
,
labelNames
[]
string
)
*
prometheus
.
CounterVec
NewGauge
(
opts
prometheus
.
GaugeOpts
)
prometheus
.
Gauge
NewGaugeVec
(
opts
prometheus
.
GaugeOpts
,
labelNames
[]
string
)
*
prometheus
.
GaugeVec
NewHistogram
(
opts
prometheus
.
HistogramOpts
)
prometheus
.
Histogram
NewHistogramVec
(
opts
prometheus
.
HistogramOpts
,
labelNames
[]
string
)
*
prometheus
.
HistogramVec
NewSummary
(
opts
prometheus
.
SummaryOpts
)
prometheus
.
Summary
NewSummaryVec
(
opts
prometheus
.
SummaryOpts
,
labelNames
[]
string
)
*
prometheus
.
SummaryVec
Document
()
[]
DocumentedMetric
}
type
DocumentedMetric
struct
{
Type
string
`json:"type"`
Name
string
`json:"name"`
Help
string
`json:"help"`
Labels
[]
string
`json:"labels"`
}
type
documentor
struct
{
metrics
[]
DocumentedMetric
factory
promauto
.
Factory
}
func
With
(
registry
*
prometheus
.
Registry
)
Factory
{
return
&
documentor
{
factory
:
promauto
.
With
(
registry
),
}
}
func
(
d
*
documentor
)
NewCounter
(
opts
prometheus
.
CounterOpts
)
prometheus
.
Counter
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"counter"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
})
return
d
.
factory
.
NewCounter
(
opts
)
}
func
(
d
*
documentor
)
NewCounterVec
(
opts
prometheus
.
CounterOpts
,
labelNames
[]
string
)
*
prometheus
.
CounterVec
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"counter"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
Labels
:
labelNames
,
})
return
d
.
factory
.
NewCounterVec
(
opts
,
labelNames
)
}
func
(
d
*
documentor
)
NewGauge
(
opts
prometheus
.
GaugeOpts
)
prometheus
.
Gauge
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"gauge"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
})
return
d
.
factory
.
NewGauge
(
opts
)
}
func
(
d
*
documentor
)
NewGaugeVec
(
opts
prometheus
.
GaugeOpts
,
labelNames
[]
string
)
*
prometheus
.
GaugeVec
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"gauge"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
Labels
:
labelNames
,
})
return
d
.
factory
.
NewGaugeVec
(
opts
,
labelNames
)
}
func
(
d
*
documentor
)
NewHistogram
(
opts
prometheus
.
HistogramOpts
)
prometheus
.
Histogram
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"histogram"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
})
return
d
.
factory
.
NewHistogram
(
opts
)
}
func
(
d
*
documentor
)
NewHistogramVec
(
opts
prometheus
.
HistogramOpts
,
labelNames
[]
string
)
*
prometheus
.
HistogramVec
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"histogram"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
Labels
:
labelNames
,
})
return
d
.
factory
.
NewHistogramVec
(
opts
,
labelNames
)
}
func
(
d
*
documentor
)
NewSummary
(
opts
prometheus
.
SummaryOpts
)
prometheus
.
Summary
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"summary"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
})
return
d
.
factory
.
NewSummary
(
opts
)
}
func
(
d
*
documentor
)
NewSummaryVec
(
opts
prometheus
.
SummaryOpts
,
labelNames
[]
string
)
*
prometheus
.
SummaryVec
{
d
.
metrics
=
append
(
d
.
metrics
,
DocumentedMetric
{
Type
:
"summary"
,
Name
:
fullName
(
opts
.
Namespace
,
opts
.
Subsystem
,
opts
.
Name
),
Help
:
opts
.
Help
,
Labels
:
labelNames
,
})
return
d
.
factory
.
NewSummaryVec
(
opts
,
labelNames
)
}
func
(
d
*
documentor
)
Document
()
[]
DocumentedMetric
{
return
d
.
metrics
}
func
fullName
(
ns
,
subsystem
,
name
string
)
string
{
out
:=
ns
if
subsystem
!=
""
{
out
+=
"_"
+
subsystem
}
return
out
+
"_"
+
name
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment