metric

package
v0.0.0-...-678bb0e Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package metric is the API for defining metrics and updating their values.

When you define a metric you must also define the names and types of any fields on that metric. It is an error to define two metrics with the same name (this will cause a panic).

Example:

var (
  Requests = metric.NewCounter("myapp/requests", field.String("status"))
)
...
func handleRequest() {
  if success {
    Requests.Add(1, "success")
  } else {
    Requests.Add(1, "failure")
  }
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstrumentTransport

func InstrumentTransport(ctx context.Context, base http.RoundTripper, client string) http.RoundTripper

InstrumentTransport returns a transport that sends HTTP client metrics via the given context.

If the context has no tsmon initialized (no metrics store installed), returns the original transport unchanged.

func UpdateHTTPMetrics

func UpdateHTTPMetrics(ctx context.Context, name string, client string,
	code int, duration time.Duration, requestBytes int64, responseBytes int64)

UpdateHTTPMetrics updates the metrics for a request to a remote server.

func UpdateServerMetrics

func UpdateServerMetrics(ctx context.Context, name string, code int,
	duration time.Duration, requestBytes int64, responseBytes int64,
	userAgent string)

UpdateServerMetrics updates the metrics for a handled request.

Types

type Bool

type Bool interface {
	types.Metric

	Get(c context.Context, fieldVals ...interface{}) (bool, error)
	Set(c context.Context, v bool, fieldVals ...interface{}) error
}

Bool is a boolean-valued metric.

func NewBool

func NewBool(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Bool

NewBool returns a new bool-valued metric. This will panic if another metric already exists with this name.

func NewBoolIn

func NewBoolIn(c context.Context, name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Bool

NewBoolIn is like NewBool but registers in a given context.

type CallbackBool

type CallbackBool interface {
	types.Metric

	Set(ctx context.Context, v bool, fieldVals ...interface{}) error
}

CallbackBool is a boolean-valued metric whose values can only be set from a callback. Use tsmon.RegisterCallback to add a callback to set the metric's values.

func NewCallbackBool

func NewCallbackBool(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) CallbackBool

NewCallbackBool returns a new bool metric whose value is populated by a callback at collection time.

func NewCallbackBoolIn

func NewCallbackBoolIn(c context.Context, name string, description string, metadata *types.MetricMetadata, fields ...field.Field) CallbackBool

NewCallbackBoolIn is like NewCallbackBool but registers in a given context.

type CallbackDistribution

type CallbackDistribution interface {
	types.DistributionMetric

	Set(ctx context.Context, d *distribution.Distribution, fieldVals ...interface{}) error
}

CallbackDistribution is a non-cumulative-distribution-valued metric whose values can only be set from a callback. Use tsmon.RegisterCallback to add a callback to set the metric's values.

func NewCallbackDistribution

func NewCallbackDistribution(name string, description string, metadata *types.MetricMetadata, bucketer *distribution.Bucketer, fields ...field.Field) CallbackDistribution

NewCallbackDistribution returns a new distribution metric whose value is populated by a callback at collection time.

func NewCallbackDistributionIn

func NewCallbackDistributionIn(c context.Context, name string, description string, metadata *types.MetricMetadata, bucketer *distribution.Bucketer, fields ...field.Field) CallbackDistribution

NewCallbackDistributionIn is like NewCallbackDistribution but registers in a given context.

type CallbackFloat

type CallbackFloat interface {
	types.Metric

	Set(ctx context.Context, v float64, fieldVals ...interface{}) error
}

CallbackFloat is a non-cumulative floating-point gauge metric whose values can only be set from a callback. Use tsmon.RegisterCallback to add a callback to set the metric's values.

func NewCallbackFloat

func NewCallbackFloat(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) CallbackFloat

NewCallbackFloat returns a new float metric whose value is populated by a callback at collection time.

func NewCallbackFloatIn

func NewCallbackFloatIn(c context.Context, name string, description string, metadata *types.MetricMetadata, fields ...field.Field) CallbackFloat

NewCallbackFloatIn is like NewCallbackFloat but registers in a given context.

type CallbackInt

type CallbackInt interface {
	types.Metric

	Set(ctx context.Context, v int64, fieldVals ...interface{}) error
}

CallbackInt is a non-cumulative integer gauge metric whose values can only be set from a callback. Use tsmon.RegisterCallback to add a callback to set the metric's values.

func NewCallbackInt

func NewCallbackInt(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) CallbackInt

NewCallbackInt returns a new integer metric whose value is populated by a callback at collection time.

func NewCallbackIntIn

func NewCallbackIntIn(c context.Context, name string, description string, metadata *types.MetricMetadata, fields ...field.Field) CallbackInt

NewCallbackIntIn is like NewCallbackInt but registers in a given context.

type CallbackString

type CallbackString interface {
	types.Metric

	Set(ctx context.Context, v string, fieldVals ...interface{}) error
}

CallbackString is a string-valued metric whose values can only be set from a callback. Use tsmon.RegisterCallback to add a callback to set the metric's values.

func NewCallbackString

func NewCallbackString(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) CallbackString

NewCallbackString returns a new string metric whose value is populated by a callback at collection time.

func NewCallbackStringIn

func NewCallbackStringIn(c context.Context, name string, description string, metadata *types.MetricMetadata, fields ...field.Field) CallbackString

NewCallbackStringIn is like NewCallbackString but registers in a given context.

type Counter

type Counter interface {
	Int
	Add(c context.Context, n int64, fieldVals ...interface{}) error
}

Counter is a cumulative integer metric.

func NewCounter

func NewCounter(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Counter

NewCounter returns a new cumulative integer metric. This will panic if another metric already exists with this name.

func NewCounterIn

func NewCounterIn(c context.Context, name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Counter

NewCounterIn is like NewCounter but registers in a given context.

type CumulativeDistribution

type CumulativeDistribution interface {
	NonCumulativeDistribution
	Add(c context.Context, v float64, fieldVals ...interface{}) error
}

CumulativeDistribution is a cumulative-distribution-valued metric.

func NewCumulativeDistribution

func NewCumulativeDistribution(name string, description string, metadata *types.MetricMetadata, bucketer *distribution.Bucketer, fields ...field.Field) CumulativeDistribution

NewCumulativeDistribution returns a new cumulative-distribution-valued metric. This will panic if another metric already exists with this name.

func NewCumulativeDistributionIn

func NewCumulativeDistributionIn(c context.Context, name string, description string, metadata *types.MetricMetadata, bucketer *distribution.Bucketer, fields ...field.Field) CumulativeDistribution

NewCumulativeDistributionIn is like NewCumulativeDistribution but registers in a given context.

type Float

type Float interface {
	types.Metric

	Get(c context.Context, fieldVals ...interface{}) (float64, error)
	Set(c context.Context, v float64, fieldVals ...interface{}) error
}

Float is a non-cumulative floating-point gauge metric.

func NewFloat

func NewFloat(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Float

NewFloat returns a new non-cumulative floating-point gauge metric. This will panic if another metric already exists with this name.

func NewFloatIn

func NewFloatIn(c context.Context, name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Float

NewFloatIn is like NewFloat but registers in a given context.

type FloatCounter

type FloatCounter interface {
	Float
	Add(c context.Context, n float64, fieldVals ...interface{}) error
}

FloatCounter is a cumulative floating-point metric.

func NewFloatCounter

func NewFloatCounter(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) FloatCounter

NewFloatCounter returns a new cumulative floating-point metric. This will panic if another metric already exists with this name.

func NewFloatCounterIn

func NewFloatCounterIn(c context.Context, name string, description string, metadata *types.MetricMetadata, fields ...field.Field) FloatCounter

NewFloatCounterIn is like NewFloatCounter but registers in a given context.

type Int

type Int interface {
	types.Metric

	Get(c context.Context, fieldVals ...interface{}) (int64, error)
	Set(c context.Context, v int64, fieldVals ...interface{}) error
}

Int is a non-cumulative integer gauge metric.

func NewInt

func NewInt(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Int

NewInt returns a new non-cumulative integer gauge metric. This will panic if another metric already exists with this name.

func NewIntIn

func NewIntIn(c context.Context, name string, description string, metadata *types.MetricMetadata, fields ...field.Field) Int

NewIntIn is like NewInt but registers in a given context.

type NonCumulativeDistribution

type NonCumulativeDistribution interface {
	types.DistributionMetric

	Get(c context.Context, fieldVals ...interface{}) (*distribution.Distribution, error)
	Set(c context.Context, d *distribution.Distribution, fieldVals ...interface{}) error
}

NonCumulativeDistribution is a non-cumulative-distribution-valued metric.

func NewNonCumulativeDistribution

func NewNonCumulativeDistribution(name string, description string, metadata *types.MetricMetadata, bucketer *distribution.Bucketer, fields ...field.Field) NonCumulativeDistribution

NewNonCumulativeDistribution returns a new non-cumulative-distribution-valued metric. This will panic if another metric already exists with this name.

func NewNonCumulativeDistributionIn

func NewNonCumulativeDistributionIn(c context.Context, name string, description string, metadata *types.MetricMetadata, bucketer *distribution.Bucketer, fields ...field.Field) NonCumulativeDistribution

NewNonCumulativeDistributionIn is like NewNonCumulativeDistribution but registers in a given context.

type String

type String interface {
	types.Metric

	Get(c context.Context, fieldVals ...interface{}) (string, error)
	Set(c context.Context, v string, fieldVals ...interface{}) error
}

String is a string-valued metric.

func NewString

func NewString(name string, description string, metadata *types.MetricMetadata, fields ...field.Field) String

NewString returns a new string-valued metric. This will panic if another metric already exists with this name.

func NewStringIn

func NewStringIn(c context.Context, name string, description string, metadata *types.MetricMetadata, fields ...field.Field) String

NewStringIn is like NewString but registers in a given context.

Jump to

Keyboard shortcuts

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