metric

package
v4.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2022 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// GAUGE is a value that may increase and decrease.
	// It generally represents the value for something at a particular moment in time
	GAUGE SourceType = iota
	// COUNT counts the number of times an event occurred since the last time it was retrieved (time window).
	// It's values can go up or down
	COUNT SourceType = iota
	// SUMMARY is a composite value with avg, min, max sample count and sum
	SUMMARY SourceType = iota
	// CUMULATIVE_COUNT counts the number of times an event occurred. It is not a delta, but an absolute value.
	// It's value should either be the same or go up, never down
	CUMULATIVE_COUNT = iota
	// RATE represents a rate of change of a value in a specific time window
	RATE = iota
	// CUMULATIVE_RATE represents an ever-increasing rate of change.
	CUMULATIVE_RATE = iota
	// PROMETHEUS_HISTROGRAM is a histogram as defined by Prometheus
	PROMETHEUS_HISTOGRAM SourceType = iota
	// PROMETHEUS_SUMMARY is a summaru as defined by Prometheus
	PROMETHEUS_SUMMARY SourceType = iota
)

Source types If any more SourceTypes are added update maps: SourcesTypeToName & SourcesNameToType.

Variables

View Source
var SourcesNameToType = map[string]SourceType{
	"gauge":                GAUGE,
	"count":                COUNT,
	"summary":              SUMMARY,
	"cumulative-count":     CUMULATIVE_COUNT,
	"rate":                 RATE,
	"cumulative-rate":      CUMULATIVE_RATE,
	"prometheus-histogram": PROMETHEUS_HISTOGRAM,
	"prometheus-summary":   PROMETHEUS_SUMMARY,
}

SourcesNameToType metric sources list mapping its name to type.

View Source
var SourcesTypeToName = map[SourceType]string{
	GAUGE:                "gauge",
	COUNT:                "count",
	SUMMARY:              "summary",
	CUMULATIVE_COUNT:     "cumulative-count",
	RATE:                 "rate",
	CUMULATIVE_RATE:      "cumulative-rate",
	PROMETHEUS_HISTOGRAM: "prometheus-histogram",
	PROMETHEUS_SUMMARY:   "prometheus-summary",
}

SourcesTypeToName metric sources list mapping its type to readable name.

Functions

This section is empty.

Types

type Dimensions

type Dimensions map[string]string

Dimensions stores the metric dimensions

type Metric

type Metric interface {
	AddDimension(key string, value string) error
	Dimension(key string) string
	GetDimensions() Dimensions
}

Metric is the common interface for all metric types

func NewCount

func NewCount(timestamp time.Time, name string, value float64) (Metric, error)

NewCount creates a new metric of type count

func NewCumulativeCount

func NewCumulativeCount(timestamp time.Time, name string, value float64) (Metric, error)

NewCumulativeCount creates a new metric of type cumulative count

func NewCumulativeRate

func NewCumulativeRate(timestamp time.Time, name string, value float64) (Metric, error)

NewCumulativeRate creates a new metric of type cumulative rate

func NewGauge

func NewGauge(timestamp time.Time, name string, value float64) (Metric, error)

NewGauge creates a new metric of type gauge

func NewRate

func NewRate(timestamp time.Time, name string, value float64) (Metric, error)

NewRate creates a new metric of type rate

func NewSummary

func NewSummary(timestamp time.Time, name string, count float64, average float64, sum float64,
	min float64, max float64) (Metric, error)

NewSummary creates a new metric of type summary

type Metrics

type Metrics []Metric

Metrics is the basic structure for storing metrics.

type PrometheusHistogram

type PrometheusHistogram struct {
	Value PrometheusHistogramValue `json:"value,omitempty"`
	// contains filtered or unexported fields
}

PrometheusHistogram represents a Prometheus histogram

func NewPrometheusHistogram

func NewPrometheusHistogram(timestamp time.Time, name string, sampleCount uint64, sampleSum float64) (*PrometheusHistogram, error)

NewPrometheusHistogram creates a new metric structurally similar to a Prometheus histogram

func (*PrometheusHistogram) AddBucket

func (ph *PrometheusHistogram) AddBucket(cumulativeCount uint64, upperBound float64)

AddBucket adds a new bucket to the histogram. Note that no attempt is made to keep buckets ordered, it's on the caller to guarantee the buckets are added in the correct order.

func (*PrometheusHistogram) AddDimension

func (m *PrometheusHistogram) AddDimension(key string, value string) error

AddDimension adds a dimension to the metric instance

func (*PrometheusHistogram) Dimension

func (m *PrometheusHistogram) Dimension(key string) string

Dimension returns an dimension by key

func (*PrometheusHistogram) GetDimensions

func (m *PrometheusHistogram) GetDimensions() Dimensions

GetDimensions gets all the dimensions

type PrometheusHistogramValue

type PrometheusHistogramValue struct {
	SampleCount *uint64  `json:"sample_count,omitempty"`
	SampleSum   *float64 `json:"sample_sum,omitempty"`
	// Buckets defines the buckets into which observations are counted. Each
	// element in the slice is the upper inclusive bound of a bucket. The
	// values must are sorted in strictly increasing order.
	Buckets []*bucket `json:"buckets,omitempty"`
}

PrometheusHistogramValue represents the Value type for a Prometheus histogram.

type PrometheusSummary

type PrometheusSummary struct {
	Value PrometheusSummaryValue `json:"value,omitempty"`
	// contains filtered or unexported fields
}

PrometheusSummary represents a Prometheus summary

func NewPrometheusSummary

func NewPrometheusSummary(timestamp time.Time, name string, sampleCount uint64, sampleSum float64) (*PrometheusSummary, error)

NewPrometheusSummary creates a new metric structurally similar to a Prometheus summary

func (*PrometheusSummary) AddDimension

func (m *PrometheusSummary) AddDimension(key string, value string) error

AddDimension adds a dimension to the metric instance

func (*PrometheusSummary) AddQuantile

func (ps *PrometheusSummary) AddQuantile(quant float64, value float64)

AddQuantile adds a new quantile to the summary.

func (*PrometheusSummary) Dimension

func (m *PrometheusSummary) Dimension(key string) string

Dimension returns an dimension by key

func (*PrometheusSummary) GetDimensions

func (m *PrometheusSummary) GetDimensions() Dimensions

GetDimensions gets all the dimensions

type PrometheusSummaryValue

type PrometheusSummaryValue struct {
	SampleCount *uint64     `json:"sample_count,omitempty"`
	SampleSum   *float64    `json:"sample_sum,omitempty"`
	Quantiles   []*quantile `json:"quantiles,omitempty"`
}

PrometheusSummaryValue represents the Value type for a Prometheus summary.

type SourceType

type SourceType int

SourceType defines the kind of data source. Based on this SourceType, metric package performs some calculations with it. Check below the description for each one.

func SourceTypeForName

func SourceTypeForName(sourceTypeTag string) (SourceType, error)

SourceTypeForName does a case insensitive conversion from a string to a SourceType. An error will be returned if no valid SourceType matched.

func (SourceType) String

func (t SourceType) String() string

String fulfills stringer interface, returning empty string on invalid source types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL