cloudprober: github.com/google/cloudprober/metrics Index | Files | Directories

package metrics

import "github.com/google/cloudprober/metrics"

Package metrics implements data types for probes generated data.

Index

Package Files

dist.go eventmetrics.go float.go int.go map.go metrics.go string.go

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
)

func IsString Uses

func IsString(v Value) bool

IsString checks if the given value is a string.

type AtomicInt Uses

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 NewAtomicInt Uses

func NewAtomicInt(i int64) *AtomicInt

NewAtomicInt returns a new AtomicInt

func (*AtomicInt) Add Uses

func (i *AtomicInt) Add(val Value) error

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 Uses

func (i *AtomicInt) AddFloat64(f float64)

AddFloat64 adds a float64 to the receiver Int.

func (*AtomicInt) AddInt64 Uses

func (i *AtomicInt) AddInt64(ii int64)

AddInt64 adds an int64 to the receiver Int.

func (*AtomicInt) Clone Uses

func (i *AtomicInt) Clone() Value

Clone returns a copy the receiver AtomicInt

func (*AtomicInt) Float64 Uses

func (i *AtomicInt) Float64() float64

Float64 returns the stored int64 as a float64

func (*AtomicInt) Inc Uses

func (i *AtomicInt) Inc()

Inc increments the receiver AtomicInt by one. It's part of the NumValue interface.

func (*AtomicInt) IncBy Uses

func (i *AtomicInt) IncBy(delta NumValue)

IncBy increments the receiver AtomicInt by "delta" NumValue. It's part of the NumValue interface.

func (*AtomicInt) Int64 Uses

func (i *AtomicInt) Int64() int64

Int64 returns the stored int64

func (*AtomicInt) String Uses

func (i *AtomicInt) String() string

String returns the string representation of AtomicInt. It's part of the Value interface.

type Distribution Uses

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 Uses

func NewDistribution(lowerBounds []float64) *Distribution

NewDistribution returns a new distribution container.

func NewDistributionFromProto Uses

func NewDistributionFromProto(distProto *distpb.Dist) (*Distribution, error)

NewDistributionFromProto returns a new distribution based on the provided protobuf.

func NewExponentialDistribution Uses

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 Uses

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 Uses

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 Uses

func (d *Distribution) AddFloat64(f float64)

AddFloat64 adds an float64 to the receiver distribution.

func (*Distribution) AddInt64 Uses

func (d *Distribution) AddInt64(i int64)

AddInt64 adds an int64 to the receiver distribution.

func (*Distribution) AddSample Uses

func (d *Distribution) AddSample(sample float64)

AddSample adds a sample to the receiver distribution.

func (*Distribution) Clone Uses

func (d *Distribution) Clone() Value

Clone returns a copy of the receiver distribution.

func (*Distribution) Data Uses

func (d *Distribution) Data() *DistributionData

Data returns a DistributionData object, built using Distribution's current state.

func (*Distribution) StackdriverTypedValue Uses

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 Uses

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) Verify Uses

func (d *Distribution) Verify() error

Verify verifies that the distribution is valid.

type DistributionData Uses

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 Uses

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 Uses

func NewEventMetrics(ts time.Time) *EventMetrics

NewEventMetrics return a new EventMetrics object with internals maps initialized.

func (*EventMetrics) AddLabel Uses

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 Uses

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 Uses

func (em *EventMetrics) Clone() *EventMetrics

Clone clones the underlying fields. This is useful for creating copies of the EventMetrics objects.

func (*EventMetrics) Label Uses

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 Uses

func (em *EventMetrics) LabelsKeys() []string

LabelsKeys returns the list of all label keys.

func (*EventMetrics) Metric Uses

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 Uses

func (em *EventMetrics) MetricsKeys() []string

MetricsKeys returns the list of all metric keys.

func (*EventMetrics) String Uses

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) Update Uses

func (em *EventMetrics) Update(in *EventMetrics) error

Update updates the receiver EventMetrics with the incoming one.

type Float Uses

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 NewFloat Uses

func NewFloat(f float64) *Float

NewFloat returns a new Float.

func (*Float) Add Uses

func (f *Float) Add(val Value) error

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 Uses

func (f *Float) AddFloat64(ff float64)

AddFloat64 adds a float64 to the receiver Float.

func (*Float) AddInt64 Uses

func (f *Float) AddInt64(i int64)

AddInt64 adds an int64 to the receiver Float.

func (*Float) Clone Uses

func (f *Float) Clone() Value

Clone returns a copy the receiver Float

func (*Float) Float64 Uses

func (f *Float) Float64() float64

Float64 returns the stored float64.

func (*Float) Inc Uses

func (f *Float) Inc()

Inc increments the receiver Float by one. It's part of the NumValue interface.

func (*Float) IncBy Uses

func (f *Float) IncBy(delta NumValue)

