metrics

package
v0.71.3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Gauge ...
	Gauge instrument = iota
	// Counter ...
	Counter
	// Histogram ...
	Histogram
	// Summary ...
	Summary
)

Variables

View Source
var (
	// ErrInstrumentNotSupported signals the specified instrument is not yet supported.
	ErrInstrumentNotSupported = errors.New("instrument type unsupported")
	// ErrInstrumentTypeMismatch signal the type of the instrument is not expected.
	ErrInstrumentTypeMismatch = errors.New("instrument is not of the expected type")
)

Functions

func APIRequestAndTimeGRPC

func APIRequestAndTimeGRPC(request string, startTime time.Time)

APIRequestAndTimeGRPC updates the metrics for GRPC API calls.

func APIRequestAndTimeGraphQL

func APIRequestAndTimeGraphQL(request string, time float64)

APIRequestAndTimeGraphQL updates the metrics for GraphQL API calls.

func APIRequestAndTimeREST

func APIRequestAndTimeREST(method, request string, time float64)

APIRequestAndTimeREST updates the metrics for REST API calls.

func EthCallInc

func EthCallInc(labelValues ...string)

EthCallInc increments the eth call counter.

func EvtForwardInc

func EvtForwardInc(labelValues ...string)

EvtForwardInc increments the evt forward counter.

func OrderCounterInc

func OrderCounterInc(labelValues ...string)

OrderCounterInc increments the order counter.

func OrderGaugeAdd

func OrderGaugeAdd(n int, labelValues ...string)

OrderGaugeAdd increment the order gauge.

func Start

func Start(conf Config)

Start enable metrics (given config).

func StartAPIRequestAndTimeGRPC

func StartAPIRequestAndTimeGRPC(request string) func()

StartAPIRequestAndTimeGRPC updates the metrics for GRPC API calls.

func StartSnapshot

func StartSnapshot(engine string) func()

func UnconfirmedTxGaugeSet

func UnconfirmedTxGaugeSet(n int)

UnconfirmedTxGaugeSet update the number of unconfirmed transactions.

Types

type Config

type Config struct {
	Level   encoding.LogLevel `long:"log-level" description:" "`
	Timeout encoding.Duration `long:"timeout" description:" "`
	Port    int               `long:"port" description:" "`
	Path    string            `long:"path" description:" "`
	Enabled encoding.Bool     `long:"enabled" description:" "`
}

Config represents the configuration of the metric package.

func NewDefaultConfig

func NewDefaultConfig() Config

NewDefaultConfig creates an instance of the package specific configuration, given a pointer to a logger instance to be used for logging within the package.

type InstrumentOption

type InstrumentOption func(o *instrumentOpts)

InstrumentOption - vararg for instrument options setting.

func AgeBuckets

func AgeBuckets(ab uint32) InstrumentOption

AgeBuckets - specific to summary type.

func Buckets

func Buckets(b []float64) InstrumentOption

Buckets - specific to histogram type.

func BufCap

func BufCap(bc uint32) InstrumentOption

BufCap - specific to summary type.

func Help

func Help(help string) InstrumentOption

Help - set the help field on instrument.

func Labels

func Labels(labels map[string]string) InstrumentOption

Labels set labels for instrument (similar to vector, but with given values).

func MaxAge

func MaxAge(m time.Duration) InstrumentOption

MaxAge - specific to summary type.

func Namespace

func Namespace(ns string) InstrumentOption

Namespace - set namespace.

func Objectives

func Objectives(obj map[float64]float64) InstrumentOption

Objectives - specific to summary type.

func Subsystem

func Subsystem(s string) InstrumentOption

Subsystem - set subsystem... obviously.

func Vectors

func Vectors(labels ...string) InstrumentOption

Vectors - configuration used to create a vector of a given interface, slice of label names.

type MetricInstrument

type MetricInstrument interface {
	Gauge() (prometheus.Gauge, error)
	GaugeVec() (*prometheus.GaugeVec, error)
	Counter() (prometheus.Counter, error)
	CounterVec() (*prometheus.CounterVec, error)
	Histogram() (prometheus.Histogram, error)
	HistogramVec() (*prometheus.HistogramVec, error)
	Summary() (prometheus.Summary, error)
	SummaryVec() (*prometheus.SummaryVec, error)
}

MetricInstrument - template interface for mi type return value - only mock if needed, and only mock the funcs you use.

type TimeCounter

type TimeCounter struct {
	// contains filtered or unexported fields
}

TimeCounter holds a time.Time and a list of label values, hiding the start time from being accidentally overwritten, and removing the need to duplicate the label values.

func NewTimeCounter

func NewTimeCounter(labelValues ...string) *TimeCounter

NewTimeCounter returns a new TimeCounter, with the start time already recorded.

func (*TimeCounter) EngineTimeCounterAdd

func (tc *TimeCounter) EngineTimeCounterAdd()

EngineTimeCounterAdd is used to time a function. e.g.

func DoSomething() {
	timer := metrics.NewTimeCounter("x", "y", "z")
	// do something
	timer.EngineTimeCounterAdd()
}

Jump to

Keyboard shortcuts

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