instrument

package
Version: v0.0.0-...-d74ee84 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefBuckets = []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10, 25, 50, 100}

DefBuckets are histogram buckets for the response time (in seconds) of a network service, including one that is responding very slowly.

View Source
var HistogramCollectorBuckets = []string{"operation", "status_code"}

HistogramCollectorBuckets define the buckets when passing the metric

Functions

func CollectedRequest

func CollectedRequest(ctx context.Context, method string, col Collector, toStatusCode func(error) string, f func(context.Context) error) error

CollectedRequest runs a tracked request. It uses the given Collector to monitor requests.

If `f` returns no error we log "200" as status code, otherwise "500". Pass in a function for `toStatusCode` to overwrite this behaviour. It will also emit an OpenTracing span if you have a global tracer configured.

func ErrorCode

func ErrorCode(err error) string

ErrorCode converts an error into an HTTP status code

func TimeRequestHistogram deprecated

func TimeRequestHistogram(ctx oldcontext.Context, method string, metric *prometheus.HistogramVec, f func(context.Context) error) error

TimeRequestHistogram runs 'f' and records how long it took in the given Prometheus histogram metric. If 'f' returns successfully, record a "200". Otherwise, record "500". It will also emit an OpenTracing span if you have a global tracer configured.

Deprecated: Use CollectedRequest()

func TimeRequestHistogramStatus deprecated

func TimeRequestHistogramStatus(ctx oldcontext.Context, method string, metric *prometheus.HistogramVec, toStatusCode func(error) string, f func(context.Context) error) error

TimeRequestHistogramStatus runs 'f' and records how long it took in the given Prometheus histogram metric. If 'f' returns successfully, record a "200". Otherwise, record "500". It will also emit an OpenTracing span if you have a global tracer configured.

Deprecated: Use CollectedRequest()

Types

type Collector

type Collector interface {
	Register()
	Before(method string, start time.Time)
	After(method, statusCode string, start time.Time)
}

Collector describes something that collects data before and/or after a task.

type HistogramCollector

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

HistogramCollector collects the duration of a request

func NewHistogramCollector

func NewHistogramCollector(metric *prometheus.HistogramVec) *HistogramCollector

NewHistogramCollector creates a Collector from a metric.

func NewHistogramCollectorFromOpts

func NewHistogramCollectorFromOpts(opts prometheus.HistogramOpts) *HistogramCollector

NewHistogramCollectorFromOpts creates a Collector from histogram options. It makes sure that the buckets are named properly and should be preferred over NewHistogramCollector().

func (*HistogramCollector) After

func (c *HistogramCollector) After(method, statusCode string, start time.Time)

After collects when the request is done.

func (*HistogramCollector) Before

func (c *HistogramCollector) Before(method string, start time.Time)

Before collects for the upcoming request.

func (*HistogramCollector) Register

func (c *HistogramCollector) Register()

Register registers metrics.

type JobCollector

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

JobCollector collects metrics for jobs. Designed for batch jobs which run on a regular, not-too-frequent, non-overlapping interval. We can afford to measure duration directly with gauges, and compute quantile with quantile_over_time.

func NewJobCollector

func NewJobCollector(namespace string) *JobCollector

NewJobCollector instantiates JobCollector which creates its metrics.

func (*JobCollector) After

func (c *JobCollector) After(method, statusCode string, start time.Time)

After collects when the request is done.

func (*JobCollector) Before

func (c *JobCollector) Before(method string, start time.Time)

Before collects for the upcoming request.

func (*JobCollector) Register

func (c *JobCollector) Register()

Register registers metrics.

Source Files

Jump to

Keyboard shortcuts

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