go.opencensus.io: go.opencensus.io/metric Index | Examples | Files | Directories

package metric

import "go.opencensus.io/metric"

Package metric support for gauge metrics.

This is an EXPERIMENTAL package, and may change in arbitrary ways without notice.

Index

Examples

Package Files

doc.go error_const.go gauge.go registry.go

type Float64DerivedGauge Uses

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

Float64DerivedGauge represents float64 gauge value that is derived from an object.

Float64DerivedGauge maintains objects for each combination of label values. These objects implement Float64DerivedGaugeInterface to read instantaneous value representing the object.

func (*Float64DerivedGauge) UpsertEntry Uses

func (g *Float64DerivedGauge) UpsertEntry(fn func() float64, labelVals ...metricdata.LabelValue) error

UpsertEntry inserts or updates a derived gauge entry for the given set of label values. The object for which this gauge entry is inserted or updated, must implement func() float64

It returns an error if 1. The number of label values supplied are not the same as the number of keys supplied when this gauge was created. 2. fn func() float64 is nil.

type Float64Entry Uses

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

Float64Entry represents a single value of the gauge corresponding to a set of label values.

func (*Float64Entry) Add Uses

func (e *Float64Entry) Add(val float64)

Add increments the gauge entry value by val.

func (*Float64Entry) Set Uses

func (e *Float64Entry) Set(val float64)

Set sets the gauge entry value to val.

type Float64Gauge Uses

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

Float64Gauge represents a float64 value that can go up and down.

Float64Gauge maintains a float64 value for each combination of of label values passed to the Set or Add methods.

func (*Float64Gauge) GetEntry Uses

func (g *Float64Gauge) GetEntry(labelVals ...metricdata.LabelValue) (*Float64Entry, error)

GetEntry returns a gauge entry where each key for this gauge has the value given.

The number of label values supplied must be exactly the same as the number of keys supplied when this gauge was created.

type Int64DerivedGauge Uses

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

Int64DerivedGauge represents int64 gauge value that is derived from an object.

Int64DerivedGauge maintains objects for each combination of label values. These objects implement Int64DerivedGaugeInterface to read instantaneous value representing the object.

func (*Int64DerivedGauge) UpsertEntry Uses

func (g *Int64DerivedGauge) UpsertEntry(fn func() int64, labelVals ...metricdata.LabelValue) error

UpsertEntry inserts or updates a derived gauge entry for the given set of label values. The object for which this gauge entry is inserted or updated, must implement func() int64

It returns an error if 1. The number of label values supplied are not the same as the number of keys supplied when this gauge was created. 2. fn func() int64 is nil.

type Int64Gauge Uses

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

Int64Gauge represents a int64 gauge value that can go up and down.

Int64Gauge maintains an int64 value for each combination of label values passed to the Set or Add methods.

func (*Int64Gauge) GetEntry Uses

func (g *Int64Gauge) GetEntry(labelVals ...metricdata.LabelValue) (*Int64GaugeEntry, error)

GetEntry returns a gauge entry where each key for this gauge has the value given.

The number of label values supplied must be exactly the same as the number of keys supplied when this gauge was created.

type Int64GaugeEntry Uses

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

Int64GaugeEntry represents a single value of the gauge corresponding to a set of label values.

func (*Int64GaugeEntry) Add Uses

func (e *Int64GaugeEntry) Add(val int64)

Add increments the current gauge entry value by val, which may be negative.

func (*Int64GaugeEntry) Set Uses

func (e *Int64GaugeEntry) Set(val int64)

Set sets the value of the gauge entry to the provided value.

type Registry Uses

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

Registry creates and manages a set of gauges. External synchronization is required if you want to add gauges to the same registry from multiple goroutines.

func NewRegistry Uses

func NewRegistry() *Registry

NewRegistry initializes a new Registry.

func (*Registry) AddFloat64DerivedGauge Uses

func (r *Registry) AddFloat64DerivedGauge(name, description string, unit metricdata.Unit, labelKeys ...string) (*Float64DerivedGauge, error)

AddFloat64DerivedGauge creates and adds a new derived float64-valued gauge to this registry. A derived gauge is convenient form of gauge where the object associated with the gauge provides its value by implementing func() float64.

func (*Registry) AddFloat64Gauge Uses

func (r *Registry) AddFloat64Gauge(name, description string, unit metricdata.Unit, labelKeys ...string) (*Float64Gauge, error)

AddFloat64Gauge creates and adds a new float64-valued gauge to this registry.

func (*Registry) AddInt64DerivedGauge Uses

func (r *Registry) AddInt64DerivedGauge(name, description string, unit metricdata.Unit, labelKeys ...string) (*Int64DerivedGauge, error)

AddInt64DerivedGauge creates and adds a new derived int64-valued gauge to this registry. A derived gauge is convenient form of gauge where the object associated with the gauge provides its value by implementing func() int64.

func (*Registry) AddInt64Gauge Uses

func (r *Registry) AddInt64Gauge(name, description string, unit metricdata.Unit, labelKeys ...string) (*Int64Gauge, error)

AddInt64Gauge creates and adds a new int64-valued gauge to this registry.

Code:

r := metric.NewRegistry()
// TODO: allow exporting from a registry

g, _ := r.AddInt64Gauge("active_request", "Number of active requests, per method.", metricdata.UnitDimensionless, "method")

http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
    e, _ := g.GetEntry(metricdata.NewLabelValue(request.Method))
    e.Add(1)
    defer e.Add(-1)
    // process request ...
})

func (*Registry) Read Uses

func (r *Registry) Read() []*metricdata.Metric

Read reads all gauges in this registry and returns their values as metrics.

Directories

PathSynopsis
metricdataPackage metricdata contains the metrics data model.
metricexportPackage metricexport contains support for exporting metric data.

Package metric imports 7 packages (graph). Updated 2019-03-19. Refresh now. Tools for package owners.