metrics

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnabledFlagName    = "metrics.enabled"
	ListenAddrFlagName = "metrics.addr"
	PortFlagName       = "metrics.port"
)
View Source
const (
	RPCServerSubsystem = "rpc_server"
	RPCClientSubsystem = "rpc_client"
)

Variables

View Source
var LatencyBuckets = []float64{.025, .05, .1, .25, .5, 1, 2.5, 5, 10, 25, 50, 100}
View Source
var NoopHTTPRecorder = new(noopHTTPRecorder)
View Source
var NoopNodeRecorder = new(noopNodeRecorder)

Functions

func CLIFlags

func CLIFlags(envPrefix string) []cli.Flag

func LaunchBalanceMetrics

func LaunchBalanceMetrics(log log.Logger, r *prometheus.Registry, ns string, client *ethclient.Client, account common.Address) *clock.LoopFn

LaunchBalanceMetrics starts a periodic query of the balance of the supplied account and records it to the "balance" metric of the namespace. The balance of the account is recorded in Ether (not Wei). Cancel the supplied context to shut down the go routine

func NewHTTPRecordingMiddleware

func NewHTTPRecordingMiddleware(rec HTTPRecorder, next http.Handler) http.Handler

func NewRegistry

func NewRegistry() *prometheus.Registry

func StartServer added in v1.2.0

func StartServer(r *prometheus.Registry, hostname string, port int) (*httputil.HTTPServer, error)

func WeiToEther

func WeiToEther(wei *big.Int) float64

WeiToEther divides the wei value by 10^18 to get a number in ether as a float64

Types

type CLIConfig

type CLIConfig struct {
	Enabled    bool
	ListenAddr string
	ListenPort int
}

func DefaultCLIConfig

func DefaultCLIConfig() CLIConfig

func ReadCLIConfig

func ReadCLIConfig(ctx *cli.Context) CLIConfig

func (CLIConfig) Check

func (m CLIConfig) Check() error

type CacheMetrics added in v1.2.0

type CacheMetrics struct {
	SizeVec *prometheus.GaugeVec
	GetVec  *prometheus.CounterVec
	AddVec  *prometheus.CounterVec
}

CacheMetrics implements the Metrics interface in the caching package, implementing reusable metrics for different caches.

func NewCacheMetrics added in v1.2.0

func NewCacheMetrics(factory Factory, ns string, name string, displayName string) *CacheMetrics

func (*CacheMetrics) CacheAdd added in v1.2.0

func (m *CacheMetrics) CacheAdd(typeLabel string, typeCacheSize int, evicted bool)

CacheAdd meters the addition of an item with a given type to the cache, metering the change of the cache size of that type, and indicating a corresponding eviction if any.

func (*CacheMetrics) CacheGet added in v1.2.0

func (m *CacheMetrics) CacheGet(typeLabel string, hit bool)

CacheGet meters a lookup of an item with a given type to the cache and indicating if the lookup was a hit.

type DocumentedMetric

type DocumentedMetric struct {
	Type   string   `json:"type"`
	Name   string   `json:"name"`
	Help   string   `json:"help"`
	Labels []string `json:"labels"`
}

type Event

type Event struct {
	Total    prometheus.Counter
	LastTime prometheus.Gauge
}

func NewEvent

func NewEvent(factory Factory, ns string, subsystem string, name string, displayName string) *Event

func (*Event) Record

func (e *Event) Record()

type EventVec

type EventVec struct {
	Total    prometheus.CounterVec
	LastTime prometheus.GaugeVec
}

func NewEventVec

func NewEventVec(factory Factory, ns string, subsystem string, name string, displayName string, labelNames []string) EventVec

func (*EventVec) Record

func (e *EventVec) Record(lvs ...string)

type Factory

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
}

func With

func With(registry *prometheus.Registry) Factory

type HTTPParams

type HTTPParams struct {
	Method     string
	StatusCode int
}

type HTTPRecorder

type HTTPRecorder interface {
	RecordHTTPRequestDuration(params *HTTPParams, dur time.Duration)
	RecordHTTPResponseSize(params *HTTPParams, size int)
	RecordInflightRequest(params *HTTPParams, quantity int)
	RecordHTTPRequest(params *HTTPParams)
	RecordHTTPResponse(params *HTTPParams)
}

func NewPromHTTPRecorder

func NewPromHTTPRecorder(r *prometheus.Registry, ns string) HTTPRecorder

type NodeRecorder

type NodeRecorder interface {
	RecordUp()
	RecordInfo(version string)
}

func NewPromNodeRecorder

func NewPromNodeRecorder(r *prometheus.Registry, ns string) NodeRecorder

type NoopRPCMetrics added in v1.2.0

type NoopRPCMetrics struct{}

func (*NoopRPCMetrics) RecordRPCClientRequest added in v1.2.0

func (n *NoopRPCMetrics) RecordRPCClientRequest(method string) func(err error)

func (*NoopRPCMetrics) RecordRPCClientResponse added in v1.2.0

func (n *NoopRPCMetrics) RecordRPCClientResponse(method string, err error)

func (*NoopRPCMetrics) RecordRPCServerRequest added in v1.2.0

func (n *NoopRPCMetrics) RecordRPCServerRequest(method string) func()

type NoopRefMetrics

type NoopRefMetrics struct{}

NoopRefMetrics can be embedded in a noop version of a metric implementation to have a noop RefMetricer.

func (*NoopRefMetrics) RecordL1Ref

func (*NoopRefMetrics) RecordL1Ref(string, eth.L1BlockRef)

func (*NoopRefMetrics) RecordL2Ref

func (*NoopRefMetrics) RecordL2Ref(string, eth.L2BlockRef)

func (*NoopRefMetrics) RecordRef

