Documentation ¶
Overview ¶
Package view contains support for collecting and exposing aggregates over stats.
In order to collect measurements, views need to be defined and registered. A view allows recorded measurements to be filtered and aggregated over a time window.
All recorded measurements can be filtered by a list of tags.
OpenCensus provides several aggregation methods: count, distribution, sum and mean. Count aggregation only counts the number of measurement points. Distribution aggregation provides statistical summary of the aggregated data. Sum distribution sums up the measurement points. Mean provides the mean of the recorded measurements. Aggregations can either happen cumulatively or over an interval.
Users can dynamically create and delete views.
Libraries can export their own views and claim the view names by registering them themselves.
Exporting ¶
Collected and aggregated data can be exported to a metric collection backend by registering its exporter.
Multiple exporters can be registered to upload the data to various different backends. Users need to unregister the exporters once they no longer are needed.
Example ¶
package main import ( "log" "go.opencensus.io/stats" "go.opencensus.io/stats/view" ) func main() { m, _ := stats.Int64("my.org/measure/openconns", "open connections", "") if err := view.Subscribe(&view.View{ Name: "my.org/views/openconns", Description: "open connections", Measure: m, Aggregation: view.DistributionAggregation{0, 1000, 2000}, }); err != nil { log.Fatal(err) } // Use stats.RegisterExporter to export collected data. }
Output:
Index ¶
- func Register(_ *View) errordeprecated
- func RegisterExporter(e Exporter)
- func SetReportingPeriod(d time.Duration)
- func Subscribe(views ...*View) error
- func Unregister(_ *View) errordeprecated
- func UnregisterExporter(e Exporter)
- func Unsubscribe(views ...*View)
- type Aggregation
- type AggregationData
- type CountAggregation
- type CountData
- type Data
- type DistributionAggregation
- type DistributionData
- type Exporter
- type MeanAggregation
- type MeanData
- type Row
- type SumAggregation
- type SumData
- type View
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterExporter ¶
func RegisterExporter(e Exporter)
RegisterExporter registers an exporter. Collected data will be reported via all the registered exporters. Once you no longer want data to be exported, invoke UnregisterExporter with the previously registered exporter.
func SetReportingPeriod ¶
SetReportingPeriod sets the interval between reporting aggregated views in the program. If duration is less than or equal to zero, it enables the default behavior.
func Subscribe ¶ added in v0.4.0
Subscribe begins collecting data for the given views. Once a view is subscribed, it reports data to the registered exporters.
func Unregister
deprecated
func UnregisterExporter ¶
func UnregisterExporter(e Exporter)
UnregisterExporter unregisters an exporter.
func Unsubscribe ¶ added in v0.4.0
func Unsubscribe(views ...*View)
Unsubscribe the given views. Data will not longer be exported for these views after Unsubscribe returns.
Types ¶
type Aggregation ¶
type Aggregation interface {
// contains filtered or unexported methods
}
Aggregation represents a data aggregation method. There are several aggregation methods made available in the package such as CountAggregation, SumAggregation, MeanAggregation and DistributionAggregation.
type AggregationData ¶
type AggregationData interface {
// contains filtered or unexported methods
}
AggregationData represents an aggregated value from a collection. They are reported on the view data during exporting. Mosts users won't directly access aggregration data.
type CountAggregation ¶
type CountAggregation struct{}
CountAggregation indicates that data collected and aggregated with this method will be turned into a count value. For example, total number of accepted requests can be aggregated by using CountAggregation.
type CountData ¶
type CountData int64
CountData is the aggregated data for a CountAggregation. A count aggregation processes data and counts the recordings.
Most users won't directly access count data.
type Data ¶
A Data is a set of rows about usage of the single measure associated with the given view. Each row is specific to a unique set of tags.
type DistributionAggregation ¶
type DistributionAggregation []float64
DistributionAggregation indicates that the desired aggregation is a histogram distribution. An distribution aggregation may contain a histogram of the values in the population. The bucket boundaries for that histogram are described by DistributionAggregation slice. This defines length+1 buckets.
If length >= 2 then the boundaries for bucket index i are:
[-infinity, bounds[i]) for i = 0 [bounds[i-1], bounds[i]) for 0 < i < length [bounds[i-1], +infinity) for i = length
If length is 0 then there is no histogram associated with the distribution. There will be a single bucket with boundaries (-infinity, +infinity).
If length is 1 then there is no finite buckets, and that single element is the common boundary of the overflow and underflow buckets.
type DistributionData ¶
type DistributionData struct { Count int64 // number of data points aggregated Min float64 // minimum value in the distribution Max float64 // max value in the distribution Mean float64 // mean of the distribution SumOfSquaredDev float64 // sum of the squared deviation from the mean CountPerBucket []int64 // number of occurrences per bucket // contains filtered or unexported fields }
DistributionData is the aggregated data for an DistributionAggregation.
Most users won't directly access distribution data.
func (*DistributionData) Sum ¶
func (a *DistributionData) Sum() float64
Sum returns the sum of all samples collected.
type Exporter ¶
type Exporter interface {
ExportView(viewData *Data)
}
Exporter exports the collected records as view data.
The ExportView method should return quickly; if an Exporter takes a significant amount of time to process a Data, that work should be done on another goroutine.
The Data should not be modified.
type MeanAggregation ¶
type MeanAggregation struct{}
MeanAggregation indicates that collect and aggregate data and maintain the mean value. For example, average latency in milliseconds can be aggregated by using MeanAggregation.
type MeanData ¶
type MeanData struct { Count int64 // number of data points aggregated Mean float64 // mean of all data points }
MeanData is the aggregated data for a MeanAggregation. A mean aggregation processes data and maintains the mean value.
Most users won't directly access mean data.
type Row ¶
type Row struct { Tags []tag.Tag Data AggregationData }
Row is the collected value for a specific set of key value pairs a.k.a tags.
func RetrieveData ¶ added in v0.4.0
type SumAggregation ¶
type SumAggregation struct{}
SumAggregation indicates that data collected and aggregated with this method will be summed up. For example, accumulated request bytes can be aggregated by using SumAggregation.
type SumData ¶
type SumData float64
SumData is the aggregated data for a SumAggregation. A sum aggregation processes data and sums up the recordings.
Most users won't directly access sum data.
type View ¶
type View struct { Name string // Name of View. Must be unique. If unset, will default to the name of the Measure. Description string // Description is a human-readable description for this view. // TagKeys are the tag keys describing the grouping of this view. // A single Row will be produced for each combination of associated tag values. TagKeys []tag.Key // Measure is a stats.Measure to aggregate in this view. Measure stats.Measure // Aggregation is the aggregation function tp apply to the set of Measurements. Aggregation Aggregation }
View allows users to aggregate the recorded stats.Measurements. Views need to be passed to the Subscribe function to be before data will be collected and sent to Exporters.
func Find ¶
Find returns a subscribed view associated with this name. If no subscribed view is found, nil is returned.