solomon

package
v0.4.11 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderSize = 24

Variables

This section is empty.

Functions

func NewSpackEncoder

func NewSpackEncoder(ctx context.Context, compression CompressionType, metrics *Metrics, opts ...SpackOpts) *spackEncoder

func Rated

func Rated(s interface{})

Rated marks given Solomon metric or vector as rated. Example:

cnt := r.Counter("mycounter")
Rated(cnt)

cntvec := r.CounterVec("mycounter", []string{"mytag"})
Rated(cntvec)

For additional info: https://docs.yandex-team.ru/solomon/data-collection/dataformat/json

func WithTags

func WithTags(tags map[string]string) func(*MetricsOpts)

func WithTimestamp

func WithTimestamp(t time.Time) func(*MetricsOpts)

func WithUseNameTag

func WithUseNameTag() func(*MetricsOpts)

func WithVersion12

func WithVersion12() func(*spackEncoder)

Types

type CompressionType

type CompressionType uint8
const (
	CompressionNone CompressionType = 0x0
	CompressionZlib CompressionType = 0x1
	CompressionZstd CompressionType = 0x2
	CompressionLz4  CompressionType = 0x3
)

type Counter

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

Counter tracks monotonically increasing value.

func (*Counter) Add

func (c *Counter) Add(delta int64)

Add adds delta to the counter. Delta must be >=0.

func (*Counter) Inc

func (c *Counter) Inc()

Inc increments counter by 1.

func (*Counter) MarshalJSON

func (c *Counter) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Counter) Name

func (c *Counter) Name() string

func (*Counter) Snapshot

func (c *Counter) Snapshot() Metric

Snapshot returns independent copy on metric.

type CounterVec

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

CounterVec stores counters and implements metrics.CounterVec interface.

func (*CounterVec) Reset

func (v *CounterVec) Reset()

Reset deletes all metrics in this vector.

func (*CounterVec) With

func (v *CounterVec) With(tags map[string]string) metrics.Counter

With creates new or returns existing counter with given tags from vector. It will panic if tags keys set is not equal to vector labels.

type DurationHistogramVec

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

DurationHistogramVec stores duration histograms and implements metrics.TimerVec interface.

func (*DurationHistogramVec) Reset

func (v *DurationHistogramVec) Reset()

Reset deletes all metrics in this vector.

func (*DurationHistogramVec) With

func (v *DurationHistogramVec) With(tags map[string]string) metrics.Timer

With creates new or returns existing duration histogram with given tags from vector. It will panic if tags keys set is not equal to vector labels.

type FuncCounter

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

FuncCounter tracks int64 value returned by function.

func (*FuncCounter) Function

func (c *FuncCounter) Function() func() int64

func (*FuncCounter) MarshalJSON

func (c *FuncCounter) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*FuncCounter) Name

func (c *FuncCounter) Name() string

func (*FuncCounter) Snapshot

func (c *FuncCounter) Snapshot() Metric

Snapshot returns independent copy on metric.

type FuncGauge

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

FuncGauge tracks float64 value returned by function.

func (*FuncGauge) Function

func (g *FuncGauge) Function() func() float64

func (*FuncGauge) MarshalJSON

func (g *FuncGauge) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*FuncGauge) Name

func (g *FuncGauge) Name() string

func (*FuncGauge) Snapshot

func (g *FuncGauge) Snapshot() Metric

Snapshot returns independent copy on metric.

type FuncIntGauge

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

FuncIntGauge tracks int64 value returned by function.

func (*FuncIntGauge) Function

func (g *FuncIntGauge) Function() func() int64

func (*FuncIntGauge) MarshalJSON

func (g *FuncIntGauge) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*FuncIntGauge) Name

func (g *FuncIntGauge) Name() string

func (*FuncIntGauge) Snapshot

func (g *FuncIntGauge) Snapshot() Metric

Snapshot returns independent copy on metric.

type Gauge

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

Gauge tracks single float64 value.

func NewGauge

func NewGauge(name string, value float64, opts ...MetricOpt) Gauge

func (*Gauge) Add

func (g *Gauge) Add(value float64)

func (*Gauge) MarshalJSON

func (g *Gauge) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Gauge) Name

func (g *Gauge) Name() string

func (*Gauge) Set

func (g *Gauge) Set(value float64)

func (*Gauge) Snapshot

func (g *Gauge) Snapshot() Metric

Snapshot returns independent copy of metric.

type GaugeVec

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

GaugeVec stores gauges and implements metrics.GaugeVec interface.

func (*GaugeVec) Reset

func (v *GaugeVec) Reset()

Reset deletes all metrics in this vector.

func (*GaugeVec) With

func (v *GaugeVec) With(tags map[string]string) metrics.Gauge

With creates new or returns existing gauge with given tags from vector. It will panic if tags keys set is not equal to vector labels.

type Histogram

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

func (*Histogram) InitBucketValues

func (h *Histogram) InitBucketValues(bucketValues []int64)

