Categorygithub.com/msaf1980/go-metrics
modulepackage
0.0.14
Repository: https://github.com/msaf1980/go-metrics.git
Documentation: pkg.go.dev

# README

go-metrics

Golang metrics library: Initialyy based on https://github.com/rcrowley/go-metrics Main changes:

  1. Reduce alocations for better perfomance
  2. Read-lock during Registry.Each iterator (for avoid copy registry storage)
  3. Don't append ".value" postfix and Gauge and GaugeFloat64
  4. Modified graphite client
  5. Simplify metrics types

Documentation: http://godoc.org/github.com/msaf1980/go-metrics.

Usage

Create and update metrics:

c := metrics.NewCounter()
metrics.Register("foo", c)
c.Inc(47)

g := metrics.NewGauge()
metrics.Register("bar", g)
g.Update(47)

r := metrics.NewRegistry()
g := metrics.NewRegisteredFunctionalGauge("cache-evictions", r, func() int64 { return cache.getEvictionsCount() })

fixedH := metrics.NewUFixedHistogram(1, 3, 1, "req_", "")
if err := r.Register("fixed_histogram", fixedH); err != nil {
    ...
}
fixedH.Add(2)

h := metrics.NewVHistogram([]int64{1, 2, 5, 8, 20}, nil, "", "")
if err := r.Register("histogram", h); err != nil {
    ...
}
h.Add(2)

Register() return error is metric with this name exists. For error-less metric registration use GetOrRegister: Functions NewRegistered not thread-safe and can't return unregistered metric (if name duplicated)

t := metrics.GetOrRegisterVHistogram("account.create.latency", r, []int64{1, 2, 5, 8, 20}, nil, "", "")
t.Time(func() {})
t.Update(47)

NOTE: Be sure to unregister short-lived meters and timers otherwise they will leak memory:

// Will call Stop() on the Meter to allow for garbage collection
metrics.Unregister("quux")
// Or similarly for a Timer that embeds a Meter
metrics.Unregister("bang")

Periodically log every metric in human-readable form to standard error:

go metrics.Log(metrics.DefaultRegistry, 5 * time.Second, log.New(os.Stderr, "metrics: ", log.Lmicroseconds))

Periodically log every metric in slightly-more-parseable form to syslog:

w, _ := syslog.Dial("unixgram", "/dev/log", syslog.LOG_INFO, "metrics")
go metrics.Syslog(metrics.DefaultRegistry, 60e9, w)

Periodically emit every metric to Graphite using the Graphite client:


import "github.com/msaf1980/go-metrics/graphite"

go graphite.Graphite(metrics.DefaultRegistry, 10e9, "metrics", "127.0.0.1:2003")

Maintain all metrics along with expvars at /debug/metrics:

This uses the same mechanism as the official expvar but exposed under /debug/metrics, which shows a json representation of all your usual expvars as well as all your go-metrics.

import "github.com/msaf1980/go-metrics/exp"

exp.Exp(metrics.DefaultRegistry)

Installation

go get github.com/msaf1980/go-metrics

Publishing Metrics

Clients are available for the following destinations:

# Packages

Hook go-metrics into expvar on any /debug/metrics request, load all vars from the registry into expvar, and execute regular expvar handler.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

