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 ¶
- type Float64Entry
- type Float64Gauge
- type Int64Gauge
- type Int64GaugeEntry
- type Registry
- func NewRegistry() *Registry
- func (r *Registry) AddFloat64Gauge(name, description string, unit metricdata.Unit, labelKeys ...string) *Float64Gauge
- func (r *Registry) AddInt64Gauge(name, description string, unit metricdata.Unit, labelKeys ...string) *Int64Gauge
- func (r *Registry) ReadAll() []*metricdata.Metric
Examples ¶
Types ¶
type Float64Entry ¶
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 ¶
func (e *Float64Entry) Add(val float64)
Add increments the gauge entry value by val.
func (*Float64Entry) Set ¶
func (e *Float64Entry) Set(val float64)
Set sets the gauge entry value to val.
type Float64Gauge ¶
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 ¶
func (g *Float64Gauge) GetEntry(labelVals ...metricdata.LabelValue) *Float64Entry
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 Int64Gauge ¶
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 ¶
func (g *Int64Gauge) GetEntry(labelVals ...metricdata.LabelValue) *Int64GaugeEntry
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 ¶
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 ¶
func (e *Int64GaugeEntry) Add(val int64)
Add increments the current gauge entry value by val, which may be negative.
func (*Int64GaugeEntry) Set ¶
func (e *Int64GaugeEntry) Set(val int64)
Set sets the value of the gauge entry to the provided value.
type Registry ¶
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 ¶
func NewRegistry() *Registry
NewRegistry initializes a new Registry.
func (*Registry) AddFloat64Gauge ¶
func (r *Registry) AddFloat64Gauge(name, description string, unit metricdata.Unit, labelKeys ...string) *Float64Gauge
AddFloat64Gauge creates and adds a new float64-valued gauge to this registry.
func (*Registry) AddInt64Gauge ¶
func (r *Registry) AddInt64Gauge(name, description string, unit metricdata.Unit, labelKeys ...string) *Int64Gauge
AddInt64Gauge creates and adds a new int64-valued gauge to this registry.
Code:play
Example¶
package main
import (
"net/http"
"go.opencensus.io/metric"
"go.opencensus.io/metric/metricdata"
)
func main() {
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) ReadAll ¶
func (r *Registry) ReadAll() []*metricdata.Metric
ReadAll reads all gauges in this registry and returns their values as metrics.
Source Files ¶
doc.go gauge.go registry.go
Directories ¶
Path | Synopsis |
---|---|
metric/metricdata | Package metricdata contains the metrics data model. |
metric/metricexport | Package metricexport contains support for exporting metric data. |
metric/producer |
- Version
- v0.19.1
- Published
- Mar 4, 2019
- Platform
- js/wasm
- Imports
- 7 packages
- Last checked
- 1 hour ago –
Tools for package owners.