Documentation ¶
Overview ¶
Package metrics implements data types for probes generated data.
Index ¶
- Constants
- func IsString(v Value) bool
- type AtomicInt
- func (i *AtomicInt) Add(val Value) error
- func (i *AtomicInt) AddFloat64(f float64)
- func (i *AtomicInt) AddInt64(ii int64)
- func (i *AtomicInt) Clone() Value
- func (i *AtomicInt) Float64() float64
- func (i *AtomicInt) Inc()
- func (i *AtomicInt) IncBy(delta NumValue)
- func (i *AtomicInt) Int64() int64
- func (i *AtomicInt) String() string
- func (i *AtomicInt) SubtractCounter(lastVal Value) (bool, error)
- type Distribution
- func (d *Distribution) Add(val Value) error
- func (d *Distribution) AddFloat64(f float64)
- func (d *Distribution) AddInt64(i int64)
- func (d *Distribution) AddSample(sample float64)
- func (d *Distribution) Clone() Value
- func (d *Distribution) Data() *DistributionData
- func (d *Distribution) StackdriverTypedValue() *monitoring.TypedValue
- func (d *Distribution) String() string
- func (d *Distribution) SubtractCounter(lastVal Value) (bool, error)
- func (d *Distribution) Verify() error
- type DistributionData
- type EventMetrics
- func (em *EventMetrics) AddLabel(name string, val string) *EventMetrics
- func (em *EventMetrics) AddMetric(name string, val Value) *EventMetrics
- func (em *EventMetrics) Clone() *EventMetrics
- func (em *EventMetrics) Key() string
- func (em *EventMetrics) Label(name string) string
- func (em *EventMetrics) LabelsKeys() []string
- func (em *EventMetrics) Metric(name string) Value
- func (em *EventMetrics) MetricsKeys() []string
- func (em *EventMetrics) String() string
- func (em *EventMetrics) SubtractLast(lastEM *EventMetrics) (*EventMetrics, error)
- func (em *EventMetrics) Update(in *EventMetrics) error
- type Float
- func (f *Float) Add(val Value) error
- func (f *Float) AddFloat64(ff float64)
- func (f *Float) AddInt64(i int64)
- func (f *Float) Clone() Value
- func (f *Float) Float64() float64
- func (f *Float) Inc()
- func (f *Float) IncBy(delta NumValue)
- func (f *Float) Int64() int64
- func (f *Float) String() string
- func (f *Float) SubtractCounter(lastVal Value) (bool, error)
- type Int
- func (i *Int) Add(val Value) error
- func (i *Int) AddFloat64(f float64)
- func (i *Int) AddInt64(ii int64)
- func (i *Int) Clone() Value
- func (i *Int) Float64() float64
- func (i *Int) Inc()
- func (i *Int) IncBy(delta NumValue)
- func (i *Int) Int64() int64
- func (i *Int) String() string
- func (i *Int) SubtractCounter(lastVal Value) (bool, error)
- type Kind
- type Map
- func (m *Map) Add(val Value) error
- func (m *Map) AddFloat64(f float64)
- func (m *Map) AddInt64(i int64)
- func (m *Map) Clone() Value
- func (m *Map) GetKey(key string) NumValue
- func (m *Map) IncKey(key string)
- func (m *Map) IncKeyBy(key string, delta NumValue)
- func (m *Map) Keys() []string
- func (m *Map) String() string
- func (m *Map) SubtractCounter(lastVal Value) (bool, error)
- type NumValue
- type String
- type Value
Constants ¶
const ( // CUMULATIVE metrics accumulate with time and are usually used to // represent counters, e.g. number of requests. CUMULATIVE = iota // GAUGE metrics are used to represent values at a certain point of // time, e.g. pending queries. GAUGE )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AtomicInt ¶
type AtomicInt struct { // If Str is defined, this is method used to convert AtomicInt into a string. Str func(int64) string // contains filtered or unexported fields }
AtomicInt implements NumValue with int64 storage and atomic operations. If concurrency-safety is not a requirement, e.g. for use in already mutex protected map, you could use Int.
func (*AtomicInt) Add ¶
Add adds a Value to the receiver AtomicInt. If Value is not AtomicInt, an error is returned. It's part of the Value interface.
func (*AtomicInt) AddFloat64 ¶
AddFloat64 adds a float64 to the receiver Int.
func (*AtomicInt) Inc ¶
func (i *AtomicInt) Inc()
Inc increments the receiver AtomicInt by one. It's part of the NumValue interface.
func (*AtomicInt) IncBy ¶
IncBy increments the receiver AtomicInt by "delta" NumValue. It's part of the NumValue interface.
func (*AtomicInt) String ¶
String returns the string representation of AtomicInt. It's part of the Value interface.
func (*AtomicInt) SubtractCounter ¶ added in v0.11.3
SubtractCounter subtracts the provided "lastVal". Note that this function is not fully atomic: we first load the values, compare them, and then update the receiver if required. There is a possibility that either receiver, or lastVal may change between loading of the values and updating them. We should still not get negative values though, as we use the snapshots to finally update the value.
type Distribution ¶
type Distribution struct {
// contains filtered or unexported fields
}
Distribution metrics type implements a histogram of values distributed over a set of pre-defined buckets.
func NewDistribution ¶
func NewDistribution(lowerBounds []float64) *Distribution
NewDistribution returns a new distribution container.
func NewDistributionFromProto ¶
func NewDistributionFromProto(distProto *distpb.Dist) (*Distribution, error)
NewDistributionFromProto returns a new distribution based on the provided protobuf.
func NewExponentialDistribution ¶
func NewExponentialDistribution(base, scaleFactor float64, numBuckets int) (*Distribution, error)
NewExponentialDistribution returns a distribution container with exponentially growing bucket sizes. Buckets' lower bounds are determined as follows: -Inf, 0, scale_factor, scale_factor * base, scale_factor * base^2, ... scale_factor * base^(i-1).., ith bucket ... scale_factor * base^(numBuckets), last element (numBuckets+1-th)
func ParseDistFromString ¶
func ParseDistFromString(str string) (*Distribution, error)
ParseDistFromString parses a distribution value from a string that's in a format that's generated by the String() method: Example string: dist:sum:899|count:221|lb:-Inf,0.5,2,7.5|bc:34,54,121,12
func (*Distribution) Add ¶
func (d *Distribution) Add(val Value) error
Add adds a distribution to the receiver distribution. If both distributions don't have the same buckets, an error is returned.
func (*Distribution) AddFloat64 ¶
func (d *Distribution) AddFloat64(f float64)
AddFloat64 adds an float64 to the receiver distribution.
func (*Distribution) AddInt64 ¶
func (d *Distribution) AddInt64(i int64)
AddInt64 adds an int64 to the receiver distribution.
func (*Distribution) AddSample ¶
func (d *Distribution) AddSample(sample float64)
AddSample adds a sample to the receiver distribution.
func (*Distribution) Clone ¶
func (d *Distribution) Clone() Value
Clone returns a copy of the receiver distribution.
func (*Distribution) Data ¶
func (d *Distribution) Data() *DistributionData
Data returns a DistributionData object, built using Distribution's current state.
func (*Distribution) StackdriverTypedValue ¶
func (d *Distribution) StackdriverTypedValue() *monitoring.TypedValue
StackdriverTypedValue returns a Stackdriver typed value corresponding to the receiver distribution. This routine is used by stackdriver surfacer.
func (*Distribution) String ¶
func (d *Distribution) String() string
String returns a string representation of the distribution: "dist:sum:<sum>|count:<count>|lb:<lower bounds>|bc:<bucket counts>" For example for a distribution with lower bounds 0.5, 2.0, 7.5 and bucket counts 34, 54, 121, 12, string representation will look like the following: dist:sum:899|count:221|lb:-Inf,0.5,2,7.5|bc:34,54,121,12
func (*Distribution) SubtractCounter ¶ added in v0.11.3
func (d *Distribution) SubtractCounter(lastVal Value) (bool, error)
SubtractCounter subtracts the provided "lastVal", assuming that value represents a counter, i.e. if "value" is less than "lastVal", we assume that counter has been reset and don't subtract.
func (*Distribution) Verify ¶
func (d *Distribution) Verify() error
Verify verifies that the distribution is valid.
type DistributionData ¶
type DistributionData struct { LowerBounds []float64 // bucket lower bounds BucketCounts []int64 Count int64 // count of all values Sum float64 // sum of all samples. }
DistributionData stuct, along with Data() function, provides a way to readily share the Distribution data with other packages.
type EventMetrics ¶
type EventMetrics struct { Timestamp time.Time Kind Kind LatencyUnit time.Duration // contains filtered or unexported fields }
EventMetrics respresents metrics associated with a particular time event.
func NewEventMetrics ¶
func NewEventMetrics(ts time.Time) *EventMetrics
NewEventMetrics return a new EventMetrics object with internals maps initialized.
func (*EventMetrics) AddLabel ¶
func (em *EventMetrics) AddLabel(name string, val string) *EventMetrics
AddLabel adds a label (name & value) into the receiver EventMetrics. If a label with the same name exists already, new label is ignored. AddLabel returns the receiver EventMetrics to allow for the chaining of these calls, for example:
em := metrics.NewEventMetrics(time.Now()). AddMetric("sent", &prr.sent). AddLabel("ptype", "http"). AddLabel("dst", target)
func (*EventMetrics) AddMetric ¶
func (em *EventMetrics) AddMetric(name string, val Value) *EventMetrics
AddMetric adds a metric (name & value) into the receiver EventMetric. If a metric with the same name exists already, new metric is ignored. AddMetric returns the receiver EventMetrics to allow for the chaining of these calls, for example:
em := metrics.NewEventMetrics(time.Now()). AddMetric("sent", &prr.sent). AddMetric("rcvd", &prr.rcvd). AddMetric("rtt", &prr.rtt)
func (*EventMetrics) Clone ¶
func (em *EventMetrics) Clone() *EventMetrics
Clone clones the underlying fields. This is useful for creating copies of the EventMetrics objects.
func (*EventMetrics) Key ¶ added in v0.11.3
func (em *EventMetrics) Key() string
Key returns a string key that uniquely identifies an eventmetrics.
func (*EventMetrics) Label ¶
func (em *EventMetrics) Label(name string) string
Label returns an EventMetrics label value by name. Label will return a zero-string ("") for a non-existent label.
func (*EventMetrics) LabelsKeys ¶
func (em *EventMetrics) LabelsKeys() []string
LabelsKeys returns the list of all label keys.
func (*EventMetrics) Metric ¶
func (em *EventMetrics) Metric(name string) Value
Metric returns an EventMetrics metric value by name. Metric will return nil for a non-existent metric.
func (*EventMetrics) MetricsKeys ¶
func (em *EventMetrics) MetricsKeys() []string
MetricsKeys returns the list of all metric keys.
func (*EventMetrics) String ¶
func (em *EventMetrics) String() string
String returns the string representation of the EventMetrics. Note that this is compatible with what vmwatcher understands. Example output string: 1519084040 labels=ptype=http sent=62 rcvd=52 resp-code=map:code,200:44,204:8
func (*EventMetrics) SubtractLast ¶ added in v0.11.3
func (em *EventMetrics) SubtractLast(lastEM *EventMetrics) (*EventMetrics, error)
SubtractLast subtracts the provided (last) EventMetrics from the receiver EventMetrics and return the result as a GAUGE EventMetrics.
func (*EventMetrics) Update ¶
func (em *EventMetrics) Update(in *EventMetrics) error
Update updates the receiver EventMetrics with the incoming one.
type Float ¶
type Float struct { // If Str is defined, this is method used to convert Float into a string. Str func(float64) string // contains filtered or unexported fields }
Float implements NumValue with float64 storage. Note that Float is not concurrency safe.
func (*Float) Add ¶
Add adds a Value to the receiver Float. If Value is not Float, an error is returned. It's part of the Value interface.
func (*Float) AddFloat64 ¶
AddFloat64 adds a float64 to the receiver Float.
func (*Float) Inc ¶
func (f *Float) Inc()
Inc increments the receiver Float by one. It's part of the NumValue interface.
func (*Float) IncBy ¶
IncBy increments the receiver Float by "delta" NumValue. It's part of the NumValue interface.
type Int ¶
type Int struct { // If Str is defined, this is method used to convert Int into a string. Str func(int64) string // contains filtered or unexported fields }
Int implements NumValue with int64 storage. Note that Int is not concurrency safe, if you want a concurrency safe integer NumValue, use AtomicInt.
func (*Int) Add ¶
Add adds a Value to the receiver Int. If Value is not Int, an error is returned. It's part of the Value interface.
func (*Int) AddFloat64 ¶
AddFloat64 adds a float64 to the receiver Int.
func (*Int) Inc ¶
func (i *Int) Inc()
Inc increments the receiver Int by one. It's part of the NumValue interface.
func (*Int) IncBy ¶
IncBy increments the receiver Int by "delta" NumValue. It's part of the NumValue interface.
type Kind ¶
type Kind int
Kind represents EventMetrics type. There are currently only two kinds of EventMetrics supported: CUMULATIVE and GAUGE
type Map ¶
type Map struct { MapName string // Map key name // contains filtered or unexported fields }
Map implements a key-value store where keys are of type string and values are of type NumValue. It satisfies the Value interface.
func ParseMapFromString ¶ added in v0.10.3
ParseMapFromString parses a map value string into a map object. Note that the values are always parsed as floats, so even a map with integer values will become a float map. For example: "map:code,200:10123,404:21" will be parsed as: "map:code 200:10123.000 404:21.000".
func (*Map) Add ¶
Add adds a value (type Value) to the receiver Map. A non-Map value returns an error. This is part of the Value interface.
func (*Map) AddFloat64 ¶
AddFloat64 generates a panic for the Map type. This is added only to satisfy the Value interface.
func (*Map) AddInt64 ¶
AddInt64 generates a panic for the Map type. This is added only to satisfy the Value interface.
func (*Map) Clone ¶
Clone creates a clone of the Map. Clone makes sure that underlying data storage is properly cloned.
type NumValue ¶
NumValue represents any numerical metric value, e.g. Int, Float. It's a superset of Value interface.
type String ¶
type String struct {
// contains filtered or unexported fields
}
String implements a value type with string storage. It satisfies the Value interface.
func (String) Add ¶
Add isn't supported for the String type, this is only to satisfy the Value interface.
func (String) AddFloat64 ¶
AddFloat64 generates a panic for the String type. This is added only to satisfy the Value interface.
type Value ¶
type Value interface { Clone() Value Add(delta Value) error AddInt64(i int64) AddFloat64(f float64) String() string // SubtractCounter subtracts the provided "lastVal", assuming that value // represents a counter, i.e. if "value" is less than the "lastVal", we // assume that counter has been reset and don't subtract. SubtractCounter(last Value) (wasReset bool, err error) }
Value represents any metric value
func ParseValueFromString ¶ added in v0.10.6
ParseValueFromString parses a value from its string representation