Capture new values for the Go runtime statistics exported in runtime.MemStats.
Capture new values for the Go runtime statistics exported in runtime.MemStats.
Call the given function for each registered metric.
Get the metric by the given name or nil if none is registered.
Gets an existing metric or creates and registers a new one.
GetOrRegisterCounter returns an existing Counter or constructs and registers a new StandardCounter.
GetOrRegisterCounterT returns an existing Counter or constructs and registers a new StandardCounter.
GetOrRegisterDiffer returns an existing Differ or constructs and registers a new StandardDiffer.
GetOrRegisterDifferT returns an existing Differ or constructs and registers a new StandardDiffer.
GetOrRegisterDownCounter returns an existing DownCounter or constructs and registers a new StandardDownCounter.
GetOrRegisterDownCounterT returns an existing DownCounter or constructs and registers a new StandardDownCounter.
GetOrRegisterFGauge returns an existing FGauge or constructs and registers a new StandardFGauge.
GetOrRegisterFGaugeT returns an existing FGauge or constructs and registers a new StandardFGauge.
GetOrRegisterFHistogram returns an existing FHistogram or constructs and registers a new FFixedHistorgam.
GetOrRegisterHistogramT returns an existing Histogram or constructs and registers a new FixedHistorgam.
GetOrRegisterHistogram returns an existing Histogram or constructs and registers a new FixedHistorgam.
GetOrRegisterHistogramT returns an existing Histogram or constructs and registers a new FixedHistorgam.
GetOrRegisterFHistogram returns an existing FHistogram or constructs and registers a new FixedHistorgam (prometheus-like histogram).
GetOrRegisterSumFHistogramT returns an existing FHistogram or constructs and registers a new FixedHistorgam (prometheus-like histogram).
GetOrRegisterHistogram returns an existing Histogram or constructs and registers a new FixedHistorgam (prometheus-like histogram).
GetOrRegisterSumHistogramT returns an existing Histogram or constructs and registers a new FixedHistorgam (prometheus-like histogram).
GetOrRegisterHistogram returns an existing UHistogram or constructs and registers a new FixedHistorgam (prometheus-like histogram).
GetOrRegisterSumUHistogramT returns an existing UHistogram or constructs and registers a new FixedHistorgam (prometheus-like histogram).
GetOrRegisterHistogram returns an existing Histogram or constructs and registers a new FixedHistorgam.
GetOrRegisterHistogramT returns an existing Histogram or constructs and registers a new FixedHistorgam.
GetOrRegisterFRate returns an existing FRate or constructs and registers a new StandardFRate.
GetOrRegisterFRateT returns an existing FRate or constructs and registers a new StandardFRate.
No description provided by the author
No description provided by the author
GetOrRegisterGauge returns an existing Gauge or constructs and registers a new StandardGauge.
GetOrRegisterGaugeT returns an existing Gauge or constructs and registers a new StandardGauge.
GetOrRegisterRate returns an existing Rate or constructs and registers a new StandardRate.
GetOrRegisterRateT returns an existing Rate or constructs and registers a new StandardRate.
Gets an existing metric or creates and registers a new one.
GetOrRegisterUGauge returns an existing UGauge or constructs and registers a new StandardUGauge.
GetOrRegisterUGaugeT returns an existing UGauge or constructs and registers a new StandardUGauge.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Get the metric by the given name or nil if none is registered.
No description provided by the author
No description provided by the author
No description provided by the author
JoinTags convert tags map sorted tags string representation (separated by comma), like tags or Graphite.
No description provided by the author
MergeTags merge two tag maps into one tag map.
No description provided by the author
Register the given metric under the given name.
Register the given metric under the given name.
NewCounter constructs a new StandardCounter.
NewDiffer constructs a new StandardDiffer.
NewDownCounter constructs a new StandardDownCounter.
NewFGauge constructs a new StandardFGauge.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewFRate constructs a new StandardFRate.
No description provided by the author
NewFunctionalGauge constructs a new FunctionalGauge.
NewFunctionalGauge constructs a new FunctionalGauge.
NewFunctionalUGauge constructs a new FunctionalUGauge.
NewGauge constructs a new StandardGauge.
NewHealthcheck constructs a new Healthcheck which will use the given function to update its status.
NewRate constructs a new StandardRate.
NewRegisteredCounter constructs and registers a new StandardCounter.
NewRegisteredCounterT constructs and registers a new StandardCounter.
NewRegisteredDiffer constructs and registers a new StandardDiffer.
NewRegisteredDifferT constructs and registers a new StandardDiffer.
NewRegisteredDownCounter constructs and registers a new StandardDownCounter.
NewRegisteredDownCounterT constructs and registers a new StandardDownCounter.
NewRegisteredFGauge constructs and registers a new StandardFGauge.
NewRegisteredFGaugeT constructs and registers a new StandardFGauge.
NewRegisteredFixedHistogram constructs and registers a new FixedHistogram.
NewRegisteredFixedHistogramT constructs and registers a new FixedHistogram.
NewRegisteredFixedHistogram constructs and registers a new FixedHistogram.
NewRegisteredFixedHistogramT constructs and registers a new FixedHistogram.
NewRegisteredFixedSumFHistogram constructs and registers a new FixedSumFHistogram (prometheus-like histogram).
NewRegisteredFixedSumFHistogramT constructs and registers a new FixedSumFHistogram (prometheus-like histogram).
NewRegisteredFixedSumHistogram constructs and registers a new FixedSumHistogram (prometheus-like histogram).
NewRegisteredFixedSumHistogramT constructs and registers a new FixedSumHistogram (prometheus-like histogram).
NewRegisteredFixedSumUHistogram constructs and registers a new FixedSumUHistogram (prometheus-like histogram).
NewRegisteredFixedSumUHistogramT constructs and registers a new FixedSumUHistogram (prometheus-like histogram).
NewRegisteredFixedHistogram constructs and registers a new FixedHistogram.
NewRegisteredFixedHistogramT constructs and registers a new FixedHistogram.
NewRegisteredFRate constructs and registers a new StandardFRate.
NewRegisteredFRateT constructs and registers a new StandardFRate.
NewRegisteredVHistogram constructs and registers a new VHistogram.
NewRegisteredVHistogramT constructs and registers a new VHistogram.
NewRegisteredFunctionalGauge constructs and registers a new StandardGauge.
NewRegisteredFunctionalGaugeT constructs and registers a new StandardGauge.
NewRegisteredFunctionalGauge constructs and registers a new StandardGauge.
NewRegisteredFunctionalGaugeT constructs and registers a new StandardGauge.
NewRegisteredFunctionalUGauge constructs and registers a new StandardUGauge.
NewRegisteredFunctionalUGaugeT constructs and registers a new StandardUGauge.
NewRegisteredGauge constructs and registers a new StandardGauge.
NewRegisteredGaugeT constructs and registers a new StandardGauge.
NewRegisteredRate constructs and registers a new StandardRate.
NewRegisteredRateT constructs and registers a new StandardRate.
NewRegisteredUGauge constructs and registers a new StandardUGauge.
NewRegisteredUGaugeT constructs and registers a new StandardUGauge.
NewRegisteredVHistogram constructs and registers a new VHistogram.
NewRegisteredVHistogramT constructs and registers a new VHistogram.
NewRegisteredVSumFHistogram constructs and registers a new VSumFHistogram (prometheus-like histogram).
NewRegisteredVSumFHistogramT constructs and registers a new VSumFHistogram (prometheus-like histogram).
NewRegisteredVSumHistogram constructs and registers a new VSumHistogram (prometheus-like histogram).
NewRegisteredVSumHistogramT constructs and registers a new VSumHistogram (prometheus-like histogram).
NewRegisteredVSumUHistogram constructs and registers a new VSumUHistogram (prometheus-like histogram).
NewRegisteredVSumUHistogramT constructs and registers a new VSumUHistogram (prometheus-like histogram).
NewRegisteredVHistogram constructs and registers a new VHistogram.
NewRegisteredVHistogramT constructs and registers a new VHistogram.
Create a new registry.
NewUGauge constructs a new StandardUGauge.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Register the given metric under the given name.
Register runtimeMetrics for the Go runtime statistics exported in runtime and specifically runtime.MemStats.
Register the given metric under the given name.
Run all registered healthchecks.
No description provided by the author
No description provided by the author
No description provided by the author
Unregister the metric with the given name.
Unregister the metric with the given name.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
UseNilMetrics is checked by the constructor functions for all of the standard metrics.

