metrics

package module
v0.0.0-...-e005015 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: MIT Imports: 9 Imported by: 0

README

go-metrics

Simplified metrics tracking system for golang to output in JSON format. This system is based on the library provided by rcrowley

Go Doc: http://godoc.org/github.com/KyleLavorato/go-metrics

Supported Metric Types

  • Counter - A basic integer value that can be set, incremented, or decremented.
  • Json - A metric that will hold produced JSON values. Useful for aggregating previously output metrics into a single registry.
  • Meter - A integer value that tracks past values applied. It will track the count of marked values, the last value marked and the mean or average value marked.
  • Registry - The container that holds all metrics
  • Slice - A generic array that will hold multiple metric entries of the same type
  • Text - A simple string value that can be set or appended.
  • Timer - An integer value that will track the number of seconds it executes for. It tracks the count of runs, a []integer set of execution times, the lastValue, as well as max, mean, and min.

Basic Operations

Metric Registration

The orchestrator of the metrics library is a registry object. This is a "map" that holds the values of all the metrics for the current session. There is a global registry that can always be used named metrics.DefaultRegistry. Users can also create their own master registry using the metrics.NewRegistry() function and managing the returned object.

Once a metric is created, it must be registered to a registry object. The register action will link its value to a metrics set and allow it to be tracked and eventually output. When registering the metric, a unique name will be used to map it into the registry. This will be the name the value is output with, and what it name can be used to retrieve it.

Additional registries can be created and registered to the master or other parent registries to create a nesting system. There is no limit to the amount of nesting that can be applied.

Each metric type supports two registration methods:

Register an Existing Metric
c := metrics.NewCounter()
metrics.DefaultRegistry.Register("foo", c)
Create and Register Together
c := metrics.NewRegisteredCounter("foo", registry)
Metric Retrieval

The variable holding the reference to a metric does not need to be passed from function-to-function to be modified. The registry object supports a Get() function to retrieve the metric reference based on its registered name.

When performing a Get() a type cast is required, as this call does not know the type of the metric that will be returned.

metric := registry.Get("foo").(Counter)
Output Metrics

To get the value of all the metrics contained a registry, simply call the registry.GetAllJson() function. This will dump the entire contents of the registry into JSON format to a byte variable.

The output can then be used as desired. It is recommended to forward this to an external metrics backend. Since JSON is a universal format, any number of different backend services can be used.

The library currently supports output only in the JSON format.

Installation

go get github.com/KyleLavorato/go-metrics

Usage

Sample program that creates one of every metric type

package main

import (
    "encoding/json"
    "fmt"
    "time"
)

type NestedData struct {
    ValueOne int
    ValueTwo int
}

type ExistingJson struct {
    Sample NestedData
    Data   NestedData
    Value  int
}

func Example() {
    registry := metrics.NewRegistry()

    // Example Counter
    c := metrics.NewRegisteredCounter("foo", registry)
    c.Inc(3)
    c.Dec(1)
    c.Inc(6)
    c2 := metrics.NewRegisteredCounter("bar", registry)
    c2.Inc(31)
    c2.Dec(14)
    c2.Inc(66)

    cx := registry.Get("foo").(Counter)
    cx.Inc(1)

    // Example Text
    t1 := metrics.NewRegisteredText("hello", registry)
    t1.Set("Error: ")
    t1.Append("did not hello world")

    // Example Meter
    m1 := metrics.NewRegisteredMeter("world", registry)
    m1.Mark(50)
    m1.Mark(100)

    // Example Timer
    q1 := metrics.NewRegisteredTimer("golang", registry)
    q1.Start()
    time.Sleep(time.Second * 1)
    q1.Stop()
    q1.Time(func() { time.Sleep(time.Second * 4) })

    // Example of Nesting Metrics
    nestedRegistry := metrics.NewRegistry()
    metrics.NewRegisteredText("msg", nestedRegistry).Set("This is a nested registry")
    metrics.NewRegisteredCounter("count", nestedRegistry).Inc(1996)
    registry.Register("registry2", nestedRegistry)

    // Example Slice
    s := metrics.NewSlice()
    for i := 0; i < 5; i++ {
        p := metrics.NewRegistry()
        metrics.NewRegisteredText("msg", p).Set("This is a slice entry")
        metrics.NewRegisteredCounter("count", p).Inc(int64(i))
        s.Append(p)
    }
    registry.Register("sliceReg", s)

    // Example JSON
    data := ExistingJson{
        Sample: NestedData{
            ValueOne: 1,
            ValueTwo: 2,
        },
        Data: NestedData{
            ValueOne: 3,
            ValueTwo: 4,
        },
        Value: 5,
    }
    raw, _ := json.Marshal(&data)
    metrics.NewRegisteredJson("ExistingJson", registry).Set(raw)

    // Example Output
    js, err := registry.GetAllJson()
    if err != nil {
        panic(err)
    }
    fmt.Println(string(js))
}