InitBucketValues cleans internal bucketValues and saves new values in order. Length of internal bucketValues stays unchanged. If length of slice in argument bucketValues more than length of internal one, the first extra element of bucketValues is stored in infValue.

func (*Histogram) MarshalJSON

func (h *Histogram) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Histogram) Name

func (h *Histogram) Name() string

func (*Histogram) RecordDuration

func (h *Histogram) RecordDuration(value time.Duration)

func (*Histogram) RecordValue

func (h *Histogram) RecordValue(value float64)

func (*Histogram) Reset

func (h *Histogram) Reset()

func (*Histogram) Snapshot

func (h *Histogram) Snapshot() Metric

Snapshot returns independent copy on metric.

type HistogramVec

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

HistogramVec stores histograms and implements metrics.HistogramVec interface.

func (*HistogramVec) Reset

func (v *HistogramVec) Reset()

Reset deletes all metrics in this vector.

func (*HistogramVec) With

func (v *HistogramVec) With(tags map[string]string) metrics.Histogram

With creates new or returns existing histogram with given tags from vector. It will panic if tags keys set is not equal to vector labels.

type IntGauge

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

IntGauge tracks single float64 value.

func NewIntGauge

func NewIntGauge(name string, value int64, opts ...MetricOpt) IntGauge

func (*IntGauge) Add

func (g *IntGauge) Add(value int64)

func (*IntGauge) MarshalJSON

func (g *IntGauge) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*IntGauge) Name

func (g *IntGauge) Name() string

func (*IntGauge) Set

func (g *IntGauge) Set(value int64)

func (*IntGauge) Snapshot

func (g *IntGauge) Snapshot() Metric

Snapshot returns independent copy of metric.

type IntGaugeVec

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

IntGaugeVec stores gauges and implements metrics.IntGaugeVec interface.

func (*IntGaugeVec) Reset

func (v *IntGaugeVec) Reset()

Reset deletes all metrics in this vector.

func (*IntGaugeVec) With

func (v *IntGaugeVec) With(tags map[string]string) metrics.IntGauge

With creates new or returns existing gauge with given tags from vector. It will panic if tags keys set is not equal to vector labels.

type Metric

type Metric interface {
	json.Marshaler

	Name() string

	Snapshot() Metric
	// contains filtered or unexported methods
}

Metric is an any abstract solomon Metric.

type MetricOpt

type MetricOpt func(*MetricsOpts)

type Metrics

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

func NewMetrics

func NewMetrics(metrics []Metric) Metrics

func NewMetricsWithTimestamp

func NewMetricsWithTimestamp(metrics []Metric, ts time.Time) Metrics

func PrometheusMetrics

func PrometheusMetrics(metrics []*dto.MetricFamily) (*Metrics, error)

PrometheusMetrics converts Prometheus metrics to Solomon metrics.

func (Metrics) List

func (s Metrics) List() []Metric

List return list of metrics

func (Metrics) MarshalBinary

func (s Metrics) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (Metrics) MarshalJSON

func (s Metrics) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (Metrics) SplitToChunks

func (s Metrics) SplitToChunks(maxChunkSize int) []Metrics

SplitToChunks splits Metrics into a slice of chunks, each at most maxChunkSize long. The length of returned slice is always at least one. Zero maxChunkSize denotes unlimited chunk length.

type MetricsOpts

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

type Registry

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

func NewRegistry

func NewRegistry(opts *RegistryOpts) *Registry

func (Registry) ComposeName

func (r Registry) ComposeName(parts ...string) string

ComposeName builds FQ name with appropriate separator.

func (Registry) Counter

func (r Registry) Counter(name string) metrics.Counter

func (*Registry) CounterVec

func (r *Registry) CounterVec(name string, labels []string) metrics.CounterVec

CounterVec creates a new counters vector with given metric name and partitioned by the given label names.

func (Registry) DurationHistogram

func (r Registry) DurationHistogram(name string, buckets metrics.DurationBuckets) metrics.Timer

func (*Registry) DurationHistogramVec

func (r *Registry) DurationHistogramVec(name string, buckets metrics.DurationBuckets, labels []string) metrics.TimerVec

DurationHistogramVec creates a new duration histograms vector with given metric name and buckets and partitioned by the given label names.

func (Registry) FuncCounter

func (r Registry) FuncCounter(name string, function func() int64) metrics.FuncCounter

func (Registry) FuncGauge

func (r Registry) FuncGauge(name string, function func() float64) metrics.FuncGauge

func (Registry) FuncIntGauge

func (r Registry) FuncIntGauge(name string, function func() int64) metrics.FuncIntGauge

func (Registry) Gather

func (r Registry) Gather() (*Metrics, error)

Gather collects all metrics data via snapshots.

func (Registry) Gauge

func (r Registry) Gauge(name string) metrics.Gauge

func (*Registry) GaugeVec

func (r *Registry) GaugeVec(name string, labels []string) metrics.GaugeVec

