metrics

package
v0.0.0-...-5ec3a36 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2018 License: Apache-2.0, UPL-1.0 Imports: 3 Imported by: 0

README

metrics

Metrics contains metrics exposing and collecting related code.

StoreObserver

The StoreObserver encapsulates exposing Store specific metrics to Prometheus. The following metrics are exposed:

  • store_handling_seconds a histogram containing the response latency of the calls.
  • store_handled_total a counter which keeps track of all call made.

A specific metrics store should instantiate this StoreObserver and proxy all calls to Observe. This method returns a func() which has to be called once the metrics store has finished the call:

func (s *MetricsStore) GetUser(ctx context.Context, id string) (User, error) {
  done := s.observer.Observe("GetUser")
  defer done()
  // ... actual work
  return user, err
}

It is highly recommended to call Preload with the store to expose all metrics to prometheus from the beginning:

func NewMetricsStore(wrappedStore Store) *MetricsStore {
	store := &MetricsStore{store: wrappedStore, observer: metrics.NewStoreObserver()}
	store.observer.Preload(store)
	return store
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StoreObserver

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

StoreObserver encapsulates exposing of store specific metrics to Prometheus.

func NewStoreObserver

func NewStoreObserver() *StoreObserver

NewStoreObserver creates a new StoreObserver

func (*StoreObserver) Observe

func (s *StoreObserver) Observe(method string) func()

Observe immediately increments the counter for method and returns a func which will observe an metric item in duration based on the duration.

func (*StoreObserver) Preload

func (m *StoreObserver) Preload(s interface{}, extraIgnoredMethods ...string)

Preload counters and histograms for each method defined on s. You can optionally supply extra ignoreMethods which will be added to the defaultIgnoredMethods array.

Jump to

Keyboard shortcuts

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