Documentation ¶
Overview ¶
Package metrics contains a ready to use instance of patan. This instance can be used as the sole active instance of patan within the application. Clients are advised to use this. example: metrics.AddSample("key", 123)
Example ¶
sw := StartStopwatch() IncrementCounter("active.connections") AddSample("shopping.basket.total", 143.26) AddSample("shopping.basket.total", 167.16) AddSample("shopping.basket.total", 23.98) DecrementCounter("active.connections") RecordElapsedTime("order.processing.duration", sw) snapshot := SnapshotAndReset() //Returns a snapshot of all recorded counters, samples and durations and clears the store! _ = snapshot.Counters()["active.connections"] // 0 (1 increment, 1 decrement, counters start at 0) basketTotal := snapshot.Samples()["shopping.basket.total"] // baskedTotal = a distribution with a min, max, avg and stddev basketTotal.SampleCount() // 3 basketTotal.Avg() // 111,46 basketTotal.StdDev() // ... processingDuration := snapshot.Durations()["order.processing.duration"] // returns a distribution as well processingDuration.SampleCount() // 1 processingDuration.Avg() // ... //... timeWindow := snapshot.CreatedTimestamp() - snapshot.StartedTimestamp() // time window in which measurements were recorded in millis _ = timeWindow
Output:
Index ¶
- func AddSample(key string, value float64)
- func AddToCounter(key string, value int64)
- func DecrementCounter(key string)
- func IncrementCounter(key string)
- func MeasureFunc(key string, subject func()) float64
- func MeasureFuncCanPanic(key string, subject func()) float64
- func New() api.Facade
- func RecordElapsedTime(key string, stopwatch api.Stopwatch) float64
- func Reset()
- func Snapshot() api.Snapshot
- func SnapshotAndReset() api.Snapshot
- func StartStopwatch() api.Stopwatch
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddSample ¶
AddSample adds a sample to the distribution identified by value, if the distribution doesn't exist, it will be created
func AddToCounter ¶
AddToCounter adds value to the counter identified by key, value can be negative
func DecrementCounter ¶
func DecrementCounter(key string)
DecrementCounter decrements the counter identified by key by 1
func IncrementCounter ¶
func IncrementCounter(key string)
IncrementCounter increments the counter identified by key by 1
func MeasureFunc ¶
MeasureFunc runs the subject function and records it's execution duration under the distribution identified with key
func MeasureFuncCanPanic ¶
MeasureFuncCanPanic runs the subject function and records it's execution duration under the distribution identified with key. When subject() panics, the measurement is recored under the same key with .panic appended. This function itself will panic with the same error as the inner function.
func RecordElapsedTime ¶
RecordElapsedTime records the elapsed time of the stopwatch under the distribution identified with key
func Snapshot ¶
Snapshot returns a snapshot of all the counters, durations and samples recorded since creation or the last reset.
func SnapshotAndReset ¶
SnapshotAndReset returns a snapshot of all the counters, durations and samples recorded since creation or the last reset, and then clears the internal state
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
Package api contains the public interface
|
Package api contains the public interface |