dmetrics

package module
v0.0.0-...-3b8cb01 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

README

dfuse Metrics Library

reference License

For now, this library contains simple wrapping structure around Prometheus metrics. This improves usage and developer experience of defining metrics for dfuse services. It is part of dfuse.

This library should be kept as SMALL as possible, as it is a dependency we want to sprinkle around widely.

Usage

All metrics must be created from a metrics Set. The idea is that each library and micro-services defines a single set of metrics.

All metrics to be published by Prometheus must be registered at some point.

Example metrics.go in an example bstream project:

// Exported, so it can be registered by a `metrics.go` in main packages.
var MetricsSet = dmetrics.NewSet()

// HitCount is exported if used by other packages elsewhere, use like `bstream.HitCount.Inc()`
var HitCount = MetricsSet.NewGauge("bstream_hit_count", "hello %s")

// myCount is not exported, because used only in here.  Use as: `myCount.Inc()`
var myCount = MetricsSet.NewGauge("bstream_my_count", "hello %s")

In a main package, in a metrics.go (similar to logging.go):

func init() {
    dmetrics.Register(
        bstream.MetricsSet,
        dauth.MetricsSet,
        blockmeta.MetricsSet,
    )
}

Background

Initially, we had defined our metrics directly as the Prometheus type giving a definition of metrics in the form:

var mapSize = newGauge(
	"map_size",
	"size of live blocks map",
)

func IncMapSize() {
	mapSize.Inc()
}

func DecMapSize() {
	mapSize.Dec()
}

The usage of this was then like this:

    metrics.IncMapSize()

    ...

    metrics.DecMapSize()

This was repeated for all metrics then defined. This is problematic as when there is multiple metrics, the source file for definitions becomes bloated with lots of repeated stuff and duplicated stuff.

To overcome this, this library wraps different Prometheus metrics to clean down the definitions file. and offer a nicer API around them , and also usage. The previous example can now be turned into:

var MapSize = dmetrics.NewGauge("map_size", "size of live blocks map")

And the usage is now like:

    metrics.MapSize.Inc()

    ...

    metrics.MapSize.Dec()

An incredible improvement in the definitions of the metrics themselves.

Contributing

Issues and PR in this repo related strictly to the dmetrics library.

Report any protocol-specific issues in their respective repositories

Please first refer to the general dfuse contribution guide, if you wish to contribute to this code base.

License

Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoOpPrometheusRegister = func(c ...prometheus.Collector) {}
View Source
var PrometheusRegister = prometheus.MustRegister

Functions

func Register

func Register(sets ...*Set)

Register from `metrics.go`

func Serve

func Serve(addr string)

Types

type Counter

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

func (*Counter) AddFloat64

func (c *Counter) AddFloat64(value float64)

func (*Counter) AddInt

func (c *Counter) AddInt(value int)

func (*Counter) AddInt64

func (c *Counter) AddInt64(value int64)

func (*Counter) AddUint64

func (c *Counter) AddUint64(value uint64)

func (*Counter) Inc

func (c *Counter) Inc()

func (*Counter) Native

func (c *Counter) Native() prometheus.Counter

type CounterVec

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

func (*CounterVec) AddFloat64

func (c *CounterVec) AddFloat64(value float64, labels ...string)

func (*CounterVec) AddInt

func (c *CounterVec) AddInt(value int, labels ...string)

func (*CounterVec) AddInt64

func (c *CounterVec) AddInt64(value int64, labels ...string)

func (*CounterVec) AddUint64

func (c *CounterVec) AddUint64(value uint64, labels ...string)

func (*CounterVec) Inc

func (c *CounterVec) Inc(labels ...string)

func (*CounterVec) Native

func (g *CounterVec) Native() *prometheus.CounterVec

type Gauge

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

func (*Gauge) Dec

func (g *Gauge) Dec()

func (*Gauge) Inc

func (g *Gauge) Inc()

func (*Gauge) Native

func (g *Gauge) Native() prometheus.Gauge

func (*Gauge) SetFloat64

func (g *Gauge) SetFloat64(value float64)

func (*Gauge) SetUint64

func (g *Gauge) SetUint64(value uint64)