type PromHTTPRecorder

type PromHTTPRecorder struct {
	// HTTPRequestDuration is the old metric for request latency
	// it was created with too tight buckets: [.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10]
	// in order to preserve backward compatibility we are keeping this metric for now
	// and it will be removed when services opt in to HTTPRequestLatency
	// Deprecated: HTTPRequestDuration is deprecated
	HTTPRequestDuration *prometheus.HistogramVec

	// HTTPRequestLatency measures request execution latency in *seconds*
	// buckets are: [.025, .05, .1, .25, .5, 1, 2.5, 5, 10, 25, 50]
	HTTPRequestLatency *prometheus.HistogramVec

	HTTPResponseSize     *prometheus.HistogramVec
	HTTPInflightRequests *prometheus.GaugeVec
	HTTPRequests         *prometheus.CounterVec
	HTTPResponses        *prometheus.CounterVec
}

func (*PromHTTPRecorder) RecordHTTPRequest

func (p *PromHTTPRecorder) RecordHTTPRequest(params *HTTPParams)

func (*PromHTTPRecorder) RecordHTTPRequestDuration

func (p *PromHTTPRecorder) RecordHTTPRequestDuration(params *HTTPParams, dur time.Duration)

func (*PromHTTPRecorder) RecordHTTPResponse

func (p *PromHTTPRecorder) RecordHTTPResponse(params *HTTPParams)

func (*PromHTTPRecorder) RecordHTTPResponseSize

func (p *PromHTTPRecorder) RecordHTTPResponseSize(params *HTTPParams, size int)

func (*PromHTTPRecorder) RecordInflightRequest

func (p *PromHTTPRecorder) RecordInflightRequest(params *HTTPParams, quantity int)

type PromNodeRecorder

type PromNodeRecorder struct {
	Up   prometheus.Gauge
	Info *prometheus.GaugeVec
}

func (*PromNodeRecorder) RecordInfo

func (p *PromNodeRecorder) RecordInfo(version string)

func (*PromNodeRecorder) RecordUp

func (p *PromNodeRecorder) RecordUp()

type RPCMetricer

type RPCMetricer interface {
	RecordRPCServerRequest(method string) func()
	RecordRPCClientRequest(method string) func(err error)
	RecordRPCClientResponse(method string, err error)
}

type RPCMetrics

type RPCMetrics struct {
	RPCServerRequestsTotal          *prometheus.CounterVec
	RPCServerRequestDurationSeconds *prometheus.HistogramVec
	RPCClientRequestsTotal          *prometheus.CounterVec
	RPCClientRequestDurationSeconds *prometheus.HistogramVec
	RPCClientResponsesTotal         *prometheus.CounterVec
}

RPCMetrics tracks all the RPC metrics for the op-service RPC.

func MakeRPCMetrics

func MakeRPCMetrics(ns string, factory Factory) RPCMetrics

MakeRPCMetrics creates a new RPCMetrics instance with the given process name, and namespace for the service.

func (*RPCMetrics) RecordRPCClientRequest

func (m *RPCMetrics) RecordRPCClientRequest(method string) func(err error)

RecordRPCClientRequest is a helper method to record an RPC client request. It bumps the requests metric, tracks the response duration, and records the response's error code.

func (*RPCMetrics) RecordRPCClientResponse

func (m *RPCMetrics) RecordRPCClientResponse(method string, err error)

RecordRPCClientResponse records an RPC response. It will convert the passed-in error into something metrics friendly. Nil errors get converted into <nil>, RPC errors are converted into rpc_<error code>, HTTP errors are converted into http_<status code>, and everything else is converted into <unknown>.

func (*RPCMetrics) RecordRPCServerRequest

func (m *RPCMetrics) RecordRPCServerRequest(method string) func()

RecordRPCServerRequest is a helper method to record an incoming RPC call to the opnode's RPC server. It bumps the requests metric, and tracks how long it takes to serve a response.

type RefMetricer

type RefMetricer interface {
	RecordRef(layer string, name string, num uint64, timestamp uint64, h common.Hash)
	RecordL1Ref(name string, ref eth.L1BlockRef)
	RecordL2Ref(name string, ref eth.L2BlockRef)
}

type RefMetrics

type RefMetrics struct {
	RefsNumber  *prometheus.GaugeVec
	RefsTime    *prometheus.GaugeVec
	RefsHash    *prometheus.GaugeVec
	RefsSeqNr   *prometheus.GaugeVec
	RefsLatency *prometheus.GaugeVec
	// hash of the last seen block per name, so we don't reduce/increase latency on updates of the same data,
	// and only count the first occurrence
	LatencySeen map[string]common.Hash
}

RefMetrics provides block reference metrics. It's a metrics module that's supposed to be embedded into a service metrics type. The service metrics type should set the full namespace and create the factory before calling NewRefMetrics.

func MakeRefMetrics

func MakeRefMetrics(ns string, factory Factory) RefMetrics

MakeRefMetrics returns a new RefMetrics, initializing its prometheus fields using factory. It is supposed to be used inside the constructors of metrics structs for any op service after the full namespace and factory have been setup.

ns is the fully qualified namespace, e.g. "op_node_default".

func (*RefMetrics) RecordL1Ref

func (m *RefMetrics) RecordL1Ref(name string, ref eth.L1BlockRef)

func (*RefMetrics) RecordL2Ref

func (m *RefMetrics) RecordL2Ref(name string, ref eth.L2BlockRef)

func (*RefMetrics) RecordRef

func (m *RefMetrics) RecordRef(layer string, name string, num uint64, timestamp uint64, h common.Hash)

type RegistryMetricer added in v1.2.0

type RegistryMetricer interface {
	Registry() *prometheus.Registry
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL