telemetry

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package telemetry adds a simple timeseries implementation for flexible computation of rates based on an append-only log of cumulative values. This is a toy implementation and not fit for production use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PerSecond

func PerSecond(ts *TimeSeries, start, end time.Time) float64

PerSecond computes the rate of change between the start and end time of ts, when expressed in per second granularity. If the rate cannot be computed (e.g., due to unavailable data) NaN is returned.

Types

type Entry

type Entry struct {
	Timestamp time.Time
	Value     float64
}

Entry is a timestamped value that can be added to a time series.

type TimeSeries

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

TimeSeries is a simplified memory-only time series with monotonic timestamps. This is a toy implementation and not fit for production use. Use Prometheus instead.

TimeSeries methods can be called concurrently from different goroutines.

func NewTimeSeries

func NewTimeSeries(start time.Time) *TimeSeries

NewTimeSeries initializes a new time series with a value of 0 at start time. Values before start are assumed to be all 0.

func (*TimeSeries) Add

func (ts *TimeSeries) Add(e Entry) error

Add appends an entry to the time series. The entry is only added if its timestamp is newer than all entries in the series and the value is greater than all entries in the series. Otherwise, an error is returned. Add can be called concurrently from different goroutines.

func (*TimeSeries) Difference

func (ts *TimeSeries) Difference(start, end time.Time) float64

Difference computes the change in value between start and end. Start can be before the reference point set at time series creation. Values before the reference point are assumed to be 0.

If start is greater or equal to end, the function panics. If end is past the last seen value observation, NaN is returned.

Difference can be called concurrently from different goroutines.

Jump to

Keyboard shortcuts

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