GaugeVec creates a new gauges vector with given metric name and partitioned by the given label names.

func (Registry) Histogram

func (r Registry) Histogram(name string, buckets metrics.Buckets) metrics.Histogram

func (*Registry) HistogramVec

func (r *Registry) HistogramVec(name string, buckets metrics.Buckets, labels []string) metrics.HistogramVec

HistogramVec creates a new histograms vector with given metric name and buckets and partitioned by the given label names.

func (Registry) IntGauge

func (r Registry) IntGauge(name string) metrics.IntGauge

func (*Registry) IntGaugeVec

func (r *Registry) IntGaugeVec(name string, labels []string) metrics.IntGaugeVec

IntGaugeVec creates a new gauges vector with given metric name and partitioned by the given label names.

func (Registry) Rated

func (r Registry) Rated(rated bool) metrics.Registry

Rated returns copy of registry with rated set to desired value.

func (*Registry) Stream

func (r *Registry) Stream(ctx context.Context, w io.Writer) (written int, err error)

func (*Registry) StreamJSON

func (r *Registry) StreamJSON(ctx context.Context, w io.Writer) (written int, err error)

func (*Registry) StreamSpack

func (r *Registry) StreamSpack(ctx context.Context, w io.Writer, compression CompressionType) (int, error)

func (Registry) Timer

func (r Registry) Timer(name string) metrics.Timer

func (*Registry) TimerVec

func (r *Registry) TimerVec(name string, labels []string) metrics.TimerVec

TimerVec creates a new timers vector with given metric name and partitioned by the given label names.

func (Registry) WithPrefix

func (r Registry) WithPrefix(prefix string) metrics.Registry

WithPrefix creates new sub-scope, where each metric has prefix added to it name.

func (Registry) WithTags

func (r Registry) WithTags(tags map[string]string) metrics.Registry

WithTags creates new sub-scope, where each metric has tags attached to it.

type RegistryOpts

type RegistryOpts struct {
	Separator    rune
	Prefix       string
	Tags         map[string]string
	Rated        bool
	UseNameTag   bool
	Collectors   []func(metrics.Registry)
	StreamFormat StreamFormat
}

func NewRegistryOpts

func NewRegistryOpts() *RegistryOpts

NewRegistryOpts returns new initialized instance of RegistryOpts

func (*RegistryOpts) AddCollectors

func (o *RegistryOpts) AddCollectors(
	ctx context.Context, c metrics.CollectPolicy, collectors ...collect.Func,
) *RegistryOpts

AddCollectors adds collectors that handle their metrics automatically (e.g. system metrics).

func (*RegistryOpts) AddTags

func (o *RegistryOpts) AddTags(tags map[string]string) *RegistryOpts

AddTags merges given tags with existing

func (*RegistryOpts) AppendPrefix

func (o *RegistryOpts) AppendPrefix(prefix string) *RegistryOpts

AppendPrefix adds given prefix as postfix to existing using separator

func (*RegistryOpts) SetPrefix

func (o *RegistryOpts) SetPrefix(prefix string) *RegistryOpts

SetPrefix overrides existing prefix

func (*RegistryOpts) SetRated

func (o *RegistryOpts) SetRated(rated bool) *RegistryOpts

SetRated overrides existing rated flag

func (*RegistryOpts) SetSeparator

func (o *RegistryOpts) SetSeparator(separator rune) *RegistryOpts

SetSeparator overrides existing separator

func (*RegistryOpts) SetStreamFormat

func (o *RegistryOpts) SetStreamFormat(format StreamFormat) *RegistryOpts

SetStreamFormat sets default sensors stream format

func (*RegistryOpts) SetTags

func (o *RegistryOpts) SetTags(tags map[string]string) *RegistryOpts

SetTags overrides existing tags

func (*RegistryOpts) SetUseNameTag

func (o *RegistryOpts) SetUseNameTag(useNameTag bool) *RegistryOpts

SetUseNameTag overrides current UseNameTag opt

type SpackOpts

type SpackOpts func(*spackEncoder)

type StreamFormat

type StreamFormat string
const (
	StreamSpack StreamFormat = "spack"
	StreamJSON  StreamFormat = "json"
)

type Timer

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

Timer measures gauge duration.

func (*Timer) MarshalJSON

func (t *Timer) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Timer) Name

func (t *Timer) Name() string

func (*Timer) RecordDuration

func (t *Timer) RecordDuration(value time.Duration)

func (*Timer) Snapshot

func (t *Timer) Snapshot() Metric

Snapshot returns independent copy on metric.

type TimerVec

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

TimerVec stores timers and implements metrics.TimerVec interface.

func (*TimerVec) Reset

func (v *TimerVec) Reset()

Reset deletes all metrics in this vector.

func (*TimerVec) With

func (v *TimerVec) With(tags map[string]string) metrics.Timer

With creates new or returns existing timer with given tags from vector. It will panic if tags keys set is not equal to vector labels.

Jump to

Keyboard shortcuts

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