# Structs

No description provided by the author
No description provided by the author
A FixedFHistogram is implementation of FHistogram with fixed-size buckets.
A FixedHistogram is implementation of Histogram with fixed-size buckets.
A FixedSumFHistogram is implementation of prometheus-like FHistogram with fixed-size buckets.
A FixedSumHistogram is implementation of prometheus-like Histogram with fixed-size buckets.
A FixedSumUHistogram is implementation of prometheus-like UHistogram with fixed-size buckets.
A FixedUHistogram is implementation of UHistogram with fixed-size buckets.
FRateSnapshot is a read-only copy of another FRate.
A FUHistogram is implementation of FHistogram with varibale-size buckets.
FunctionalFGauge returns value from given function.
FunctionalGauge returns value from given function.
FunctionalUGauge returns value from given function.
No description provided by the author
No description provided by the author
No description provided by the author
NilCounter is a no-op Counter.
NilDownCounter is a no-op DownCounter.
NilGauge is a no-op Gauge.
No description provided by the author
NilFRate is a no-op FRate.
NilGauge is a no-op Gauge.
NilHealthcheck is a no-op.
No description provided by the author
NilRate is a no-op Rate.
NilUGauge is a no-op UGauge.
No description provided by the author
RateSnapshot is a read-only copy of another Rate.
StandardCounter is the standard implementation of a Counter and uses the sync/atomic package to manage a single uint64 value.
StandardDiffer is the standard implementation of a Differ and uses the sync/atomic package to manage a single int64 value.
StandardDownCounter is the standard implementation of a DownCounter and uses the sync/atomic package to manage a single uint64 value.
StandardFGauge is the standard implementation of a FGauge and uses sync.Mutex to manage a single float64 value.
StandardFRate is the standard implementation of a FRate and uses the sync/atomic package to manage a single int64 value.
StandardGauge is the standard implementation of a Gauge and uses the sync/atomic package to manage a single int64 value.
StandardHealthcheck is the standard implementation of a Healthcheck and stores the status and a function to call to update the status.
StandardRate is the standard implementation of a Rate and uses the sync/atomic package to manage a single int64 value.
The standard implementation of a Registry is a mutex-protected map of names to metrics.
StandardUGauge is the standard implementation of a UGauge and uses the sync/atomic package to manage a single int64 value.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
A VHistogram is implementation of Histogram with varibale-size buckets.
A VSumFHistogram is implementation of prometheus-like FHistogram with varibale-size buckets.
A VSumHistogram is implementation of prometheus-like Histogram with varibale-size buckets.
A VSumUHistogram is implementation of prometheus-like UHistogram with varibale-size buckets.
A VUHistogram is implementation of UHistogram with varibale-size buckets.

