Documentation ¶
Overview ¶
Package metrics provides unified way of emitting metrics inside Kopia.
Index ¶
- Variables
- func AggregateAll(username, hostname string) string
- func AggregateByHost(username, hostname string) string
- func AggregateByUser(username, hostname string) string
- func CreateTimeSeries[TValue any](ctx context.Context, snapshots []*Snapshot, ...) map[string]TimeSeries[TValue]
- func TimeResolutionByDay(t time.Time) (dayStart, nextDayStart time.Time)
- func TimeResolutionByHour(t time.Time) (hourStart, nextHourStart time.Time)
- func TimeResolutionByMonth(t time.Time) (monthStart, nextMonthStart time.Time)
- func TimeResolutionByQuarter(t time.Time) (quarterStart, nextQuarterStart time.Time)
- func TimeResolutionByWeekStartingMonday(t time.Time) (weekStart, nextWeekStart time.Time)
- func TimeResolutionByWeekStartingSunday(t time.Time) (weekStart, nextWeekStart time.Time)
- func TimeResolutionByYear(t time.Time) (yearStart, nextYearStart time.Time)
- type AggregateByFunc
- type AggregateMetricsOptions
- type Counter
- type Distribution
- type DistributionState
- type DurationDistributionValueAggregator
- type Registry
- func (r *Registry) Close(ctx context.Context) error
- func (r *Registry) CounterInt64(name, help string, labels map[string]string) *Counter
- func (r *Registry) DurationDistribution(name, help string, thresholds *Thresholds[time.Duration], ...) *Distribution[time.Duration]
- func (r *Registry) Log(ctx context.Context)
- func (r *Registry) SizeDistribution(name, help string, thresholds *Thresholds[int64], labels map[string]string) *Distribution[int64]
- func (r *Registry) Snapshot(reset bool) Snapshot
- func (r *Registry) Throughput(name, help string, labels map[string]string) *Throughput
- type SizeDistributionValueAggregator
- type Snapshot
- type SnapshotValueAggregator
- type Thresholds
- type Throughput
- type TimeResolutionFunc
- type TimeSeries
- type TimeSeriesPoint
- type TimeseriesAggregator
Constants ¶
This section is empty.
Variables ¶
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.
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.
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
AggregateAll is an aggregation function that aggregates all data into a single series.
func AggregateByHost ¶ added in v0.16.0
AggregateByHost is an aggregation function that aggregates by hostname.
func AggregateByUser ¶ added in v0.16.0
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
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
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
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
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
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
TimeResolutionByWeekStartingSunday is a time resolution function that maps given time to a beginning and end of a week (starting Sunday).
Types ¶
type AggregateByFunc ¶ added in v0.16.0
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.
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
func (c DurationDistributionValueAggregator) FromSnapshot(s *Snapshot) (*DistributionState[time.Duration], bool)
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 (*Registry) CounterInt64 ¶
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) 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) 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
func (c SizeDistributionValueAggregator) FromSnapshot(s *Snapshot) (*DistributionState[int64], bool)
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 ¶
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.
type TimeResolutionFunc ¶ added in v0.16.0
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
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.