The expected output of the program is:

{
  "ExistingJson": {
    "Sample": {
      "ValueOne": 1,
      "ValueTwo": 2
    },
    "Data": {
      "ValueOne": 3,
      "ValueTwo": 4
    },
    "Value": 5
  },
  "bar": 83,
  "foo": 9,
  "golang": {
    "count": 2,
    "executions": [
      1,
      4
    ],
    "lastValue": 4,
    "max": 4,
    "mean": 2.5,
    "min": 1
  },
  "hello": "Error: did not hello world",
  "registry2": {
    "count": 1996,
    "msg": "This is a nested registry"
  },
  "sliceReg": [
    {
      "count": 0,
      "msg": "This is a slice entry"
    },
    {
      "count": 1,
      "msg": "This is a slice entry"
    },
    {
      "count": 2,
      "msg": "This is a slice entry"
    },
    {
      "count": 3,
      "msg": "This is a slice entry"
    },
    {
      "count": 4,
      "msg": "This is a slice entry"
    }
  ],
  "world": {
    "count": 2,
    "lastValue": 100,
    "mean": 75
  }
}

Additional Information

Multi-Threading

The Register() function is not thread safe. If using a parallel processing model, ensure that registration calls are wrapped in a mutex for that registry.

Documentation

Overview

Fork of rcrowley's Metrics library

<https://github.com/rcrowley/go-metrics>

Metrics packages have been simplified to be easier to use. Additional behaviour has been added to metrics types, as well as the inclusion of a Text type.

Example
// nolint
package main

import (
	"encoding/json"
	"fmt"
	"time"
)

type NestedData struct {
	ValueOne int
	ValueTwo int
}

type ExistingJson struct {
	Sample NestedData
	Data   NestedData
	Value  int
}

func main() {
	registry := NewRegistry()

	c := NewRegisteredCounter("foo", registry)
	c.Inc(3)
	c.Dec(1)
	c.Inc(6)
	c2 := NewRegisteredCounter("bar", registry)
	c2.Inc(31)
	c2.Dec(14)
	c2.Inc(66)

	cx := registry.Get("foo").(Counter)
	cx.Inc(1)

	t1 := NewRegisteredText("hello", registry)
	t1.Set("Error: ")
	t1.Append("did not hello world")

	m1 := NewRegisteredMeter("world", registry)
	m1.Mark(50)
	m1.Mark(100)

	q1 := NewRegisteredTimer("golang", registry)
	q1.Start()
	time.Sleep(time.Second * 1)
	q1.Stop()
	q1.Time(func() { time.Sleep(time.Second * 4) })

	nestedRegistry := NewRegistry()
	NewRegisteredText("msg", nestedRegistry).Set("This is a nested registry")
	NewRegisteredCounter("count", nestedRegistry).Inc(1996)
	registry.Register("registry2", nestedRegistry)

	s := NewSlice()
	for i := 0; i < 5; i++ {
		p := NewRegistry()
		NewRegisteredText("msg", p).Set("This is a slice entry")
		NewRegisteredCounter("count", p).Inc(int64(i))
		s.Append(p)
	}
	registry.Register("sliceReg", s)

	data := ExistingJson{
		Sample: NestedData{
			ValueOne: 1,
			ValueTwo: 2,
		},
		Data: NestedData{
			ValueOne: 3,
			ValueTwo: 4,
		},
		Value: 5,
	}
	raw, _ := json.Marshal(&data)
	NewRegisteredJson("ExistingJson", registry).Set(raw)

	js, err := registry.GetAllJson()
	if err != nil {
		panic(err)
	}
	fmt.Println(string(js))
}
Output:

