metrics

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package metrics provides unified way of emitting metrics inside Kopia.

Index

Constants

This section is empty.

Variables

View Source
var CPULatencyThresholds = &Thresholds[time.Duration]{
	[]time.Duration{
		10 * time.Microsecond,
		25 * time.Microsecond,
		50 * time.Microsecond,

		100 * time.Microsecond,
		250 * time.Microsecond,
		500 * time.Microsecond,

		1000 * time.Microsecond,
		2500 * time.Microsecond,
		5000 * time.Microsecond,

		10 * time.Millisecond,
		25 * time.Millisecond,
		50 * time.Millisecond,

		100 * time.Millisecond,
		250 * time.Millisecond,
		500 * time.Millisecond,

		1000 * time.Millisecond,
		2500 * time.Millisecond,
		5000 * time.Millisecond,
	},
	1,
	"_ns",
}

CPULatencyThresholds is a set of thresholds that can represent CPU latencies from 10us to 5s.

View Source
var IOLatencyThresholds = &Thresholds[time.Duration]{
	[]time.Duration{
		500 * time.Microsecond,

		1000 * time.Microsecond,
		2500 * time.Microsecond,
		5000 * time.Microsecond,

		10 * time.Millisecond,
		25 * time.Millisecond,
		50 * time.Millisecond,

		100 * time.Millisecond,
		250 * time.Millisecond,
		500 * time.Millisecond,

		1000 * time.Millisecond,
		2500 * time.Millisecond,
		5000 * time.Millisecond,

		10 * time.Second,
		25 * time.Second,
		50 * time.Second,
	},
	1e6,
	"_ms",
}

IOLatencyThresholds is a set of thresholds that can represent IO latencies from 500us to 50s.

View Source
var ISOBytesThresholds = &Thresholds[int64]{
	[]int64{
		100,
		250,
		500,
		1_000,
		2_500,
		5_000,
		10_000,
		25_000,
		50_000,
		100_000,
		250_000,
		500_000,
		1_000_000,
		2_500_000,
		5_000_000,
		10_000_000,
		25_000_000,
		50_000_000,
		100_000_000,
		250_000_000,
		500_000_000,
	},
	1,
	"",
}

ISOBytesThresholds is a set of thresholds for sizes.

Functions

func AggregateAll added in v0.16.0

func AggregateAll(username, hostname string) string

AggregateAll is an aggregation function that aggregates all data into a single series.

func AggregateByHost added in v0.16.0

func AggregateByHost(username, hostname string) string

AggregateByHost is an aggregation function that aggregates by hostname.

func AggregateByUser added in v0.16.0

func AggregateByUser(username, hostname string) string

AggregateByUser is an aggregation function that aggregates by user@hostname.

func CreateTimeSeries added in v0.16.0

func CreateTimeSeries[TValue any](
	ctx context.Context,
	snapshots []*Snapshot,
	valueHandler SnapshotValueAggregator[TValue],
	opts AggregateMetricsOptions,
) map[string]TimeSeries[TValue]

CreateTimeSeries computes time series which represent aggregations of a given counters or distributions over a set of snapshots.

func TimeResolutionByDay added in v0.16.0

func TimeResolutionByDay(t time.Time) (dayStart, nextDayStart time.Time)

TimeResolutionByDay is a time resolution function that maps given time to a beginning and end of a day.

func TimeResolutionByHour added in v0.16.0

func TimeResolutionByHour(t time.Time) (hourStart, nextHourStart time.Time)

TimeResolutionByHour is a time resolution function that maps given time to a beginning and end of an hour.

func TimeResolutionByMonth added in v0.16.0

func TimeResolutionByMonth(t time.Time) (monthStart, nextMonthStart time.Time)

TimeResolutionByMonth is a time resolution function that maps given time to a beginning and end of a month.

func TimeResolutionByQuarter added in v0.16.0

func TimeResolutionByQuarter(t time.Time) (quarterStart, nextQuarterStart time.Time)

TimeResolutionByQuarter is a time resolution function that maps given time to a beginning and end of a quarter (Q1=Jan-Mar, Q2=Apr-Jun, Q3=Jul-Sep, Q4=Oct-Dec).

