metrics

package
v1.0.1-0...-28f9f06 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2016 License: Apache-2.0 Imports: 3 Imported by: 0

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSample

func AddSample(key string, value float64)

AddSample adds a sample to the distribution identified by value, if the distribution doesn't exist, it will be created

func AddToCounter

func AddToCounter(key string, value int64)

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

func MeasureFunc(key string, subject func()) float64

MeasureFunc runs the subject function and records it's execution duration under the distribution identified with key

func MeasureFuncCanPanic

func MeasureFuncCanPanic(key string, subject func()) float64

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 New

func New() api.Facade

New returns a new API facade with a new and empty underlying store.

func RecordElapsedTime

func RecordElapsedTime(key string, stopwatch api.Stopwatch) float64

RecordElapsedTime records the elapsed time of the stopwatch under the distribution identified with key

func Reset

func Reset()

Reset clears the store

func Snapshot

func Snapshot() api.Snapshot

Snapshot returns a snapshot of all the counters, durations and samples recorded since creation or the last reset.

func SnapshotAndReset

func SnapshotAndReset() api.Snapshot

SnapshotAndReset returns a snapshot of all the counters, durations and samples recorded since creation or the last reset, and then clears the internal state

func StartStopwatch

func StartStopwatch() api.Stopwatch

StartStopwatch starts a new stopwatch

Types

This section is empty.

Directories

Path Synopsis
Package api contains the public interface
Package api contains the public interface

Jump to

Keyboard shortcuts

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