metrics

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2018 License: Apache-2.0 Imports: 11 Imported by: 11

Documentation

Index

Constants

View Source
const MetricsEnabledFlag = "metrics"

Variables

This section is empty.

Functions

func ToGRPCPromCounterOption

func ToGRPCPromCounterOption(opts *Options) grpcProm.CounterOption

To support grpc prometheus options

func ToGRPCPromHistogramOption

func ToGRPCPromHistogramOption(opts *Options) grpcProm.HistogramOption

Types

type Counter

type Counter interface {
	Inc()
	Add(float64)
}

Counter is a Metric that represents a single numerical value that only ever goes up. A Counter is typically used to count requests served, tasks completed, errors occurred, etc.

func NewCounter

func NewCounter(key string, opts ...Option) Counter

type DummyRegistry

type DummyRegistry struct {
}

func NewDummyRegistry

func NewDummyRegistry() *DummyRegistry

func (*DummyRegistry) NewCounter

func (d *DummyRegistry) NewCounter(key string, opts ...Option) Counter

func (*DummyRegistry) NewGauge

func (d *DummyRegistry) NewGauge(key string, opts ...Option) Gauge

func (*DummyRegistry) NewHistogram

func (d *DummyRegistry) NewHistogram(key string, opts ...Option) Histogram

func (*DummyRegistry) NewServerMetrics

func (d *DummyRegistry) NewServerMetrics(opts ...Option) ServerMetrics

func (*DummyRegistry) NewTimer

func (d *DummyRegistry) NewTimer(key string, opts ...Option) Timer

func (*DummyRegistry) NewWorker

func (d *DummyRegistry) NewWorker(key string, opts ...Option) Worker

func (*DummyRegistry) ServeHTTP

func (d *DummyRegistry) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Gauge

type Gauge interface {
	Set(float64)
}

Gauge is a Metric that represents a single numerical value that can arbitrarily go up and down. A Gauge is typically used for measured values like temperatures or current memory usage.

func NewGauge

func NewGauge(key string, opts ...Option) Gauge

type Histogram

type Histogram interface {
	Observe(float64)
}

A Histogram counts individual observations from an event or sample stream in configurable buckets. Similar to a summary, it also provides a sum of observations and an observation count.

func NewHistogram

func NewHistogram(key string, opts ...Option) Histogram

type Option

type Option func(opt *Options)

func Labels

func Labels(lbs map[string]string) Option

func Namespace

func Namespace(namespace string) Option

func Subsystem

func Subsystem(subsystem string) Option

type Options

type Options struct {
	Namespace string
	Subsystem string
	Labels    map[string]string
}

func NewOptions

func NewOptions(namespace, subsystem string, lbs map[string]string) *Options

type PrometheusRegistry

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

func NewPrometheusRegistry

func NewPrometheusRegistry() *PrometheusRegistry

func (*PrometheusRegistry) AppendLabels

func (p *PrometheusRegistry) AppendLabels(labels map[string]string)

func (*PrometheusRegistry) NewCounter

func (p *PrometheusRegistry) NewCounter(key string, opts ...Option) Counter

func (*PrometheusRegistry) NewGauge

func (p *PrometheusRegistry) NewGauge(key string, opts ...Option) Gauge

func (*PrometheusRegistry) NewHistogram

func (p *PrometheusRegistry) NewHistogram(key string, opts ...Option) Histogram

func (*PrometheusRegistry) NewServerMetrics

func (p *PrometheusRegistry) NewServerMetrics(opts ...Option) ServerMetrics

func (*PrometheusRegistry) NewTimer

func (p *PrometheusRegistry) NewTimer(key string, opts ...Option) Timer

func (*PrometheusRegistry) NewWorker

func (p *PrometheusRegistry) NewWorker(key string, opts ...Option) Worker

func (*PrometheusRegistry) ServeHTTP

func (p *PrometheusRegistry) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*PrometheusRegistry) SetNamespace

func (p *PrometheusRegistry) SetNamespace(namespace string)

type Registry

type Registry interface {
	NewServerMetrics(opts ...Option) ServerMetrics
	NewCounter(key string, opts ...Option) Counter
	NewGauge(key string, opts ...Option) Gauge
	NewHistogram(key string, opts ...Option) Histogram
	NewTimer(key string, opts ...Option) Timer
	NewWorker(key string, opts ...Option) Worker

	// ServeHTTP is used to display all metric values through http request
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

Registry is a metrics gather

var DefaultRegistry Registry = NewDummyRegistry()

type ServerMetrics

type ServerMetrics interface {
	InitializeMetrics(*grpc.Server)
	StreamServerInterceptor() func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
	UnaryServerInterceptor() func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
}

ServerMetrics is an integrated metric collector to measure count of any kind of error and elapsed time of each grpc method.

func NewServerMetrics

func NewServerMetrics(opts ...Option) ServerMetrics

type Timer

type Timer interface {
	Observe(time.Time)
}

Timer represents a Histogram Metrics to observe the time duration according to given begin time. Timer is usually used to time a function call in the following way:

func TimeMe() {
    begin := time.Now()
    defer Timer.Observe(begin)
}

func NewTimer

func NewTimer(key string, opts ...Option) Timer

type Worker

type Worker interface {
	Observe(time.Time, error)
}

Worker includes Timer Metrics to observe the time duration according to given begin time, and counter Metreic to gather the success count and fail count. Worker is usually used to measure a function call in the following way:

func MeasureMe()(err error) {
    begin := time.Now()
    defer Worker.Observe(begin, err)
}

func NewWorker

func NewWorker(key string, opts ...Option) Worker

Jump to

Keyboard shortcuts

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