{"ExistingJson":{"Sample":{"ValueOne":1,"ValueTwo":2},"Data":{"ValueOne":3,"ValueTwo":4},"Value":5},"bar":83,"foo":9,"golang":{"count":2,"executions":[1,4],"lastValue":4,"max":4,"mean":2.5,"min":1},"hello":"Error: did not hello world","registry2":{"count":1996,"msg":"This is a nested registry"},"sliceReg":[{"count":0,"msg":"This is a slice entry"},{"count":1,"msg":"This is a slice entry"},{"count":2,"msg":"This is a slice entry"},{"count":3,"msg":"This is a slice entry"},{"count":4,"msg":"This is a slice entry"}],"world":{"count":2,"lastValue":100,"mean":75}}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SampleMax

func SampleMax(values []int64) int64

SampleMax returns the maximum value of the slice of int64.

func SampleMean

func SampleMean(values []int64) float64

SampleMean returns the mean value of the slice of int64.

func SampleMin

func SampleMin(values []int64) int64

SampleMin returns the minimum value of the slice of int64.

func SamplePercentile

func SamplePercentile(values int64Slice, p float64) float64

SamplePercentiles returns an arbitrary percentile of the slice of int64.

func SamplePercentiles

func SamplePercentiles(values int64Slice, ps []float64) []float64

SamplePercentiles returns a slice of arbitrary percentiles of the slice of int64.

func SampleStdDev

func SampleStdDev(values []int64) float64

SampleStdDev returns the standard deviation of the slice of int64.

func SampleSum

func SampleSum(values []int64) int64

SampleSum returns the sum of the slice of int64.

func SampleVariance

func SampleVariance(values []int64) float64

SampleVariance returns the variance of the slice of int64.

Types

type Counter

type Counter interface {
	Clear()
	Count() int64
	Dec(int64)
	Inc(int64)
	Set(int64)
}

Counters hold an int64 value that can be incremented and decremented.

func GetCounter

func GetCounter(name string, r Registry) Counter

GetCounter returns an existing Counter

func NewCounter

func NewCounter() Counter

NewCounter constructs a new StandardCounter.

func NewRegisteredCounter

func NewRegisteredCounter(name string, r Registry) Counter

NewRegisteredCounter constructs and registers a new StandardCounter.

type DuplicateMetric

type DuplicateMetric string

DuplicateMetric is the error returned by Registry.Register when a metric already exists. If you mean to Register that metric you must first Unregister the existing metric.

func (DuplicateMetric) Error

func (err DuplicateMetric) Error() string

type ExpDecaySample

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

ExpDecaySample is an exponentially-decaying sample using a forward-decaying priority reservoir. See Cormode et al's "Forward Decay: A Practical Time Decay Model for Streaming Systems".

<http://dimacs.rutgers.edu/~graham/pubs/papers/fwddecay.pdf>

func (*ExpDecaySample) Clear

func (s *ExpDecaySample) Clear()

Clear clears all samples.

func (*ExpDecaySample) Count

func (s *ExpDecaySample) Count() int64

Count returns the number of samples recorded, which may exceed the reservoir size.

func (*ExpDecaySample) Max

func (s *ExpDecaySample) Max() int64

Max returns the maximum value in the sample, which may not be the maximum value ever to be part of the sample.

func (*ExpDecaySample) Mean

func (s *ExpDecaySample) Mean() float64

Mean returns the mean of the values in the sample.

func (*ExpDecaySample) Min

func (s *ExpDecaySample) Min() int64

Min returns the minimum value in the sample, which may not be the minimum value ever to be part of the sample.

func (*ExpDecaySample) Percentile

func (s *ExpDecaySample) Percentile(p float64) float64

Percentile returns an arbitrary percentile of values in the sample.

func (*ExpDecaySample) Percentiles

func (s *ExpDecaySample) Percentiles(ps []float64) []float64

Percentiles returns a slice of arbitrary percentiles of values in the sample.

func (*ExpDecaySample) Size

func (s *ExpDecaySample) Size() int

Size returns the size of the sample, which is at most the reservoir size.

func (*ExpDecaySample) StdDev

func (s *ExpDecaySample) StdDev() float64

StdDev returns the standard deviation of the values in the sample.

func (*ExpDecaySample) Sum

func (s *ExpDecaySample) Sum() int64

Sum returns the sum of the values in the sample.

func (*ExpDecaySample) Update

func (s *ExpDecaySample) Update(v int64)

Update samples a new value.

func (*ExpDecaySample) Values

func (s *ExpDecaySample) Values() []int64

Values returns a copy of the values in the sample.

