cumulative

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package cumulative creates Count metrics from cumulative values.

Example
h, err := telemetry.NewHarvester(
	telemetry.ConfigAPIKey(os.Getenv("NEW_RELIC_INSIGHTS_INSERT_API_KEY")),
)
if err != nil {
	fmt.Println(err)
}
dc := NewDeltaCalculator()

attributes := map[string]interface{}{
	"id":  123,
	"zip": "zap",
}
for {
	cumulativeValue := float64(time.Now().Unix())
	if m, ok := dc.CountMetric("secondsElapsed", attributes, cumulativeValue, time.Now()); ok {
		h.RecordMetric(m)
	}
	time.Sleep(5 * time.Second)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DeltaCalculator

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

DeltaCalculator is used to create Count metrics from cumulative values.

func NewDeltaCalculator

func NewDeltaCalculator() *DeltaCalculator

NewDeltaCalculator creates a new DeltaCalculator. A single DeltaCalculator stores all cumulative values seen in order to compute deltas.

func (*DeltaCalculator) CountMetric

func (dc *DeltaCalculator) CountMetric(name string, attributes map[string]interface{}, val float64, now time.Time) (count telemetry.Count, valid bool)

CountMetric creates a count metric from the difference between the values and timestamps of multiple calls. If this is the first time the name/attributes combination has been seen then the `valid` return value will be false.

func (*DeltaCalculator) SetExpirationAge

func (dc *DeltaCalculator) SetExpirationAge(age time.Duration) *DeltaCalculator

SetExpirationAge configures how old entries must be for expiration. The default is twenty minutes.

func (*DeltaCalculator) SetExpirationCheckInterval

func (dc *DeltaCalculator) SetExpirationCheckInterval(interval time.Duration) *DeltaCalculator

SetExpirationCheckInterval configures how often to check for expired entries. The default is twenty minutes.

Jump to

Keyboard shortcuts

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