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 ¶
Types ¶
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.