package stats

Import Path
	go.opencensus.io/stats (on go.dev)

Dependency Relation
	imports 6 packages, and imported by 12 packages

Involved Source Files Package stats contains support for OpenCensus stats recording. OpenCensus allows users to create typed measures, record measurements, aggregate the collected data, and export the aggregated data. Measures A measure represents a type of data point to be tracked and recorded. For example, latency, request Mb/s, and response Mb/s are measures to collect from a server. Measure constructors such as Int64 and Float64 automatically register the measure by the given name. Each registered measure needs to be unique by name. Measures also have a description and a unit. Libraries can define and export measures. Application authors can then create views and collect and break down measures by the tags they are interested in. Recording measurements Measurement is a data point to be collected for a measure. For example, for a latency (ms) measure, 100 is a measurement that represents a 100ms latency event. Measurements are created from measures with the current context. Tags from the current context are recorded with the measurements if they are any. Recorded measurements are dropped immediately if no views are registered for them. There is usually no need to conditionally enable and disable recording to reduce cost. Recording of measurements is cheap. Libraries can always record measurements, and applications can later decide on which measurements they want to collect by registering views. This allows libraries to turn on the instrumentation by default. Exemplars For a given recorded measurement, the associated exemplar is a diagnostic map that gives more information about the measurement. When aggregated using a Distribution aggregation, an exemplar is kept for each bucket in the Distribution. This allows you to easily find an example of a measurement that fell into each bucket. For example, if you also use the OpenCensus trace package and you record a measurement with a context that contains a sampled trace span, then the trace span will be added to the exemplar associated with the measurement. When exported to a supporting back end, you should be able to easily navigate to example traces that fell into each bucket in the Distribution. measure.go measure_float64.go measure_int64.go record.go units.go
Code Examples package main import ( "context" "go.opencensus.io/stats" ) func main() { ctx := context.Background() // Measures are usually declared as package-private global variables. openConns := stats.Int64("example.com/measure/openconns", "open connections", stats.UnitDimensionless) // Instrumented packages call stats.Record() to record measuremens. stats.Record(ctx, openConns.M(124)) // Record 124 open connections. // Without any views or exporters registered, this statement has no observable effects. }
Package-Level Type Names (total 8, in which 6 are exported)
/* sort exporteds by: | */
Float64Measure is a measure for float64 values. Description returns the description of the measure. M creates a new float64 measurement. Use Record to record measurements. Name returns the name of the measure. Unit returns the unit of the measure. *T : Measure func Float64(name, description, unit string) *Float64Measure var go.opencensus.io/plugin/ocgrpc.ClientRoundtripLatency *Float64Measure var go.opencensus.io/plugin/ocgrpc.ClientServerLatency *Float64Measure var go.opencensus.io/plugin/ocgrpc.ServerLatency *Float64Measure var go.opencensus.io/plugin/ochttp.ClientLatency *Float64Measure var go.opencensus.io/plugin/ochttp.ClientRoundtripLatency *Float64Measure var go.opencensus.io/plugin/ochttp.ServerLatency *Float64Measure var contrib.go.opencensus.io/integrations/ocsql.MeasureLatencyMs *Float64Measure var contrib.go.opencensus.io/integrations/ocsql.MeasureWaitDuration *Float64Measure
Int64Measure is a measure for int64 values. Description returns the description of the measure. M creates a new int64 measurement. Use Record to record measurements. Name returns the name of the measure. Unit returns the unit of the measure. *T : Measure func Int64(name, description, unit string) *Int64Measure var go.opencensus.io/plugin/ocgrpc.ClientReceivedBytesPerRPC *Int64Measure var go.opencensus.io/plugin/ocgrpc.ClientReceivedMessagesPerRPC *Int64Measure var go.opencensus.io/plugin/ocgrpc.ClientSentBytesPerRPC *Int64Measure var go.opencensus.io/plugin/ocgrpc.ClientSentMessagesPerRPC *Int64Measure var go.opencensus.io/plugin/ocgrpc.ServerReceivedBytesPerRPC *Int64Measure var go.opencensus.io/plugin/ocgrpc.ServerReceivedMessagesPerRPC *Int64Measure var go.opencensus.io/plugin/ocgrpc.ServerSentBytesPerRPC *Int64Measure var go.opencensus.io/plugin/ocgrpc.ServerSentMessagesPerRPC *Int64Measure var go.opencensus.io/plugin/ochttp.ClientReceivedBytes *Int64Measure var go.opencensus.io/plugin/ochttp.ClientRequestBytes *Int64Measure var go.opencensus.io/plugin/ochttp.ClientRequestCount *Int64Measure var go.opencensus.io/plugin/ochttp.ClientResponseBytes *Int64Measure var go.opencensus.io/plugin/ochttp.ClientSentBytes *Int64Measure var go.opencensus.io/plugin/ochttp.ServerRequestBytes *Int64Measure var go.opencensus.io/plugin/ochttp.ServerRequestCount *Int64Measure var go.opencensus.io/plugin/ochttp.ServerResponseBytes *Int64Measure var contrib.go.opencensus.io/integrations/ocsql.MeasureActiveConnections *Int64Measure var contrib.go.opencensus.io/integrations/ocsql.MeasureIdleClosed *Int64Measure var contrib.go.opencensus.io/integrations/ocsql.MeasureIdleConnections *Int64Measure var contrib.go.opencensus.io/integrations/ocsql.MeasureLifetimeClosed *Int64Measure var contrib.go.opencensus.io/integrations/ocsql.MeasureOpenConnections *Int64Measure var contrib.go.opencensus.io/integrations/ocsql.MeasureWaitCount *Int64Measure
Measure represents a single numeric value to be tracked and recorded. For example, latency, request bytes, and response bytes could be measures to collect from a server. Measures by themselves have no outside effects. In order to be exported, the measure needs to be used in a View. If no Views are defined over a measure, there is very little cost in recording it. Description returns the human-readable description of this measure. Name returns the name of this measure. Measure names are globally unique (among all libraries linked into your program). We recommend prefixing the measure name with a domain name relevant to your project or application. Measure names are never sent over the wire or exported to backends. They are only used to create Views. Unit returns the units for the values this measure takes on. Units are encoded according to the case-sensitive abbreviations from the Unified Code for Units of Measure: http://unitsofmeasure.org/ucum.html *Float64Measure *Int64Measure func Measurement.Measure() Measure
Measurement is the numeric value measured when recording stats. Each measure provides methods to create measurements of their kind. For example, Int64Measure provides M to convert an int64 into a measurement. Measure returns the Measure from which this Measurement was created. Value returns the value of the Measurement as a float64. func (*Float64Measure).M(v float64) Measurement func (*Int64Measure).M(v int64) Measurement func Record(ctx context.Context, ms ...Measurement) func RecordWithTags(ctx context.Context, mutators []tag.Mutator, ms ...Measurement) error func WithMeasurements(measurements ...Measurement) Options func golang.org/x/pkgsite/internal/dcensus.RecordWithTag(ctx context.Context, key tag.Key, val string, m Measurement)
Options apply changes to recordOptions. func WithAttachments(attachments metricdata.Attachments) Options func WithMeasurements(measurements ...Measurement) Options func WithRecorder(meter Recorder) Options func WithTags(mutators ...tag.Mutator) Options func RecordWithOptions(ctx context.Context, ros ...Options) error
Recorder provides an interface for exporting measurement information from the static Record method by using the WithRecorder option. Record records a set of measurements associated with the given tags and attachments. The second argument is a `[]Measurement`. go.opencensus.io/stats/view.Meter (interface) func WithRecorder(meter Recorder) Options
Package-Level Functions (total 12, in which 9 are exported)
Float64 creates a new measure for float64 values. See the documentation for interface Measure for more guidance on the parameters of this function.
Int64 creates a new measure for int64 values. See the documentation for interface Measure for more guidance on the parameters of this function.
Record records one or multiple measurements with the same context at once. If there are any tags in the context, measurements will be tagged with them.
RecordWithOptions records measurements from the given options (if any) against context and tags and attachments in the options (if any). If there are any tags in the context, measurements will be tagged with them.
RecordWithTags records one or multiple measurements at once. Measurements will be tagged with the tags in the context mutated by the mutators. RecordWithTags is useful if you want to record with tag mutations but don't want to propagate the mutations in the context.
WithAttachments applies provided exemplar attachments.
WithMeasurements applies provided measurements.
WithRecorder records the measurements to the specified `Recorder`, rather than to the global metrics recorder.
WithTags applies provided tag mutators.
Package-Level Variables (total 2, neither is exported)
Package-Level Constants (total 5, all are exported)
Units are encoded according to the case-sensitive abbreviations from the Unified Code for Units of Measure: http://unitsofmeasure.org/ucum.html
Units are encoded according to the case-sensitive abbreviations from the Unified Code for Units of Measure: http://unitsofmeasure.org/ucum.html
Units are encoded according to the case-sensitive abbreviations from the Unified Code for Units of Measure: http://unitsofmeasure.org/ucum.html
Units are encoded according to the case-sensitive abbreviations from the Unified Code for Units of Measure: http://unitsofmeasure.org/ucum.html
Units are encoded according to the case-sensitive abbreviations from the Unified Code for Units of Measure: http://unitsofmeasure.org/ucum.html