datum

package
v0.0.0-...-5655933 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecIntBy

func DecIntBy(d Datum, v int64, ts time.Time)

DecIntBy increments an integer Datum by the provided value, at time ts, or panics if the Datum is not an IntDatum.

func GetBucketsCount

func GetBucketsCount(d Datum) uint64

GetBucketCount returns the total count of observations in d, or panics if d is not a BucketsDatum.

func GetBucketsCumByMax

func GetBucketsCumByMax(d Datum) map[float64]uint64

GetBucketsCumByMax returns a map of cumulative bucket observations by their upper bonds, or panics if d is not a BucketsDatum.

func GetBucketsSum

func GetBucketsSum(d Datum) float64

GetBucketsSum returns the sum of observations in d, or panics if d is not a BucketsDatum.

func GetFloat

func GetFloat(d Datum) float64

GetFloat returns the floating-point value of a datum, or error.

func GetInt

func GetInt(d Datum) int64

GetInt returns the integer value of a datum, or error.

func GetString

func GetString(d Datum) string

GetString returns the string of a datum, or error.

func IncIntBy

func IncIntBy(d Datum, v int64, ts time.Time)

IncIntBy increments an integer Datum by the provided value, at time ts, or panics if the Datum is not an IntDatum.

func Observe

func Observe(d Datum, v float64, ts time.Time)

Observe records an observation v at time ts in d, or panics if d is not a BucketsDatum.

func SetFloat

func SetFloat(d Datum, v float64, ts time.Time)

SetFloat sets a floating-point Datum to the provided value and timestamp, or panics if the Datum is not a FloatDatum.

func SetInt

func SetInt(d Datum, v int64, ts time.Time)

SetInt sets an integer datum to the provided value and timestamp, or panics if the Datum is not an IntDatum.

func SetString

func SetString(d Datum, v string, ts time.Time)

SetString sets a string Datum to the provided value and timestamp, or panics if the Datym is not a String Datum.

Types

type BaseDatum

type BaseDatum struct {
	Time int64 // nanoseconds since unix epoch
}

BaseDatum is a struct used to record timestamps across all Datum implementations.

func (*BaseDatum) TimeString

func (d *BaseDatum) TimeString() string

TimeString returns the timestamp of this Datum as a string.

func (*BaseDatum) TimeUTC

func (d *BaseDatum) TimeUTC() time.Time

type BucketCount

type BucketCount struct {
	Range Range
	Count uint64
}

type Buckets

type Buckets struct {
	BaseDatum
	sync.RWMutex
	Buckets []BucketCount
	Count   uint64
	Sum     float64
}

Buckets describes a floating point value at a given timestamp.

func GetBuckets

func GetBuckets(d Datum) *Buckets

func (*Buckets) AddBucket

func (d *Buckets) AddBucket(r Range)

func (*Buckets) GetBuckets

func (d *Buckets) GetBuckets() map[Range]uint64

func (*Buckets) GetCount

func (d *Buckets) GetCount() uint64

func (*Buckets) GetSum

func (d *Buckets) GetSum() float64

func (*Buckets) MarshalJSON

func (d *Buckets) MarshalJSON() ([]byte, error)

func (*Buckets) Observe

func (d *Buckets) Observe(v float64, ts time.Time)

func (*Buckets) ValueString

func (d *Buckets) ValueString() string

type Datum

type Datum interface {

	// ValueString returns the value of a Datum as a string.
	ValueString() string

	// TimeString returns the timestamp of a Datum as a string.
	TimeString() string

	// Time returns the timestamp of the Datum as time.Time in UTC
	TimeUTC() time.Time
}

Datum is an interface for metric datums, with a type, value and timestamp to be exported.

func MakeBuckets

func MakeBuckets(buckets []Range, ts time.Time) Datum

MakeBuckets creates a new bucket datum with the provided list of ranges and timestamp. If no +inf bucket is provided, one is created.

func MakeFloat

func MakeFloat(v float64, ts time.Time) Datum

MakeFloat creates a new floating-point datum with the provided value and timestamp.

func MakeInt

func MakeInt(v int64, ts time.Time) Datum

MakeInt creates a new integer datum with the provided value and timestamp.

func MakeString

func MakeString(v string, ts time.Time) Datum

MakeString creates a new string datum with the provided value and timestamp.

func NewBuckets

func NewBuckets(buckets []Range) Datum

NewBuckets creates a new zero buckets datum.

func NewFloat

func NewFloat() Datum

NewFloat creates a new zero floating-point datum.

func NewInt

func NewInt() Datum

NewInt creates a new zero integer datum.

func NewString

func NewString() Datum

NewString creates a new zero string datum.

type Float

type Float struct {
	BaseDatum
	Valuebits uint64
}

Float describes a floating point value at a given timestamp.

func (*Float) Get

func (d *Float) Get() float64

Get returns the floating-point value.

func (*Float) MarshalJSON

func (d *Float) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON encoding of the Float.

func (*Float) Set

func (d *Float) Set(v float64, ts time.Time)

Set sets value of the Float at the timestamp ts.

func (*Float) ValueString

func (d *Float) ValueString() string

ValueString returns the value of the Float as a string.

type Int

type Int struct {
	BaseDatum
	Value int64
}

Int describes an integer value at a given timestamp.

func (*Int) DecBy

func (d *Int) DecBy(delta int64, timestamp time.Time)

DecBy increments the Int's value by the value provided, at timestamp.

func (*Int) Get

func (d *Int) Get() int64

Get returns the value of the Int.

func (*Int) IncBy

func (d *Int) IncBy(delta int64, timestamp time.Time)

IncBy increments the Int's value by the value provided, at timestamp.

func (*Int) MarshalJSON

func (d *Int) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON encoding of the Int.

func (*Int) Set

func (d *Int) Set(value int64, timestamp time.Time)

Set sets the value of the Int to the value at timestamp.

func (*Int) ValueString

func (d *Int) ValueString() string

ValueString returns the value of the Int as a string.

type Range

type Range struct {
	Min float64
	Max float64
}

func (*Range) Contains

func (r *Range) Contains(v float64) bool

func (*Range) MarshalJSON

func (r *Range) MarshalJSON() ([]byte, error)

type String

type String struct {
	BaseDatum

	Value string
	// contains filtered or unexported fields
}

String describes a string value at a given timestamp.

func (*String) Get

func (d *String) Get() string

Get returns the value of the String.

func (*String) MarshalJSON

func (d *String) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON encoding of the String.

func (*String) Set

func (d *String) Set(value string, timestamp time.Time)

Set sets the value of the String to the value at timestamp.

func (*String) ValueString

func (d *String) ValueString() string

ValueString returns the value of the String as a string.

Jump to

Keyboard shortcuts

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