IncBy increments the receiver Float by "delta" NumValue. It's part of the NumValue interface.

func (*Float) Int64 Uses

func (f *Float) Int64() int64

Int64 returns the stored float64 as int64.

func (*Float) String Uses

func (f *Float) String() string

String returns the string representation of Float. It's part of the Value interface.

type Int Uses

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 NewInt Uses

func NewInt(i int64) *Int

NewInt returns a new Int

func (*Int) Add Uses

func (i *Int) Add(val Value) error

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 Uses

func (i *Int) AddFloat64(f float64)

AddFloat64 adds a float64 to the receiver Int.

func (*Int) AddInt64 Uses

func (i *Int) AddInt64(ii int64)

AddInt64 adds an int64 to the receiver Int.

func (*Int) Clone Uses

func (i *Int) Clone() Value

Clone returns a copy the receiver Int

func (*Int) Float64 Uses

func (i *Int) Float64() float64

Float64 returns the stored int64 as a float64

func (*Int) Inc Uses

func (i *Int) Inc()

Inc increments the receiver Int by one. It's part of the NumValue interface.

func (*Int) IncBy Uses

func (i *Int) IncBy(delta NumValue)

IncBy increments the receiver Int by "delta" NumValue. It's part of the NumValue interface.

func (*Int) Int64 Uses

func (i *Int) Int64() int64

Int64 returns the stored int64

func (*Int) String Uses

func (i *Int) String() string

String returns the string representation of Int. It's part of the Value interface.

type Kind Uses

type Kind int

Kind represents EventMetrics type. There are currently only two kinds of EventMetrics supported: CUMULATIVE and GAUGE

type Map Uses

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 NewMap Uses

func NewMap(mapName string, defaultValue NumValue) *Map

NewMap returns a new Map

func ParseMapFromString Uses

func ParseMapFromString(mapValue string) (*Map, error)

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 Uses

func (m *Map) Add(val Value) error

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 Uses

func (m *Map) AddFloat64(f float64)

AddFloat64 generates a panic for the Map type. This is added only to satisfy the Value interface.

func (*Map) AddInt64 Uses

func (m *Map) AddInt64(i int64)

AddInt64 generates a panic for the Map type. This is added only to satisfy the Value interface.

func (*Map) Clone Uses

func (m *Map) Clone() Value

Clone creates a clone of the Map. Clone makes sure that underlying data storage is properly cloned.

func (*Map) GetKey Uses

func (m *Map) GetKey(key string) NumValue

GetKey returns the given key's value. TODO(manugarg): We should probably add a way to get the list of all the keys in the map.

func (*Map) IncKey Uses

func (m *Map) IncKey(key string)

IncKey increments the given key's value by one.

func (*Map) IncKeyBy Uses

func (m *Map) IncKeyBy(key string, delta NumValue)

IncKeyBy increments the given key's value by NumValue.

func (*Map) Keys Uses

func (m *Map) Keys() []string

Keys returns the list of keys

func (*Map) String Uses

func (m *Map) String() string

String returns the string representation of the receiver Map. This is part of the Value interface. map:key,k1:v1,k2:v2

type NumValue Uses

type NumValue interface {
    Value
    Inc()
    Int64() int64
    Float64() float64
    IncBy(delta NumValue)
}

NumValue represents any numerical metric value, e.g. Int, Float. It's a superset of Value interface.

type String Uses

type String struct {
    // contains filtered or unexported fields
}

String implements a value type with string storage. It satisfies the Value interface.

func NewString Uses

func NewString(s string) String

NewString returns a new String with the given string value.

func (String) Add Uses

func (s String) Add(val Value) error

Add isn't supported for the String type, this is only to satisfy the Value interface.

func (String) AddFloat64 Uses

func (s String) AddFloat64(f float64)

AddFloat64 generates a panic for the String type. This is added only to satisfy the Value interface.

func (String) AddInt64 Uses

func (s String) AddInt64(i int64)

AddInt64 generates a panic for the String type. This is added only to satisfy the Value interface.

func (String) Clone Uses

func (s String) Clone() Value

Clone returns the copy of receiver String.

func (String) String Uses

func (s String) String() string

String simply returns the stored string.

type Value Uses

type Value interface {
    Clone() Value
    Add(delta Value) error
    AddInt64(i int64)
    AddFloat64(f float64)
    String() string
}

Value represents any metric value

func ParseValueFromString Uses

func ParseValueFromString(val string) (Value, error)

ParseValueFromString parses a value from its string representation

Directories

PathSynopsis
payloadPackage payload provides utilities to work with the metrics in payload.
payload/proto
proto
testutilsPackage testutils provides utilities for tests.

Package metrics imports 13 packages (graph) and is imported by 92 packages. Updated 2020-12-01. Refresh now. Tools for package owners.