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 ¶
- type DeltaCalculator
- func (dc *DeltaCalculator) CountMetric(name string, attributes map[string]interface{}, val float64, now time.Time) (count telemetry.Count, valid bool)
- func (dc *DeltaCalculator) SetExpirationAge(age time.Duration) *DeltaCalculator
- func (dc *DeltaCalculator) SetExpirationCheckInterval(interval time.Duration) *DeltaCalculator
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.