Involved Source Filesaggregation.goaggregation_data.gocollector.go
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.
All recorded measurements can be grouped by a list of tags.
OpenCensus provides several aggregation methods: Count, Distribution and Sum.
Count only counts the number of measurement points recorded.
Distribution provides statistical summary of the aggregated data by counting
how many recorded measurements fall into each bucket.
Sum adds up the measurement values.
LastValue just keeps track of the most recently recorded measurement value.
All aggregations are cumulative.
Views can be registered and unregistered at any time during program execution.
Libraries can define views but it is recommended that in most cases registering
views be left up to applications.
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 back ends.
export.goview.goview_to_metric.goworker.goworker_commands.go
Code Examples
package main
import (
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"log"
)
func main() {
// Measures are usually declared and used by instrumented packages.
m := stats.Int64("example.com/measure/openconns", "open connections", stats.UnitDimensionless)
// Views are usually registered in your application main function.
if err := view.Register(&view.View{
Name: "example.com/views/openconns",
Description: "open connections",
Measure: m,
Aggregation: view.Distribution(0, 1000, 2000),
}); err != nil {
log.Fatal(err)
}
// Use view.RegisterExporter to export collected data.
}
Package-Level Type Names (total 25, in which 12 are exported)
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.
Endtime.TimeRows[]*RowStarttime.TimeView*View
func Exporter.ExportView(viewData *Data)
func contrib.go.opencensus.io/exporter/prometheus.(*Exporter).ExportView(vd *Data)
func contrib.go.opencensus.io/exporter/stackdriver.(*Exporter).ExportView(vd *Data)
DistributionData is the aggregated data for the
Distribution aggregation.
Most users won't directly access distribution data.
For a distribution with N bounds, the associated DistributionData will have
N+1 buckets.
// number of data points aggregated
// number of occurrences per bucket
ExemplarsPerBucket is slice the same length as CountPerBucket containing
an exemplar for the associated bucket, or nil.
// max value in the distribution
// mean of the distribution
// minimum value in the distribution
// sum of the squared deviation from the mean
// histogram distribution of the values
Sum returns the sum of all samples collected.
TODO(songy23): support exemplar attachments.
(*T) addToBucket(v float64, attachments map[string]interface{}, t time.Time)(*T) clone() AggregationData(*T) equal(other AggregationData) bool(*T) isAggregationData() bool(*T) toPoint(metricType metricdata.Type, t time.Time) metricdata.Point(*T) variance() float64
*T : AggregationData
func newDistributionData(agg *Aggregation) *DistributionData
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.
It is safe to assume that ExportView will not be called concurrently from
multiple goroutines.
The Data should not be modified.
( T) ExportView(viewData *Data)
*contrib.go.opencensus.io/exporter/prometheus.Exporter
*contrib.go.opencensus.io/exporter/stackdriver.Exporter
go.opencensus.io/zpages.snapExporter
*contrib.go.opencensus.io/exporter/stackdriver.statsExporter
func RegisterExporter(e Exporter)
func UnregisterExporter(e Exporter)
func Meter.RegisterExporter(Exporter)
func Meter.UnregisterExporter(Exporter)
Meter defines an interface which allows a single process to maintain
multiple sets of metrics exports (intended for the advanced case where a
single process wants to report metrics about multiple objects, such as
multiple databases or HTTP services).
Note that this is an advanced use case, and the static functions in this
module should cover the common use cases.
Find returns a registered view associated with this name.
If no registered view is found, nil is returned.
Record records a set of measurements associated with the given tags and attachments.
The second argument is a `[]Measurement`.
Register begins collecting data for the given views.
Once a view is registered, it reports data to the registered exporters.
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.
Binaries can register exporters, libraries shouldn't register exporters.
RetrieveData gets a snapshot of the data collected for the the view registered
with the given name. It is intended for testing only.
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.
Note: each exporter makes different promises about what the lowest supported
duration is. For example, the Stackdriver exporter recommends a value no
lower than 1 minute. Consult each exporter per your needs.
SetResource may be used to set the Resource associated with this registry.
This is intended to be used in cases where a single process exports metrics
for multiple Resources, typically in a multi-tenant situation.
Start causes the Meter to start processing Record calls and aggregating
statistics as well as exporting data.
Stop causes the Meter to stop processing calls and terminate data export.
Unregister the given views. Data will not longer be exported for these views
after Unregister returns.
It is not necessary to unregister from views you expect to collect for the
duration of your program execution.
UnregisterExporter unregisters an exporter.
*worker
T : go.opencensus.io/stats.Recorder
func NewMeter() Meter
Aggregation is the description of the aggregation to perform for this
view.
signatures holds the aggregations values for each unique tag signature
(values for all keys) to its aggregator.
(*T) addSample(s string, v float64, attachments map[string]interface{}, t time.Time)(*T) clearRows()
collectRows returns a snapshot of the collected Row values.
setReportingPeriodReq is the command to modify the duration between
reporting the collected data to the registered clients.
cchan booldtime.Duration(*T) handleCommand(w *worker)
*T : command
unregisterFromViewReq is the command to unregister to a view. Has no
impact on the data collection for client that are pulling data from the
library.
donechan struct{}views[]string(*T) handleCommand(w *worker)
*T : command
cchan commanddonechan boolexportersmap[Exporter]struct{}exportersMusync.RWMutexmeasuresmap[string]*measureRefmusync.RWMutexquitchan boolr*resource.ResourcestartTimesmap[*viewInternal]time.Timetimer*time.Tickerviewsmap[string]*viewInternal
Find returns a registered view associated with this name.
If no registered view is found, nil is returned.
Read reads all view data and returns them as metrics.
It is typically invoked by metric reader to export stats in metric format.
Record records a set of measurements ms associated with the given tags and attachments.
Register begins collecting data for the given views.
Once a view is registered, it reports data to the registered exporters.
(*T) RegisterExporter(e Exporter)
RetrieveData gets a snapshot of the data collected for the the view registered
with the given name. It is intended for testing only.
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.
Note: each exporter makes different promises about what the lowest supported
duration is. For example, the Stackdriver exporter recommends a value no
lower than 1 minute. Consult each exporter per your needs.
SetResource associates all data collected by this Meter with the specified
resource. This resource is reported when using metricexport.ReadAndExport;
it is not provided when used with ExportView/RegisterExporter, because that
interface does not provide a means for reporting the Resource.
(*T) Start()(*T) Stop()
Unregister the given views. Data will not longer be exported for these views
after Unregister returns.
It is not necessary to unregister from views you expect to collect for the
duration of your program execution.
(*T) UnregisterExporter(e Exporter)(*T) getMeasureRef(name string) *measureRef(*T) reportUsage()(*T) reportView(v *viewInternal)(*T) start()(*T) toMetric(v *viewInternal, now time.Time) *metricdata.Metric(*T) tryRegisterView(v *View) (*viewInternal, error)(*T) unregisterView(v *viewInternal)
*T : Meter
*T : go.opencensus.io/stats.Recorder
*T : go.opencensus.io/metric/metricproducer.Producer
var defaultWorker *worker
Package-Level Functions (total 30, in which 12 are exported)
Count 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 Count.
Distribution indicates that the desired aggregation is
a histogram distribution.
A distribution aggregation may contain a histogram of the values in the
population. The bucket boundaries for that histogram are described
by the bounds. This defines len(bounds)+1 buckets.
If len(bounds) >= 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 len(bounds) is 0 then there is no histogram associated with the
distribution. There will be a single bucket with boundaries
(-infinity, +infinity).
If len(bounds) is 1 then there is no finite buckets, and that single
element is the common boundary of the overflow and underflow buckets.
Find returns a registered view associated with this name.
If no registered view is found, nil is returned.
LastValue only reports the last value recorded using this
aggregation. All other measurements will be dropped.
NewMeter constructs a Meter instance. You should only need to use this if
you need to separate out Measurement recordings and View aggregations within
a single process.
Register begins collecting data for the given views.
Once a view is registered, it reports data to the registered exporters.
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.
Binaries can register exporters, libraries shouldn't register exporters.
RetrieveData gets a snapshot of the data collected for the the view registered
with the given name. It is intended for testing only.
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.
Note: each exporter makes different promises about what the lowest supported
duration is. For example, the Stackdriver exporter recommends a value no
lower than 1 minute. Consult each exporter per your needs.
Sum indicates that data collected and aggregated
with this method will be summed up.
For example, accumulated request bytes can be aggregated by using
Sum.
Unregister the given views. Data will not longer be exported for these views
after Unregister returns.
It is not necessary to unregister from views you expect to collect for the
duration of your program execution.
The pages are generated with Goldsv0.3.2-preview. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.