func TimeResolutionByWeekStartingMonday added in v0.16.0

func TimeResolutionByWeekStartingMonday(t time.Time) (weekStart, nextWeekStart time.Time)

TimeResolutionByWeekStartingMonday is a time resolution function that maps given time to a beginning and end of a week (starting Sunday).

func TimeResolutionByWeekStartingSunday added in v0.16.0

func TimeResolutionByWeekStartingSunday(t time.Time) (weekStart, nextWeekStart time.Time)

TimeResolutionByWeekStartingSunday is a time resolution function that maps given time to a beginning and end of a week (starting Sunday).

func TimeResolutionByYear added in v0.16.0

func TimeResolutionByYear(t time.Time) (yearStart, nextYearStart time.Time)

TimeResolutionByYear is a time resolution function that maps given time to a beginning and end of a year.

Types

type AggregateByFunc added in v0.16.0

type AggregateByFunc func(username, hostname string) string

AggregateByFunc is a function that aggregates a given username and hostname into a single string representing final time series ID.

type AggregateMetricsOptions added in v0.16.0

type AggregateMetricsOptions struct {
	TimeResolution TimeResolutionFunc
	AggregateBy    AggregateByFunc
}

AggregateMetricsOptions represents options for AggregateCounter function.

type Counter

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

Counter represents a monotonically increasing int64 counter value.

func (*Counter) Add

func (c *Counter) Add(v int64)

Add adds a value to a counter.

func (*Counter) Snapshot

func (c *Counter) Snapshot(reset bool) int64

Snapshot captures the momentary state of a counter.

type Distribution

type Distribution[T constraints.Integer | constraints.Float] struct {
	// contains filtered or unexported fields
}

Distribution measures distribution/summary of values.

func (*Distribution[T]) Observe

func (d *Distribution[T]) Observe(value T)

Observe adds the provided observation value to the summary.

func (*Distribution[T]) Snapshot

func (d *Distribution[T]) Snapshot(reset bool) *DistributionState[T]

Snapshot returns a snapshot of the distribution state.

type DistributionState

type DistributionState[T constraints.Float | constraints.Integer] struct {
	Min              T       `json:"min"`
	Max              T       `json:"max"`
	Sum              T       `json:"sum"`
	Count            int64   `json:"count"`
	BucketCounters   []int64 `json:"buckets"`
	BucketThresholds []T     `json:"-"`
}

DistributionState captures momentary state of a Distribution.

func (*DistributionState[T]) Mean

func (s *DistributionState[T]) Mean() T

Mean returns arithmetic mean value captured in the distribution.

type DurationDistributionValueAggregator added in v0.16.0

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

DurationDistributionValueAggregator handles aggregation of counter values.

func DurationDistributionValue added in v0.16.0

func DurationDistributionValue(name string) DurationDistributionValueAggregator

DurationDistributionValue returns a function that aggregates on given duration distribution value from a snapshot.

func (DurationDistributionValueAggregator) Aggregate added in v0.16.0

func (c DurationDistributionValueAggregator) Aggregate(previousAggregate, incoming *DistributionState[time.Duration], ratio float64) *DistributionState[time.Duration]

Aggregate aggregates counter values.

func (DurationDistributionValueAggregator) FromSnapshot added in v0.16.0

FromSnapshot extracts counter value from a snapshot.

type Registry

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

Registry groups together all metrics stored in the repository and provides ways of accessing them.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns new metrics registry.

func (*Registry) Close

func (r *Registry) Close(ctx context.Context) error

Close closes the metrics registry.

func (*Registry) CounterInt64

func (r *Registry) CounterInt64(name, help string, labels map[string]string) *Counter

CounterInt64 gets a persistent int64 counter with the provided name.

func (*Registry) DurationDistribution

func (r *Registry) DurationDistribution(name, help string, thresholds *Thresholds[time.Duration], labels map[string]string) *Distribution[time.Duration]

DurationDistribution gets a persistent duration distribution with the provided name.

func (*Registry) Log

func (r *Registry) Log(ctx context.Context)