func (*ExpDecaySample) Variance

func (s *ExpDecaySample) Variance() float64

Variance returns the variance of the values in the sample.

type Histogram

type Histogram interface {
	Clear()
	Count() int64
	Max() int64
	Mean() float64
	Min() int64
	Percentile(float64) float64
	Percentiles([]float64) []float64
	Sample() Sample
	StdDev() float64
	Sum() int64
	Update(int64)
	Variance() float64
}

Histograms calculate distribution statistics from a series of int64 values.

func GetHistogram

func GetHistogram(name string, r Registry) Histogram

GetHistogram returns an existing Counter

func NewHistogram

func NewHistogram(s Sample) Histogram

NewHistogram constructs a new StandardHistogram from a Sample.

func NewRegisteredHistogram

func NewRegisteredHistogram(name string, r Registry, s Sample) Histogram

NewRegisteredHistogram constructs and registers a new StandardHistogram from a Sample.

type Json

type Json interface {
	Clear()
	Json() json.RawMessage // Get the current msg value
	Set(json.RawMessage)   // Set a new msg value
}

Json is a basic string message that can be set and appended to

func GetJson

func GetJson(name string, r Registry) Json

GetJson returns an existing Counter

func NewJson

func NewJson() Json

NewCounter constructs a new StandardJson.

func NewRegisteredJson

func NewRegisteredJson(name string, r Registry) Json

NewRegisteredCounter constructs and registers a new StandardJson.

type Meter

type Meter interface {
	Count() int64      // Number of times the meter has saved a value
	Mark(int64)        // Set a value in the meter
	RateMean() float64 // Get the mean value from the meter
	LastValue() int64  // Get the most recently saved value
	Snapshot() Meter   // Save a snapshot of the current state
}

Meters track set values and how the value changes over time each time it is recorded

func GetMeter

func GetMeter(name string, r Registry) Meter

GetMeter returns an existing Counter

func NewMeter

func NewMeter() Meter

NewMeter constructs a new StandardMeter and launches a goroutine. Be sure to call Stop() once the meter is of no use to allow for garbage collection.

func NewRegisteredMeter

func NewRegisteredMeter(name string, r Registry) Meter

NewMeter constructs and registers a new StandardMeter and launches a goroutine. Be sure to unregister the meter from the registry once it is of no use to allow for garbage collection.

type MeterSnapshot

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

MeterSnapshot is a read-only copy of another Meter.

func (*MeterSnapshot) Count

func (m *MeterSnapshot) Count() int64

Count returns the count of events at the time the snapshot was taken.

func (*MeterSnapshot) LastValue

func (m *MeterSnapshot) LastValue() int64

LastValue returns the last recorded value on the meter

func (*MeterSnapshot) Mark

func (*MeterSnapshot) Mark(n int64)

Mark panics.

func (*MeterSnapshot) RateMean

func (m *MeterSnapshot) RateMean() float64

RateMean returns the meter's mean rate of events per second at the time the snapshot was taken.

func (*MeterSnapshot) Snapshot

func (m *MeterSnapshot) Snapshot() Meter

Snapshot returns the snapshot.

type Registry

type Registry interface {
	// Call the given function for each registered metric.
	Each(func(string, interface{}))

	// Get the metric by the given name or nil if none is registered.
	Get(string) interface{}

	// Output the value of all metrics in JSON
	GetAllJson() ([]byte, error)

	// Register the given metric under the given name.
	Register(string, interface{}) error

	// Unregister the metric with the given name.
	Unregister(string)

	// Get the number of tracked metrics
	MetricCount() int
}

A Registry holds references to a set of metrics by name and can iterate over them, calling callback functions provided by the user.

This is an interface so as to encourage other structs to implement the Registry API as appropriate.

var DefaultRegistry Registry = NewRegistry()

Default registry is none is specified

func NewRegistry

func NewRegistry() Registry

Create a new registry.

type Sample

type Sample interface {
	Clear()
	Count() int64
	Max() int64
	Mean() float64
	Min() int64
	Percentile(float64) float64
	Percentiles([]float64) []float64
	Size() int
	StdDev() float64
	Sum() int64
	Update(int64)
	Values() []int64
	Variance() float64
}

Samples maintain a statistically-significant selection of values from a stream.

func NewExpDecaySample

func NewExpDecaySample(reservoirSize int, alpha float64) Sample

NewExpDecaySample constructs a new exponentially-decaying sample with the given reservoir size and alpha.

