luci: go.chromium.org/luci/common/tsmon/metric Index | Files

package metric

import "go.chromium.org/luci/common/tsmon/metric"

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. Additionally, you can specify the target type of the metric. It is an error to define two metrics with the same and target type. It will cause a panic if there are duplicated metrics.

When setting metric values, you must pass correct number of fields, with correct types, or the setter function will panic.

Example:

var (
  requests = metric.NewCounterWithTargetType("myapp/requests",
    "Number of requests",
    nil,
    field.String("status"),
    types.TaskType),
)
...
func handleRequest() {
  if success {
    requests.Add(1, "success")
  } else {
    requests.Add(1, "failure")
  }
}

Index

Package Files

http_transport.go metric.go standard_metrics.go

func InstrumentTransport Uses

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 Uses

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 Uses

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.

type Bool Uses

type Bool interface {
    types.Metric

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

Bool is a boolean-valued metric.

func NewBool Uses

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

NewBool returns a new bool-valued metric.

func NewBoolWithTargetType Uses

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

NewBoolWithTargetType returns a new bool-valued metric with a given TargetType.

type Counter Uses

type Counter interface {
    Int

    Add(c context.Context, n int64, fieldVals ...interface{})
}

Counter is a cumulative integer metric.

func NewCounter Uses

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

NewCounter returns a new cumulative integer metric.

func NewCounterWithTargetType Uses

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

NewCounterWithTargetType returns a new cumulative integer metric with a given TargetType.

type CumulativeDistribution Uses

type CumulativeDistribution interface {
    NonCumulativeDistribution

    Add(c context.Context, v float64, fieldVals ...interface{})
}

CumulativeDistribution is a cumulative-distribution-valued metric.

func NewCumulativeDistribution Uses

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

NewCumulativeDistribution returns a new cumulative-distribution-valued metric.

func NewCumulativeDistributionWithTargetType Uses

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

NewCumulativeDistributionWithTargetType returns a new cumulative-distribution-valued metric with a given TargetType

type Float Uses

type Float interface {
    types.Metric

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

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

func NewFloat Uses

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

NewFloat returns a new non-cumulative floating-point gauge metric.

func NewFloatWithTargetType Uses

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

NewFloatWithTargetType returns a new non-cumulative floating-point gauge metric with a given TargetType.

type FloatCounter Uses

type FloatCounter interface {
    Float

    Add(c context.Context, n float64, fieldVals ...interface{})
}

FloatCounter is a cumulative floating-point metric.

func NewFloatCounter Uses

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

NewFloatCounter returns a new cumulative floating-point metric.

func NewFloatCounterWithTargetType Uses

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

NewFloatCounterWithTargetType returns a new cumulative floating-point metric with a given TargetType.

type Int Uses

type Int interface {
    types.Metric

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

Int is a non-cumulative integer gauge metric.

func NewInt Uses

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

NewInt returns a new non-cumulative integer gauge metric.

func NewIntWithTargetType Uses

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

NewIntWithTargetType returns a new non-cumulative integer gauge metric with a given TargetType.

type NonCumulativeDistribution Uses

type NonCumulativeDistribution interface {
    types.DistributionMetric

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

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

func NewNonCumulativeDistribution Uses

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.

func NewNonCumulativeDistributionWithTargetType Uses

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

NewNonCumulativeDistributionWithTargetType returns a new non-cumulative-distribution-valued metric with a given TargetType.

type String Uses

type String interface {
    types.Metric

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

String is a string-valued metric.

func NewString Uses

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

NewString returns a new string-valued metric.

func NewStringWithTargetType Uses

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

NewStringWithTargetType returns a new string-valued metric with a given TargetType

Package metric imports 15 packages (graph) and is imported by 48 packages. Updated 2019-10-14. Refresh now. Tools for package owners.