# Interfaces

Counters hold an uint64 value that can be incremented only Graphite naming scheme Plain: {PREFIX}.{NAME} Tagged: {TAG_PREFIX}.{NAME}.
DownCounters hold an int64 value that can be incremented/decremented.
FGauges hold a float64 value that can be set arbitrarily.
A FHistogram is a lossy data structure used to record the distribution of non-normally distributed data (like latency) with a high degree of accuracy and a bounded degree of precision.
FRate hold an int64 value and timestamp (current and previous) and return diff and diff/s.
No description provided by the author
Gauges hold an int64 value that can be set arbitrarily.
Healthchecks hold an error value describing an arbitrary up/down status.
A Histogram is a lossy data structure used to record the distribution of non-normally distributed data (like latency) with a high degree of accuracy and a bounded degree of precision.
A HistogramInterface is some strped (no Weights{}, it's not need in registry Each iterator) version of Histogram interface Graphite naming scheme Plain: {PREFIX}.{NAME}{LABEL_BUCKET1} {PREFIX}.{NAME}{LABEL_BUCKET2} {PREFIX}.{NAME}{LABEL_BUCKET_INF} {PREFIX}.{NAME}{TOTAL} Tagged: {TAG_PREFIX}.{NAME}{LABEL_BUCKET1};TAG=VAL;..;le=W1 {TAG_PREFIX}.{NAME}{LABEL_BUCKET2};TAG=VAL;..;le=W2 {TAG_PREFIX}.{NAME}{LABEL_BUCKET_INF};TAG=VAL;..;le=inf {TAG_PREFIX}{NAME}{TOTAL};TAG=VAL;..
Rate hold an int64 value and timestamp (current and previous) and return diff and diff/s.
No description provided by the author
A Registry holds references to a set of metrics by name and can iterate over them, calling callback functions provided by the user.
UGauges hold an int64 value that can be set arbitrarily.
A UHistogram is a lossy data structure used to record the distribution of non-normally distributed data (like latency) with a high degree of accuracy and a bounded degree of precision.
Updated defines the metrics which need to be async updated with Tick.

# Type aliases

CounterSnapshot is a read-only copy of another Counter.
DownCounterSnapshot is a read-only copy of another DownCounter.
DuplicateMetric is the error returned by Registry.Register when a metric already exists.
FGaugeSnapshot is a read-only copy of another FGauge.
GaugeSnapshot is a read-only copy of another Gauge.
UGaugeSnapshot is a read-only copy of another UGauge.