type Slice

type Slice interface {
	Append(Registry)
	GetAll() []Registry
	Clear()
}

Counters hold an int64 value that can be incremented and decremented.

func GetSlice

func GetSlice(name string, r Registry) Slice

GetSlice returns an existing Counter

func NewRegisteredSlice

func NewRegisteredSlice(name string, r Registry) Slice

NewRegisteredSlice constructs and registers a new StandardCounter.

func NewSlice

func NewSlice() Slice

NewSlice constructs a new StandardSlice.

type StandardCounter

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

StandardCounter is the standard implementation of a Counter and uses the sync/atomic package to manage a single int64 value.

func (*StandardCounter) Clear

func (c *StandardCounter) Clear()

Clear sets the counter to zero.

func (*StandardCounter) Count

func (c *StandardCounter) Count() int64

Count returns the current count.

func (*StandardCounter) Dec

func (c *StandardCounter) Dec(i int64)

Dec decrements the counter by the given amount.

func (*StandardCounter) Inc

func (c *StandardCounter) Inc(i int64)

Inc increments the counter by the given amount.

func (*StandardCounter) Set

func (c *StandardCounter) Set(i int64)

Set changes the counter to the given value.

type StandardHistogram

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

StandardHistogram is the standard implementation of a Histogram and uses a Sample to bound its memory use.

func (*StandardHistogram) Clear

func (h *StandardHistogram) Clear()

Clear clears the histogram and its sample.

func (*StandardHistogram) Count

func (h *StandardHistogram) Count() int64

Count returns the number of samples recorded since the histogram was last cleared.

func (*StandardHistogram) Max

func (h *StandardHistogram) Max() int64

Max returns the maximum value in the sample.

func (*StandardHistogram) Mean

func (h *StandardHistogram) Mean() float64

Mean returns the mean of the values in the sample.

func (*StandardHistogram) Min

func (h *StandardHistogram) Min() int64

Min returns the minimum value in the sample.

func (*StandardHistogram) Percentile

func (h *StandardHistogram) Percentile(p float64) float64

Percentile returns an arbitrary percentile of the values in the sample.

func (*StandardHistogram) Percentiles

func (h *StandardHistogram) Percentiles(ps []float64) []float64

Percentiles returns a slice of arbitrary percentiles of the values in the sample.

func (*StandardHistogram) Sample

func (h *StandardHistogram) Sample() Sample

Sample returns the Sample underlying the histogram.

func (*StandardHistogram) StdDev

func (h *StandardHistogram) StdDev() float64

StdDev returns the standard deviation of the values in the sample.

func (*StandardHistogram) Sum

func (h *StandardHistogram) Sum() int64

Sum returns the sum in the sample.

func (*StandardHistogram) Update

func (h *StandardHistogram) Update(v int64)

Update samples a new value.

func (*StandardHistogram) Variance

func (h *StandardHistogram) Variance() float64

Variance returns the variance of the values in the sample.

type StandardJson

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

StandardJson is the standard implementation of a Json value

func (*StandardJson) Clear

func (t *StandardJson) Clear()

Clear removes the current msg value

func (*StandardJson) Json

func (t *StandardJson) Json() json.RawMessage

Json returns the msg value

func (*StandardJson) Set

func (t *StandardJson) Set(j json.RawMessage)

Set changes the msg value to the indicated string

type StandardMeter

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

StandardMeter is the standard implementation of a Meter.

func (*StandardMeter) Count

func (m *StandardMeter) Count() int64

Count returns the number of events recorded.

func (*StandardMeter) LastValue

func (m *StandardMeter) LastValue() int64

LastValue returns the last recorded value on the meter

func (*StandardMeter) Mark

func (m *StandardMeter) Mark(n int64)

Mark records the occurance of n events.

func (*StandardMeter) RateMean

func (m *StandardMeter) RateMean() float64

RateMean returns the meter's mean rate of events per second.

func (*StandardMeter) Snapshot

func (m *StandardMeter) Snapshot() Meter

Snapshot returns a read-only copy of the meter.

type StandardRegistry

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

The standard implementation of a Registry is a mutex-protected map of names to metrics.

func (*StandardRegistry) Each

func (r *StandardRegistry) Each(f func(string, interface{}))

Call the given function for each registered metric.

func (*StandardRegistry) Get

func (r *StandardRegistry) Get(name string) interface{}