type GaugeVec

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

func (*GaugeVec) Dec

func (g *GaugeVec) Dec(labels ...string)

func (*GaugeVec) Inc

func (g *GaugeVec) Inc(labels ...string)

func (*GaugeVec) Native

func (g *GaugeVec) Native() *prometheus.GaugeVec

func (*GaugeVec) SetFloat64

func (g *GaugeVec) SetFloat64(value float64, labels ...string)

func (*GaugeVec) SetInt

func (g *GaugeVec) SetInt(value int, labels ...string)

func (*GaugeVec) SetInt64

func (g *GaugeVec) SetInt64(value int64, labels ...string)

func (*GaugeVec) SetUint64

func (g *GaugeVec) SetUint64(value uint64, labels ...string)

type HeadBlockNum

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

func (*HeadBlockNum) SetUint64

func (h *HeadBlockNum) SetUint64(blockNum uint64)

type HeadTimeDrift

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

func (*HeadTimeDrift) SetBlockTime

func (h *HeadTimeDrift) SetBlockTime(blockTime time.Time)

type Histogram

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

func (*Histogram) Native

func (h *Histogram) Native() prometheus.Histogram

func (*Histogram) ObserveDuration

func (h *Histogram) ObserveDuration(value time.Duration)

func (*Histogram) ObserveFloat64

func (h *Histogram) ObserveFloat64(value float64)

func (*Histogram) ObserveInt

func (h *Histogram) ObserveInt(value int64)

func (*Histogram) ObserveInt64

func (h *Histogram) ObserveInt64(value int64)

func (*Histogram) ObserveSince

func (h *Histogram) ObserveSince(value time.Time)

func (*Histogram) ObserveUint64

func (h *Histogram) ObserveUint64(value int64)

type HistogramVec

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

func (*HistogramVec) Native

func (h *HistogramVec) Native() *prometheus.HistogramVec

func (*HistogramVec) ObserveDuration

func (h *HistogramVec) ObserveDuration(value time.Duration, labels ...string)

func (*HistogramVec) ObserveFloat64

func (h *HistogramVec) ObserveFloat64(value float64, labels ...string)

func (*HistogramVec) ObserveInt

func (h *HistogramVec) ObserveInt(value int64, labels ...string)

func (*HistogramVec) ObserveInt64

func (h *HistogramVec) ObserveInt64(value int64, labels ...string)

func (*HistogramVec) ObserveSince

func (h *HistogramVec) ObserveSince(value time.Time, labels ...string)

func (*HistogramVec) ObserveUint64

func (h *HistogramVec) ObserveUint64(value int64, labels ...string)

type Metric

type Metric interface {
	// contains filtered or unexported methods
}

type Option

type Option func(s *Set)

func PrefixNameWith

func PrefixNameWith(prefix string) Option

PrefixNameWith will prefix all metric of this given set using the following prefix.

type Set

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

func NewSet

func NewSet(options ...Option) *Set

NewSet creates a set of metrics that can then be used to create a varieties of specific metrics (Gauge, Counter, Histogram).

func (*Set) NewCounter

func (s *Set) NewCounter(name string, helpChunks ...string) *Counter

func (*Set) NewCounterVec

func (s *Set) NewCounterVec(name string, labels []string, helpChunks ...string) *CounterVec

func (*Set) NewGauge

func (s *Set) NewGauge(name string, helpChunks ...string) *Gauge

func (*Set) NewGaugeVec

func (s *Set) NewGaugeVec(name string, labels []string, helpChunks ...string) *GaugeVec

func (*Set) NewHeadBlockNumber

func (s *Set) NewHeadBlockNumber(service string) *HeadBlockNum

func (*Set) NewHeadTimeDrift

func (s *Set) NewHeadTimeDrift(service string) *HeadTimeDrift

func (*Set) NewHistogram

func (s *Set) NewHistogram(name string, helpChunks ...string) *Histogram

func (*Set) NewHistogramVec

func (s *Set) NewHistogramVec(name string, labels []string, helpChunks ...string) *HistogramVec

func (*Set) Register

func (s *Set) Register()

Jump to

Keyboard shortcuts

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