Log logs all metrics in the registry.

func (*Registry) SizeDistribution

func (r *Registry) SizeDistribution(name, help string, thresholds *Thresholds[int64], labels map[string]string) *Distribution[int64]

SizeDistribution gets a persistent size distribution with the provided name.

func (*Registry) Snapshot

func (r *Registry) Snapshot(reset bool) Snapshot

Snapshot captures the snapshot of all metrics.

func (*Registry) Throughput

func (r *Registry) Throughput(name, help string, labels map[string]string) *Throughput

Throughput gets a persistent counter with the provided name.

type SizeDistributionValueAggregator added in v0.16.0

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

SizeDistributionValueAggregator handles aggregation of counter values.

func SizeDistributionValue added in v0.16.0

func SizeDistributionValue(name string) SizeDistributionValueAggregator

SizeDistributionValue returns a function that aggregates on given duration distribution value from a snapshot.

func (SizeDistributionValueAggregator) Aggregate added in v0.16.0

func (c SizeDistributionValueAggregator) Aggregate(previousAggregate, incoming *DistributionState[int64], ratio float64) *DistributionState[int64]

Aggregate aggregates counter values.

func (SizeDistributionValueAggregator) FromSnapshot added in v0.16.0

FromSnapshot extracts counter value from a snapshot.

type Snapshot

type Snapshot struct {
	StartTime time.Time `json:"startTime"`
	EndTime   time.Time `json:"endTime"`
	User      string    `json:"user"`
	Hostname  string    `json:"hostname"`

	Counters              map[string]int64                             `json:"counters"`
	DurationDistributions map[string]*DistributionState[time.Duration] `json:"durationDistributions"`
	SizeDistributions     map[string]*DistributionState[int64]         `json:"sizeDistributions"`
}

Snapshot captures the state of all metrics.

func AggregateSnapshots

func AggregateSnapshots(snapshots []Snapshot) Snapshot

AggregateSnapshots computes aggregate of the provided snapshots.

type SnapshotValueAggregator added in v0.16.0

type SnapshotValueAggregator[T any] interface {
	FromSnapshot(s *Snapshot) (T, bool)
	Aggregate(previousAggregate T, incoming T, ratio float64) T
}

SnapshotValueAggregator extracts and aggregates counter or distribution values from snapshots.

type Thresholds

type Thresholds[T constraints.Float | constraints.Integer] struct {
	// contains filtered or unexported fields
}

Thresholds encapsulates a set of bucket thresholds used in Summary[T].

type Throughput

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

Throughput measures throughput by keeping track of total value and total duration.

func (*Throughput) Observe

func (c *Throughput) Observe(size int64, dt time.Duration)

Observe increases duration and total value counters based on the amount of time to process particular amount of data.

type TimeResolutionFunc added in v0.16.0

type TimeResolutionFunc func(time.Time) (time.Time, time.Time)

TimeResolutionFunc is a function that maps given point in time to a beginning and end of a time period, such as hour, day, week, month, quarter, or year.

type TimeSeries added in v0.16.0

type TimeSeries[T any] []TimeSeriesPoint[T]

TimeSeries represents a time series of a counter or a distribution.

type TimeSeriesPoint added in v0.16.0

type TimeSeriesPoint[T any] struct {
	Time  time.Time
	Value T
}

TimeSeriesPoint represents a single data point in a time series.

type TimeseriesAggregator added in v0.16.0

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

TimeseriesAggregator handles aggregation of counter values.

func CounterValue added in v0.16.0

func CounterValue(name string) TimeseriesAggregator

CounterValue returns a function that extracts given counter value from a snapshot.

func (TimeseriesAggregator) Aggregate added in v0.16.0

func (c TimeseriesAggregator) Aggregate(agg, incoming int64, ratio float64) int64

Aggregate aggregates counter values.

func (TimeseriesAggregator) FromSnapshot added in v0.16.0

func (c TimeseriesAggregator) FromSnapshot(s *Snapshot) (int64, bool)

FromSnapshot extracts counter value from a snapshot.

Jump to

Keyboard shortcuts

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