Get the metric by the given name or nil if none is registered.

func (*StandardRegistry) GetAllJson

func (r *StandardRegistry) GetAllJson() ([]byte, error)

Output the value of all registered metrics in JSON format

func (*StandardRegistry) MetricCount

func (r *StandardRegistry) MetricCount() int

Get the number of tracked metrics

func (*StandardRegistry) Register

func (r *StandardRegistry) Register(name string, i interface{}) error

Register the given metric under the given name. Returns a DuplicateMetric if a metric by the given name is already registered.

func (*StandardRegistry) Unregister

func (r *StandardRegistry) Unregister(name string)

Unregister the metric with the given name.

type StandardSlice

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

StandardSlice is the standard implementation of a Slice metrics set

func (*StandardSlice) Append

func (s *StandardSlice) Append(r Registry)

Append a registry onto the slice

func (*StandardSlice) Clear

func (s *StandardSlice) Clear()

Clear sets the slize to empty

func (*StandardSlice) GetAll

func (s *StandardSlice) GetAll() []Registry

Return all included registries

type StandardText

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

StandardText is the standard implementation of a text value

func (*StandardText) Append

func (t *StandardText) Append(str string)

Append adds the indicated string to the end of the msg value

func (*StandardText) Clear

func (t *StandardText) Clear()

Clear removes the current msg value

func (*StandardText) Set

func (t *StandardText) Set(str string)

Set changes the msg value to the indicated string

func (*StandardText) Text

func (t *StandardText) Text() string

Text returns the msg value

type StandardTimer

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

StandardTimer is the standard implementation of a Timer and uses a Histogram and Meter.

func (*StandardTimer) AllExecutions

func (t *StandardTimer) AllExecutions() []float64

AllExecutions returns all the past executions

func (*StandardTimer) Count

func (t *StandardTimer) Count() int64

Count returns the number of events recorded.

func (*StandardTimer) LastValue

func (t *StandardTimer) LastValue() float64

LastValue returns the value from the most recent execution.

func (*StandardTimer) Max

func (t *StandardTimer) Max() int64

Max returns the maximum value in the sample.

func (*StandardTimer) Mean

func (t *StandardTimer) Mean() float64

Mean returns the mean of the values in the sample.

func (*StandardTimer) Min

func (t *StandardTimer) Min() int64

Min returns the minimum value in the sample.

func (*StandardTimer) Start

func (t *StandardTimer) Start()

Record the current time to prepare for a Stop() call

func (*StandardTimer) Stop

func (t *StandardTimer) Stop()

Record the duration of an event that started with a call to Start() and ends now.

func (*StandardTimer) Time

func (t *StandardTimer) Time(f func())

Record the duration of the execution of the given function.

type Text

type Text interface {
	Clear()
	Text() string  // Get the current msg value
	Set(string)    // Set a new msg value
	Append(string) // Append to the end of the msg value
}

Text is a basic string message that can be set and appended to

func GetText

func GetText(name string, r Registry) Text

GetText returns an existing Counter

func NewRegisteredText

func NewRegisteredText(name string, r Registry) Text

NewRegisteredCounter constructs and registers a new StandardText.

func NewText

func NewText() Text

NewCounter constructs a new StandardText.

type Timer

type Timer interface {
	Count() int64             // Number of timer executions
	Max() int64               // Highest recorded timer execution in seconds
	Mean() float64            // Mean recorded timer execution in seconds
	Min() int64               // Lowest recorded timer execution in seconds
	LastValue() float64       // The value from the most recent execution in seconds
	AllExecutions() []float64 // All past executions in seconds
	Start()                   // Record current time
	Stop()                    // Record duration since Start() call
	Time(func())              // Record duration to execute a function
}

Timers measures the time to complete a task and tracks the history of past executions

func GetTimer

func GetTimer(name string, r Registry) Timer

GetTimer returns an existing Counter

func NewRegisteredTimer

func NewRegisteredTimer(name string, r Registry) Timer

NewRegisteredTimer constructs and registers a new StandardTimer. Be sure to unregister the meter from the registry once it is of no use to allow for garbage collection.

func NewTimer

func NewTimer() Timer

NewTimer constructs a new StandardTimer using an exponentially-decaying sample with the same reservoir size and alpha as UNIX load averages. Be sure to call Cleanup() once the timer is of no use to allow for garbage collection.

Jump to

Keyboard shortcuts

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