metrics

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 11 Imported by: 3

README

go-metrics

Golang metrics library: 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:

Documentation

Overview

Go port of Coda Hale's Metrics library

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

Coda Hale's original work: <https://github.com/codahale/metrics>

Example
c := NewCounter()
Register("money", c)
c.Inc(17)

// Threadsafe registration
// t := GetOrRegisterTimer("db.get.latency", nil)
// t.Time(func() {})
// t.Update(1)

fmt.Println(c.Count())
// fmt.Println(t.Min())
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	RuntimeNames struct {
		MemStats struct {
			Alloc         string
			BuckHashSys   string
			Frees         string
			HeapAlloc     string
			HeapIdle      string
			HeapInUse     string
			HeapObjects   string
			HeapReleased  string
			HeapSys       string
			LastGC        string
			Lookups       string
			Mallocs       string
			MCacheInUse   string
			MCacheSys     string
			MSpanInuse    string
			MSpanSys      string
			NextGC        string
			NumGC         string
			GCCPUFraction string
			// PauseNs       Histogram
			PauseTotalNs string
			StackInUse   string
			StackSys     string
			Sys          string
			TotalAlloc   string
		}
		NumCgoCall   string
		NumGoroutine string
		NumThread    string
	}
)
View Source
var UseNilMetrics bool = false

UseNilMetrics is checked by the constructor functions for all of the standard metrics. If it is true, the metric returned is a stub.

This global kill-switch helps quantify the observer effect and makes for less cluttered pprof profiles.

Functions

func CaptureRuntimeMemStats

func CaptureRuntimeMemStats(d time.Duration)

Capture new values for the Go runtime statistics exported in runtime.MemStats. This is designed to be called as a goroutine.

func CaptureRuntimeMemStatsOnce

func CaptureRuntimeMemStatsOnce()

Capture new values for the Go runtime statistics exported in runtime.MemStats. This is designed to be called in a background goroutine. Giving a registry which has not been given to RegisterRuntimeMemStats will panic.

Be very careful with this because runtime.ReadMemStats calls the C functions runtime·semacquire(&runtime·worldsema) and runtime·stoptheworld() and that last one does what it says on the tin.

func Each

func Each(f func(name, tags string, tagsMap map[string]string, i interface{}) error, minLock bool) error

Call the given function for each registered metric.

func Get

func Get(name string) interface{}

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

func GetOrRegister

func GetOrRegister(name string, i interface{}) interface{}

Gets an existing metric or creates and registers a new one. Threadsafe alternative to calling Get and Register on failure.

func GetOrRegisterT

func GetOrRegisterT(name string, tagsMap map[string]string, i interface{}) interface{}

Gets an existing metric or creates and registers a new one. Threadsafe alternative to calling Get and Register on failure.

func GetT

func GetT(name string, tagsMap map[string]string) interface{}

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

func JoinTags

func JoinTags(tagsMap map[string]string) string

JoinTags convert tags map sorted tags string representation (separated by comma), like tags or Graphite

func Max

func Max(a, b int) int

func MergeTags

func MergeTags(a, b map[string]string) map[string]string

MergeTags merge two tag maps into one tag map

func Min

func Min(a, b int) int

func MustRegister

func MustRegister(name string, i interface{})

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

func MustRegisterT

func MustRegisterT(name string, tagsMap map[string]string, i interface{})

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

func Register

func 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 RegisterRuntimeMemStats

func RegisterRuntimeMemStats(r Registry)

Register runtimeMetrics for the Go runtime statistics exported in runtime and specifically runtime.MemStats. The runtimeMetrics are named by their fully-qualified Go symbols, i.e. runtime.MemStats.Alloc.

func RegisterT

func RegisterT(name string, tagsMap map[string]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 RunHealthchecks

func RunHealthchecks()

Run all registered healthchecks.

func Unregister

func Unregister(name string)

Unregister the metric with the given name.

func UnregisterT

func UnregisterT(name string, tagsMap map[string]string)

Unregister the metric with the given name.

Types

type Counter

type Counter interface {
	Clear() uint64
	Count() uint64
	Inc(uint64)
	Snapshot() Counter
}

Counters hold an uint64 value that can be incremented only

Graphite naming scheme

Plain: {PREFIX}.{NAME}

Tagged: {TAG_PREFIX}.{NAME}

func GetOrRegisterCounter

func GetOrRegisterCounter(name string, r Registry) Counter

GetOrRegisterCounter returns an existing Counter or constructs and registers a new StandardCounter.

func GetOrRegisterCounterT

func GetOrRegisterCounterT(name string, tagsMap map[string]string, r Registry) Counter

GetOrRegisterCounterT returns an existing Counter or constructs and registers a new StandardCounter.

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.

func NewRegisteredCounterT

func NewRegisteredCounterT(name string, tagsMap map[string]string, r Registry) Counter

NewRegisteredCounterT constructs and registers a new StandardCounter.

type CounterSnapshot

type CounterSnapshot uint64

CounterSnapshot is a read-only copy of another Counter.

func (CounterSnapshot) Clear

func (CounterSnapshot) Clear() uint64

Clear panics.

func (CounterSnapshot) Count

func (c CounterSnapshot) Count() uint64

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

func (CounterSnapshot) Inc

func (CounterSnapshot) Inc(uint64)

Inc panics.

func (CounterSnapshot) Snapshot

func (c CounterSnapshot) Snapshot() Counter

Snapshot returns the snapshot.

type DownCounter

type DownCounter interface {
	Clear() int64
	Count() int64
	Inc(int64)
	Dec(int64)
	Snapshot() DownCounter
}

DownCounters hold an int64 value that can be incremented/decremented

func GetOrRegisterDownCounter

func GetOrRegisterDownCounter(name string, r Registry) DownCounter

GetOrRegisterDownCounter returns an existing DownCounter or constructs and registers a new StandardDownCounter.

func GetOrRegisterDownCounterT

func GetOrRegisterDownCounterT(name string, tagsMap map[string]string, r Registry) DownCounter

GetOrRegisterDownCounterT returns an existing DownCounter or constructs and registers a new StandardDownCounter.

func NewDownCounter

func NewDownCounter() DownCounter

NewDownCounter constructs a new StandardDownCounter.

func NewRegisteredDownCounter

func NewRegisteredDownCounter(name string, r Registry) DownCounter

NewRegisteredDownCounter constructs and registers a new StandardDownCounter.

func NewRegisteredDownCounterT

func NewRegisteredDownCounterT(name string, tagsMap map[string]string, r Registry) DownCounter

NewRegisteredDownCounterT constructs and registers a new StandardDownCounter.

type DownCounterSnapshot

type DownCounterSnapshot uint64

DownCounterSnapshot is a read-only copy of another DownCounter.

func (DownCounterSnapshot) Clear

func (DownCounterSnapshot) Clear() int64

Clear panics.

func (DownCounterSnapshot) Count

func (c DownCounterSnapshot) Count() int64

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

func (DownCounterSnapshot) Dec

Inc panics.

func (DownCounterSnapshot) Inc

Inc panics.

func (DownCounterSnapshot) Snapshot

func (c DownCounterSnapshot) Snapshot() DownCounter

Snapshot returns the snapshot.

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 FFixedHistogram

type FFixedHistogram struct {
	FHistogramStorage
	// contains filtered or unexported fields
}

A FFixedHistogram is implementation of FHistogram with fixed-size buckets.

func (*FFixedHistogram) Add

func (h *FFixedHistogram) Add(v float64)

func (*FFixedHistogram) AddLabelPrefix

func (h *FFixedHistogram) AddLabelPrefix(labelPrefix string) FHistogram

func (*FFixedHistogram) SetLabels

func (h *FFixedHistogram) SetLabels(labels []string) FHistogram

func (*FFixedHistogram) SetNameTotal

func (h *FFixedHistogram) SetNameTotal(total string) FHistogram

type FHistogram

type FHistogram interface {
	HistogramInterface
	SetLabels([]string) FHistogram
	AddLabelPrefix(string) FHistogram
	SetNameTotal(string) FHistogram
	Snapshot() FHistogram
	Add(v float64)
	Weights() []float64
}

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.

func GetOrRegisterFFixedHistogram

func GetOrRegisterFFixedHistogram(name string, r Registry, startVal, endVal, width float64) FHistogram

GetOrRegisterFHistogram returns an existing FHistogram or constructs and registers a new FFixedHistorgam.

func GetOrRegisterFFixedHistogramT

func GetOrRegisterFFixedHistogramT(name string, tagsMap map[string]string, r Registry, startVal, endVal, width float64) FHistogram

GetOrRegisterHistogramT returns an existing Histogram or constructs and registers a new FixedHistorgam.

func GetOrRegisterFVHistogram

func GetOrRegisterFVHistogram(name string, r Registry, weights []float64, names []string) FHistogram

func GetOrRegisterFVHistogramT

func GetOrRegisterFVHistogramT(name string, tagsMap map[string]string, r Registry, weights []float64, names []string) FHistogram

func NewFFixedHistogram

func NewFFixedHistogram(startVal, endVal, width float64) FHistogram

func NewRegisteredFFixedHistogram

func NewRegisteredFFixedHistogram(name string, r Registry, startVal, endVal, width float64) FHistogram

NewRegisteredFixedHistogram constructs and registers a new FixedHistogram.

func NewRegisteredFFixedHistogramT

func NewRegisteredFFixedHistogramT(name string, tagsMap map[string]string, r Registry, startVal, endVal, width float64) FHistogram

NewRegisteredFixedHistogramT constructs and registers a new FixedHistogram.

func NewRegisteredFVHistogram

func NewRegisteredFVHistogram(name string, r Registry, weights []float64, names []string) FHistogram

NewRegisteredVHistogram constructs and registers a new VHistogram.

func NewRegisteredFVHistogramT

func NewRegisteredFVHistogramT(name string, tagsMap map[string]string, r Registry, weights []float64, names []string) FHistogram

NewRegisteredVHistogramT constructs and registers a new VHistogram.

type FHistogramSnapshot

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

func (*FHistogramSnapshot) Add

func (h *FHistogramSnapshot) Add(v float64)

func (FHistogramSnapshot) AddLabelPrefix

func (FHistogramSnapshot) AddLabelPrefix(string) FHistogram

func (*FHistogramSnapshot) Clear

func (h *FHistogramSnapshot) Clear() []uint64

func (*FHistogramSnapshot) Interface

func (h *FHistogramSnapshot) Interface() HistogramInterface

for static check compatbility with HistogramInterface

func (*FHistogramSnapshot) IsSummed added in v0.0.4

func (h *FHistogramSnapshot) IsSummed() bool

func (*FHistogramSnapshot) Labels

func (h *FHistogramSnapshot) Labels() []string

func (*FHistogramSnapshot) NameTotal

func (h *FHistogramSnapshot) NameTotal() string

func (FHistogramSnapshot) SetLabels

func (FHistogramSnapshot) SetLabels([]string) FHistogram

func (FHistogramSnapshot) SetNameTotal

func (FHistogramSnapshot) SetNameTotal(string) FHistogram

func (*FHistogramSnapshot) Snapshot

func (h *FHistogramSnapshot) Snapshot() FHistogram

func (*FHistogramSnapshot) Values

func (h *FHistogramSnapshot) Values() []uint64

func (*FHistogramSnapshot) Weights

func (h *FHistogramSnapshot) Weights() []float64

func (*FHistogramSnapshot) WeightsAliases

func (h *FHistogramSnapshot) WeightsAliases() []string

type FHistogramStorage

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

func (*FHistogramStorage) AddLabelPrefix

func (h *FHistogramStorage) AddLabelPrefix(labelPrefix string)

func (*FHistogramStorage) Clear

func (h *FHistogramStorage) Clear() []uint64

func (*FHistogramStorage) Interface

func (h *FHistogramStorage) Interface() HistogramInterface

for static check compatbility with HistogramInterface

func (*FHistogramStorage) IsSummed added in v0.0.4

func (h *FHistogramStorage) IsSummed() bool

func (*FHistogramStorage) Labels

func (h *FHistogramStorage) Labels() []string

func (*FHistogramStorage) NameTotal

func (h *FHistogramStorage) NameTotal() string

func (*FHistogramStorage) SetLabels

func (h *FHistogramStorage) SetLabels(labels []string)

func (*FHistogramStorage) SetNameTotal

func (h *FHistogramStorage) SetNameTotal(total string)

func (*FHistogramStorage) Snapshot

func (h *FHistogramStorage) Snapshot() FHistogram

func (*FHistogramStorage) Values

func (h *FHistogramStorage) Values() []uint64

func (*FHistogramStorage) Weights

func (h *FHistogramStorage) Weights() []float64

func (*FHistogramStorage) WeightsAliases

func (h *FHistogramStorage) WeightsAliases() []string

type FRate

type FRate interface {
	FRateNames
	Snapshot() FRate
	Clear() (float64, float64)
	Update(v float64)
	UpdateTs(v float64, timestamp_ns int64)
	Values() (float64, float64)
}

FRate hold an int64 value and timestamp (current and previous) and return diff and diff/s.

func GetOrRegisterFRate

func GetOrRegisterFRate(name string, r Registry) FRate

GetOrRegisterFRate returns an existing FRate or constructs and registers a new StandardFRate.

Example
m := "server.memory_used"
r := NewRegistry()
g := GetOrRegisterFRate(m, r)
g.UpdateTs(1.1, 1e9)
g.UpdateTs(7.1, 3e9)
fmt.Println(g.Values()) 
Output:

7.1 3

func GetOrRegisterFRateT

func GetOrRegisterFRateT(name string, tagsMap map[string]string, r Registry) FRate

GetOrRegisterFRateT returns an existing FRate or constructs and registers a new StandardFRate.

func NewFRate

func NewFRate() FRate

NewFRate constructs a new StandardFRate.

func NewRegisteredFRate

func NewRegisteredFRate(name string, r Registry) FRate

NewRegisteredFRate constructs and registers a new StandardFRate.

func NewRegisteredFRateT

func NewRegisteredFRateT(name string, tagsMap map[string]string, r Registry) FRate

NewRegisteredFRateT constructs and registers a new StandardFRate.

type FRateNames

type FRateNames interface {
	SetName(string) FRate
	Name() string
	SetRateName(string) FRate
	RateName() string
}

type FRateSnapshot

type FRateSnapshot struct {
	FRate float64
	// contains filtered or unexported fields
}

FRateSnapshot is a read-only copy of another FRate.

func (FRateSnapshot) Clear

func (FRateSnapshot) Clear() (float64, float64)

Clear panics.

func (*FRateSnapshot) Name

func (g *FRateSnapshot) Name() string

func (*FRateSnapshot) RateName

func (g *FRateSnapshot) RateName() string

func (FRateSnapshot) SetName

func (FRateSnapshot) SetName(string) FRate

func (FRateSnapshot) SetRateName

func (FRateSnapshot) SetRateName(string) FRate

func (*FRateSnapshot) Snapshot

func (g *FRateSnapshot) Snapshot() FRate

Snapshot returns the snapshot.

func (FRateSnapshot) Update

func (FRateSnapshot) Update(float64)

Update panics.

func (FRateSnapshot) UpdateTs

func (FRateSnapshot) UpdateTs(float64, int64)

Update panics.

func (*FRateSnapshot) Values

func (g *FRateSnapshot) Values() (float64, float64)

Value returns the value at the time the snapshot was taken.

type FVHistogram

type FVHistogram struct {
	FHistogramStorage
}

A FVHistogram is implementation of FHistogram with varibale-size buckets.

func NewFVHistogram

func NewFVHistogram(weights []float64, names []string) *FVHistogram

func (*FVHistogram) Add

func (h *FVHistogram) Add(v float64)

func (*FVHistogram) AddLabelPrefix

func (h *FVHistogram) AddLabelPrefix(labelPrefix string) FHistogram

func (*FVHistogram) SetLabels

func (h *FVHistogram) SetLabels(labels []string) FHistogram

func (*FVHistogram) SetNameTotal

func (h *FVHistogram) SetNameTotal(total string) FHistogram

func (*FVHistogram) Snapshot

func (h *FVHistogram) Snapshot() FHistogram

func (*FVHistogram) Values

func (h *FVHistogram) Values() []uint64

type FixedHistogram

type FixedHistogram struct {
	HistogramStorage
	// contains filtered or unexported fields
}

A FixedHistogram is implementation of Histogram with fixed-size buckets.

func NewFixedHistogram

func NewFixedHistogram(startVal, endVal, width int64) *FixedHistogram

func (*FixedHistogram) Add

func (h *FixedHistogram) Add(v int64)

func (*FixedHistogram) AddLabelPrefix

func (h *FixedHistogram) AddLabelPrefix(labelPrefix string) Histogram

func (*FixedHistogram) SetLabels

func (h *FixedHistogram) SetLabels(labels []string) Histogram

func (*FixedHistogram) SetNameTotal

func (h *FixedHistogram) SetNameTotal(total string) Histogram

type FixedSumHistogram added in v0.0.4

type FixedSumHistogram struct {
	HistogramStorage
	// contains filtered or unexported fields
}

A FixedSumHistogram is implementation of prometheus-like Histogram with fixed-size buckets.

func NewFixedSumHistogram added in v0.0.4

func NewFixedSumHistogram(startVal, endVal, width int64) *FixedSumHistogram

func (*FixedSumHistogram) Add added in v0.0.4

func (h *FixedSumHistogram) Add(v int64)

func (*FixedSumHistogram) AddLabelPrefix added in v0.0.4

func (h *FixedSumHistogram) AddLabelPrefix(labelPrefix string) Histogram

func (*FixedSumHistogram) Clear added in v0.0.4

func (h *FixedSumHistogram) Clear() []uint64

func (*FixedSumHistogram) IsSummed added in v0.0.4

func (h *FixedSumHistogram) IsSummed() bool

func (*FixedSumHistogram) SetLabels added in v0.0.4

func (h *FixedSumHistogram) SetLabels(labels []string) Histogram

func (*FixedSumHistogram) SetNameTotal added in v0.0.4

func (h *FixedSumHistogram) SetNameTotal(total string) Histogram

type FunctionalGauge

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

FunctionalGauge returns value from given function

func (FunctionalGauge) Clear

func (g FunctionalGauge) Clear() int64

Clear panics.

func (FunctionalGauge) Snapshot

func (g FunctionalGauge) Snapshot() Gauge

Snapshot returns the snapshot.

func (FunctionalGauge) Update

func (FunctionalGauge) Update(int64)

Update panics.

func (FunctionalGauge) Value

func (g FunctionalGauge) Value() int64

Value returns the gauge's current value.

type FunctionalGaugeFloat64

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

FunctionalGaugeFloat64 returns value from given function

func (FunctionalGaugeFloat64) Snapshot

func (g FunctionalGaugeFloat64) Snapshot() GaugeFloat64

Snapshot returns the snapshot.

func (FunctionalGaugeFloat64) Update

Update panics.

func (FunctionalGaugeFloat64) Value

func (g FunctionalGaugeFloat64) Value() float64

Value returns the gauge's current value.

type Gauge

type Gauge interface {
	Snapshot() Gauge
	Clear() int64
	Update(int64)
	Value() int64
}

Gauges hold an int64 value that can be set arbitrarily.

Graphite naming scheme

Plain: {PREFIX}.{NAME}

Tagged: {TAG_PREFIX}.{NAME}

func GetOrRegisterDiffer

func GetOrRegisterDiffer(name string, r Registry, d int64) Gauge

GetOrRegisterDiffer returns an existing Differ or constructs and registers a new StandardDiffer.

Example
m := "server.memory_used"
init := int64(1)
g := GetOrRegisterDiffer(m, NewRegistry(), init)
g.Update(47)
fmt.Println(g.Value()) 
Output:

46

func GetOrRegisterDifferT

func GetOrRegisterDifferT(name string, tagsMap map[string]string, r Registry, d int64) Gauge

GetOrRegisterDifferT returns an existing Differ or constructs and registers a new StandardDiffer.

func GetOrRegisterGauge

func GetOrRegisterGauge(name string, r Registry) Gauge

GetOrRegisterGauge returns an existing Gauge or constructs and registers a new StandardGauge.

Example
m := "server.bytes_sent"
g := GetOrRegisterGauge(m, NewRegistry())
g.Update(47)
fmt.Println(g.Value()) 
Output:

47

func GetOrRegisterGaugeT

func GetOrRegisterGaugeT(name string, tagsMap map[string]string, r Registry) Gauge

GetOrRegisterGaugeT returns an existing Gauge or constructs and registers a new StandardGauge.

func NewDiffer

func NewDiffer(d int64) Gauge

NewDiffer constructs a new StandardDiffer.

func NewFunctionalGauge

func NewFunctionalGauge(f func() int64) Gauge

NewFunctionalGauge constructs a new FunctionalGauge.

func NewGauge

func NewGauge() Gauge

NewGauge constructs a new StandardGauge.

func NewRegisteredDiffer

func NewRegisteredDiffer(name string, r Registry, d int64) Gauge

NewRegisteredDiffer constructs and registers a new StandardDiffer.

func NewRegisteredDifferT

func NewRegisteredDifferT(name string, tagsMap map[string]string, r Registry, d int64) Gauge

NewRegisteredDifferT constructs and registers a new StandardDiffer.

func NewRegisteredFunctionalGauge

func NewRegisteredFunctionalGauge(name string, r Registry, f func() int64) Gauge

NewRegisteredFunctionalGauge constructs and registers a new StandardGauge.

func NewRegisteredFunctionalGaugeT

func NewRegisteredFunctionalGaugeT(name string, tagsMap map[string]string, r Registry, f func() int64) Gauge

NewRegisteredFunctionalGaugeT constructs and registers a new StandardGauge.

func NewRegisteredGauge

func NewRegisteredGauge(name string, r Registry) Gauge

NewRegisteredGauge constructs and registers a new StandardGauge.

func NewRegisteredGaugeT

func NewRegisteredGaugeT(name string, tagsMap map[string]string, r Registry) Gauge

NewRegisteredGaugeT constructs and registers a new StandardGauge.

type GaugeFloat64

type GaugeFloat64 interface {
	Snapshot() GaugeFloat64
	Update(float64)
	Value() float64
}

GaugeFloat64s hold a float64 value that can be set arbitrarily.

Plain: {PREFIX}.{NAME}

Tagged: {TAG_PREFIX}.{NAME}

func GetOrRegisterGaugeFloat64

func GetOrRegisterGaugeFloat64(name string, r Registry) GaugeFloat64

GetOrRegisterGaugeFloat64 returns an existing GaugeFloat64 or constructs and registers a new StandardGaugeFloat64.

func GetOrRegisterGaugeFloat64T

func GetOrRegisterGaugeFloat64T(name string, tagsMap map[string]string, r Registry) GaugeFloat64

GetOrRegisterGaugeFloat64T returns an existing GaugeFloat64 or constructs and registers a new StandardGaugeFloat64.

func NewFunctionalGaugeFloat64

func NewFunctionalGaugeFloat64(f func() float64) GaugeFloat64

NewFunctionalGauge constructs a new FunctionalGauge.

func NewGaugeFloat64

func NewGaugeFloat64() GaugeFloat64

NewGaugeFloat64 constructs a new StandardGaugeFloat64.

func NewRegisteredFunctionalGaugeFloat64

func NewRegisteredFunctionalGaugeFloat64(name string, r Registry, f func() float64) GaugeFloat64

NewRegisteredFunctionalGauge constructs and registers a new StandardGauge.

func NewRegisteredFunctionalGaugeFloat64T

func NewRegisteredFunctionalGaugeFloat64T(name string, tagsMap map[string]string, r Registry, f func() float64) GaugeFloat64

NewRegisteredFunctionalGaugeT constructs and registers a new StandardGauge.

func NewRegisteredGaugeFloat64

func NewRegisteredGaugeFloat64(name string, r Registry) GaugeFloat64

NewRegisteredGaugeFloat64 constructs and registers a new StandardGaugeFloat64.

func NewRegisteredGaugeFloat64T

func NewRegisteredGaugeFloat64T(name string, tagsMap map[string]string, r Registry) GaugeFloat64

NewRegisteredGaugeFloat64T constructs and registers a new StandardGaugeFloat64.

type GaugeFloat64Snapshot

type GaugeFloat64Snapshot float64

GaugeFloat64Snapshot is a read-only copy of another GaugeFloat64.

func (GaugeFloat64Snapshot) Snapshot

func (g GaugeFloat64Snapshot) Snapshot() GaugeFloat64

Snapshot returns the snapshot.

func (GaugeFloat64Snapshot) Update

func (GaugeFloat64Snapshot) Update(float64)

Update panics.

func (GaugeFloat64Snapshot) Value

func (g GaugeFloat64Snapshot) Value() float64

Value returns the value at the time the snapshot was taken.

type GaugeSnapshot

type GaugeSnapshot int64

GaugeSnapshot is a read-only copy of another Gauge.

func (GaugeSnapshot) Clear

func (g GaugeSnapshot) Clear() int64

Clear panics.

func (GaugeSnapshot) Snapshot

func (g GaugeSnapshot) Snapshot() Gauge

Snapshot returns the snapshot.

func (GaugeSnapshot) Update

func (GaugeSnapshot) Update(int64)

Update panics.

func (GaugeSnapshot) Value

func (g GaugeSnapshot) Value() int64

Value returns the value at the time the snapshot was taken.

type Healthcheck

type Healthcheck interface {
	Check() int32
	IsUp() bool
	Status() int32
	Healthy()
	Unhealthy()
}

Healthchecks hold an error value describing an arbitrary up/down status.

func NewHealthcheck

func NewHealthcheck(f func(bool) bool) Healthcheck

NewHealthcheck constructs a new Healthcheck which will use the given function to update its status.

type Histogram

type Histogram interface {
	HistogramInterface
	SetLabels([]string) Histogram
	AddLabelPrefix(string) Histogram
	SetNameTotal(string) Histogram
	Snapshot() Histogram
	Add(v int64)
	Weights() []int64
}

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.

func GetOrRegisterFixedHistogram

func GetOrRegisterFixedHistogram(name string, r Registry, startVal, endVal, width int64) Histogram

GetOrRegisterHistogram returns an existing Histogram or constructs and registers a new FixedHistorgam.

func GetOrRegisterFixedHistogramT

func GetOrRegisterFixedHistogramT(name string, tagsMap map[string]string, r Registry, startVal, endVal, width int64) Histogram

GetOrRegisterHistogramT returns an existing Histogram or constructs and registers a new FixedHistorgam.

func GetOrRegisterFixedSumHistogram added in v0.0.4

func GetOrRegisterFixedSumHistogram(name string, r Registry, startVal, endVal, width int64) Histogram

GetOrRegisterHistogram returns an existing Histogram or constructs and registers a new FixedHistorgam (prometheus-like histogram).

func GetOrRegisterFixedSumHistogramT added in v0.0.4

func GetOrRegisterFixedSumHistogramT(name string, tagsMap map[string]string, r Registry, startVal, endVal, width int64) Histogram

GetOrRegisterSumHistogramT returns an existing Histogram or constructs and registers a new FixedHistorgam (prometheus-like histogram).

func GetOrRegisterVHistogram

func GetOrRegisterVHistogram(name string, r Registry, weights []int64, names []string) Histogram

func GetOrRegisterVHistogramT

func GetOrRegisterVHistogramT(name string, tagsMap map[string]string, r Registry, weights []int64, names []string) Histogram

func GetOrRegisterVSumHistogram added in v0.0.4

func GetOrRegisterVSumHistogram(name string, r Registry, weights []int64, names []string) Histogram

func GetOrRegisterVSumHistogramT added in v0.0.4

func GetOrRegisterVSumHistogramT(name string, tagsMap map[string]string, r Registry, weights []int64, names []string) Histogram

func NewRegisteredFixedHistogram

func NewRegisteredFixedHistogram(name string, r Registry, startVal, endVal, width int64) Histogram

NewRegisteredFixedHistogram constructs and registers a new FixedHistogram.

func NewRegisteredFixedHistogramT

func NewRegisteredFixedHistogramT(name string, tagsMap map[string]string, r Registry, startVal, endVal, width int64) Histogram

NewRegisteredFixedHistogramT constructs and registers a new FixedHistogram.

func NewRegisteredFixedSumHistogram added in v0.0.4

func NewRegisteredFixedSumHistogram(name string, r Registry, startVal, endVal, width int64) Histogram

NewRegisteredFixedSumHistogram constructs and registers a new FixedSumHistogram (prometheus-like histogram).

func NewRegisteredFixedSumHistogramT added in v0.0.4

func NewRegisteredFixedSumHistogramT(name string, tagsMap map[string]string, r Registry, startVal, endVal, width int64) Histogram

NewRegisteredFixedSumHistogramT constructs and registers a new FixedSumHistogram (prometheus-like histogram).

func NewRegisteredVHistogram

func NewRegisteredVHistogram(name string, r Registry, weights []int64, names []string) Histogram

NewRegisteredVHistogram constructs and registers a new VHistogram.

func NewRegisteredVHistogramT

func NewRegisteredVHistogramT(name string, tagsMap map[string]string, r Registry, weights []int64, names []string) Histogram

NewRegisteredVHistogramT constructs and registers a new VHistogram.

func NewRegisteredVSumHistogram added in v0.0.4

func NewRegisteredVSumHistogram(name string, r Registry, weights []int64, names []string) Histogram

NewRegisteredVSumHistogram constructs and registers a new VSumHistogram (prometheus-like histogram).

func NewRegisteredVSumHistogramT added in v0.0.4

func NewRegisteredVSumHistogramT(name string, tagsMap map[string]string, r Registry, weights []int64, names []string) Histogram

NewRegisteredVSumHistogramT constructs and registers a new VSumHistogram (prometheus-like histogram).

type HistogramInterface

type HistogramInterface interface {
	Clear() []uint64
	Values() []uint64
	Labels() []string
	NameTotal() string
	// Tag aliases values (for le key)
	WeightsAliases() []string
	// If true, is prometheus-like (cummulative, increment in bucket[1]  also increment bucket[0])
	IsSummed() bool
}

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;..

type HistogramSnapshot

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

func (*HistogramSnapshot) Add

func (h *HistogramSnapshot) Add(v int64)

func (HistogramSnapshot) AddLabelPrefix

func (HistogramSnapshot) AddLabelPrefix(string) Histogram

func (*HistogramSnapshot) Clear

func (h *HistogramSnapshot) Clear() []uint64

func (*HistogramSnapshot) Interface

func (h *HistogramSnapshot) Interface() HistogramInterface

for static check compatbility with HistogramInterface

func (HistogramSnapshot) IsSummed added in v0.0.4

func (HistogramSnapshot) IsSummed() bool

func (*HistogramSnapshot) Labels

func (h *HistogramSnapshot) Labels() []string

func (*HistogramSnapshot) NameTotal

func (h *HistogramSnapshot) NameTotal() string

func (HistogramSnapshot) SetLabels

func (HistogramSnapshot) SetLabels([]string) Histogram

func (HistogramSnapshot) SetNameTotal

func (HistogramSnapshot) SetNameTotal(string) Histogram

func (*HistogramSnapshot) Snapshot

func (h *HistogramSnapshot) Snapshot() Histogram

func (*HistogramSnapshot) Values

func (h *HistogramSnapshot) Values() []uint64

func (*HistogramSnapshot) Weights

func (h *HistogramSnapshot) Weights() []int64

func (*HistogramSnapshot) WeightsAliases

func (h *HistogramSnapshot) WeightsAliases() []string

type HistogramStorage

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

func (*HistogramStorage) AddLabelPrefix

func (h *HistogramStorage) AddLabelPrefix(labelPrefix string)

func (*HistogramStorage) Clear

func (h *HistogramStorage) Clear() []uint64

func (*HistogramStorage) Interface

func (h *HistogramStorage) Interface() HistogramInterface

for static check compatbility with HistogramInterface

func (*HistogramStorage) IsSummed added in v0.0.4

func (h *HistogramStorage) IsSummed() bool

func (*HistogramStorage) Labels

func (h *HistogramStorage) Labels() []string

func (*HistogramStorage) NameTotal

func (h *HistogramStorage) NameTotal() string

func (*HistogramStorage) SetLabels

func (h *HistogramStorage) SetLabels(labels []string)

func (*HistogramStorage) SetNameTotal

func (h *HistogramStorage) SetNameTotal(total string)

func (*HistogramStorage) Snapshot

func (h *HistogramStorage) Snapshot() Histogram

func (*HistogramStorage) Values

func (h *HistogramStorage) Values() []uint64

func (*HistogramStorage) Weights

func (h *HistogramStorage) Weights() []int64

func (*HistogramStorage) WeightsAliases

func (h *HistogramStorage) WeightsAliases() []string

type NameTagged

type NameTagged struct {
	Name string
	Tags string
}

type NilCounter

type NilCounter struct{}

NilCounter is a no-op Counter.

func (NilCounter) Clear

func (NilCounter) Clear() uint64

Clear is a no-op.

func (NilCounter) Count

func (NilCounter) Count() uint64

Count is a no-op.

func (NilCounter) Inc

func (NilCounter) Inc(i uint64)

Inc is a no-op.

func (NilCounter) Snapshot

func (NilCounter) Snapshot() Counter

Snapshot is a no-op.

type NilDownCounter

type NilDownCounter struct{}

NilDownCounter is a no-op DownCounter.

func (NilDownCounter) Clear

func (NilDownCounter) Clear() int64

Clear is a no-op.

func (NilDownCounter) Count

func (NilDownCounter) Count() int64

Count is a no-op.

func (NilDownCounter) Dec

func (NilDownCounter) Dec(i int64)

func (NilDownCounter) Inc

func (NilDownCounter) Inc(i int64)

Inc is a no-op.

func (NilDownCounter) Snapshot

func (NilDownCounter) Snapshot() DownCounter

Snapshot is a no-op.

type NilFRate

type NilFRate struct{}

NilFRate is a no-op FRate.

func (NilFRate) Clear

func (NilFRate) Clear() (float64, float64)

Clear is a no-op.

func (NilFRate) Name

func (NilFRate) Name() string

func (NilFRate) RateName

func (NilFRate) RateName() string

func (NilFRate) SetName

func (g NilFRate) SetName(string) FRate

func (NilFRate) SetRateName

func (g NilFRate) SetRateName(string) FRate

func (NilFRate) Snapshot

func (NilFRate) Snapshot() FRate

Snapshot is a no-op.

func (NilFRate) Update

func (NilFRate) Update(float64)

Update is a no-op.

func (NilFRate) UpdateTs

func (NilFRate) UpdateTs(float64, int64)

UpdateTs is a no-op.

func (NilFRate) Values

func (NilFRate) Values() (float64, float64)

Value is a no-op.

type NilGauge

type NilGauge struct{}

NilGauge is a no-op Gauge.

func (NilGauge) Clear

func (NilGauge) Clear() int64

Clear is a no-op.

func (NilGauge) Snapshot

func (NilGauge) Snapshot() Gauge

Snapshot is a no-op.

func (NilGauge) Update

func (NilGauge) Update(v int64)

Update is a no-op.

func (NilGauge) Value

func (NilGauge) Value() int64

Value is a no-op.

type NilGaugeFloat64

type NilGaugeFloat64 struct{}

NilGauge is a no-op Gauge.

func (NilGaugeFloat64) Snapshot

func (NilGaugeFloat64) Snapshot() GaugeFloat64

Snapshot is a no-op.

func (NilGaugeFloat64) Update

func (NilGaugeFloat64) Update(v float64)

Update is a no-op.

func (NilGaugeFloat64) Value

func (NilGaugeFloat64) Value() float64

Value is a no-op.

type NilHealthcheck

type NilHealthcheck struct{}

NilHealthcheck is a no-op.

func (NilHealthcheck) Check

func (NilHealthcheck) Check() int32

Check is a no-op.

func (NilHealthcheck) Healthy

func (NilHealthcheck) Healthy()

Healthy is a no-op.

func (NilHealthcheck) IsUp

func (NilHealthcheck) IsUp() bool

IsError is a no-op.

func (NilHealthcheck) Status

func (NilHealthcheck) Status() int32

func (NilHealthcheck) Unhealthy

func (NilHealthcheck) Unhealthy()

Unhealthy is a no-op.

type NilRate

type NilRate struct{}

NilRate is a no-op Rate.

func (NilRate) Clear

func (NilRate) Clear() (int64, float64)

Clear is a no-op.

func (NilRate) Name

func (NilRate) Name() string

func (NilRate) RateName

func (NilRate) RateName() string

func (NilRate) SetName

func (g NilRate) SetName(string) Rate

func (NilRate) SetRateName

func (g NilRate) SetRateName(string) Rate

func (NilRate) Snapshot

func (NilRate) Snapshot() Rate

Snapshot is a no-op.

func (NilRate) Update

func (NilRate) Update(int64)

Update is a no-op.

func (NilRate) UpdateTs

func (NilRate) UpdateTs(int64, int64)

UpdateTs is a no-op.

func (NilRate) Values

func (NilRate) Values() (int64, float64)

Value is a no-op.

type Rate

type Rate interface {
	RateNames
	Snapshot() Rate
	Clear() (int64, float64)
	Update(v int64)
	UpdateTs(v int64, timestamp_ns int64)
	Values() (int64, float64)
}

Rate hold an int64 value and timestamp (current and previous) and return diff and diff/s.

func GetOrRegisterRate

func GetOrRegisterRate(name string, r Registry) Rate

GetOrRegisterRate returns an existing Rate or constructs and registers a new StandardRate.

Example
m := "server.memory_used"
r := NewRegistry()
g := GetOrRegisterRate(m, r)
g.UpdateTs(1, 1e9)
g.UpdateTs(7, 3e9)
fmt.Println(g.Values()) 
Output:

7 3

func GetOrRegisterRateT

func GetOrRegisterRateT(name string, tagsMap map[string]string, r Registry) Rate

GetOrRegisterRateT returns an existing Rate or constructs and registers a new StandardRate.

func NewRate

func NewRate() Rate

NewRate constructs a new StandardRate.

func NewRegisteredRate

func NewRegisteredRate(name string, r Registry) Rate

NewRegisteredRate constructs and registers a new StandardRate.

func NewRegisteredRateT

func NewRegisteredRateT(name string, tagsMap map[string]string, r Registry) Rate

NewRegisteredRateT constructs and registers a new StandardRate.

type RateNames

type RateNames interface {
	SetName(string) Rate
	Name() string
	SetRateName(string) Rate
	RateName() string
}

type RateSnapshot

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

RateSnapshot is a read-only copy of another Rate.

func (RateSnapshot) Clear

func (RateSnapshot) Clear() (int64, float64)

Clear panics.

func (*RateSnapshot) Name

func (g *RateSnapshot) Name() string

func (*RateSnapshot) RateName

func (g *RateSnapshot) RateName() string

func (RateSnapshot) SetName

func (RateSnapshot) SetName(string) Rate

func (RateSnapshot) SetRateName

func (RateSnapshot) SetRateName(string) Rate

func (*RateSnapshot) Snapshot

func (g *RateSnapshot) Snapshot() Rate

Snapshot returns the snapshot.

func (RateSnapshot) Update

func (RateSnapshot) Update(int64)

Update panics.

func (RateSnapshot) UpdateTs

func (RateSnapshot) UpdateTs(int64, int64)

Update panics.

func (*RateSnapshot) Values

func (g *RateSnapshot) Values() (int64, float64)

Value returns the value at the time the snapshot was taken.

type Registry

type Registry interface {

	// Call the given function for each registered metric.
	Each(f func(name string, tags string, tagsMap map[string]string, i interface{}) error, minLock bool) error

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

	// Get the metric by the given name or nil if none is registered.
	GetT(name string, tagsMap map[string]string) interface{}

	// Get an existing metric or registers the given one.
	// The interface can be the metric to register if not found in registry,
	// or a function returning the metric for lazy instantiation.
	GetOrRegister(name string, i interface{}) interface{}

	// Get get an existing metric or registers the given one.
	// The interface can be the metric to register if not found in registry,
	// or a function returning the metric for lazy instantiation.
	GetOrRegisterT(name string, tagsMap map[string]string, i interface{}) interface{}

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

	// Register the given metric under the given name.
	RegisterT(name string, tagsMap map[string]string, i interface{}) error

	// Run all registered healthchecks.
	RunHealthchecks()

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

	// Unregister the metric with the given name.
	UnregisterT(name string, tagsMap map[string]string)

	// Unregister all metrics.  (Mostly for testing.)
	UnregisterAll()
}

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()

func NewRegistry

func NewRegistry() Registry

Create a new registry.

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 uint64 value.

func (*StandardCounter) Clear

func (c *StandardCounter) Clear() uint64

Clear sets the Counter to zero.

func (*StandardCounter) Count

func (c *StandardCounter) Count() uint64

Count returns the current count.

func (*StandardCounter) Inc

func (c *StandardCounter) Inc(i uint64)

Inc increments the Counter by the given amount.

func (*StandardCounter) Snapshot

func (c *StandardCounter) Snapshot() Counter

Snapshot returns a read-only copy of the Counter.

type StandardDiffer

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

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

func (*StandardDiffer) Clear

func (g *StandardDiffer) Clear() int64

Clear sets the DownCounter to zero.

func (*StandardDiffer) Snapshot

func (g *StandardDiffer) Snapshot() Gauge

Snapshot returns a read-only copy of the Differ.

func (*StandardDiffer) Update

func (g *StandardDiffer) Update(v int64)

Update updates the Differ's value.

func (*StandardDiffer) Value

func (g *StandardDiffer) Value() int64

Value returns the Differ's current value.

type StandardDownCounter

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

StandardDownCounter is the standard implementation of a DownCounter and uses the sync/atomic package to manage a single uint64 value.

func (*StandardDownCounter) Clear

func (c *StandardDownCounter) Clear() int64

Clear sets the DownCounter to zero.

func (*StandardDownCounter) Count

func (c *StandardDownCounter) Count() int64

Count returns the current count.

func (*StandardDownCounter) Dec

func (c *StandardDownCounter) Dec(i int64)

Dec decrements the DownCounter by the given amount.

func (*StandardDownCounter) Inc

func (c *StandardDownCounter) Inc(i int64)

Inc increments the DownCounter by the given amount.

func (*StandardDownCounter) Snapshot

func (c *StandardDownCounter) Snapshot() DownCounter

Snapshot returns a read-only copy of the DownCounter.

type StandardFRate

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

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

func (*StandardFRate) Clear

func (g *StandardFRate) Clear() (float64, float64)

Clear sets the DownCounter to zero.

func (*StandardFRate) Name

func (g *StandardFRate) Name() string

func (*StandardFRate) RateName

func (g *StandardFRate) RateName() string

func (*StandardFRate) SetName

func (g *StandardFRate) SetName(name string) FRate

func (*StandardFRate) SetRateName

func (g *StandardFRate) SetRateName(rateName string) FRate

func (*StandardFRate) Snapshot

func (g *StandardFRate) Snapshot() FRate

Snapshot returns a read-only copy of the FRate.

func (*StandardFRate) Update

func (g *StandardFRate) Update(v float64)

Update updates the FRate's value.

func (*StandardFRate) UpdateTs

func (g *StandardFRate) UpdateTs(v float64, ts int64)

UpdateTs updates the FRate's value.

func (*StandardFRate) Values

func (g *StandardFRate) Values() (float64, float64)

Value returns the FRate's current value.

type StandardGauge

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

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

func (*StandardGauge) Clear

func (g *StandardGauge) Clear() int64

Clear sets the DownCounter to zero.

func (*StandardGauge) Snapshot

func (g *StandardGauge) Snapshot() Gauge

Snapshot returns a read-only copy of the gauge.

func (*StandardGauge) Update

func (g *StandardGauge) Update(v int64)

Update updates the gauge's value.

func (*StandardGauge) Value

func (g *StandardGauge) Value() int64

Value returns the gauge's current value.

type StandardGaugeFloat64

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

StandardGaugeFloat64 is the standard implementation of a GaugeFloat64 and uses sync.Mutex to manage a single float64 value.

func (*StandardGaugeFloat64) Snapshot

func (g *StandardGaugeFloat64) Snapshot() GaugeFloat64

Snapshot returns a read-only copy of the gauge.

func (*StandardGaugeFloat64) Update

func (g *StandardGaugeFloat64) Update(v float64)

Update updates the gauge's value.

func (*StandardGaugeFloat64) Value

func (g *StandardGaugeFloat64) Value() float64

Value returns the gauge's current value.

type StandardHealthcheck

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

StandardHealthcheck is the standard implementation of a Healthcheck and stores the status and a function to call to update the status.

func (*StandardHealthcheck) Check

func (h *StandardHealthcheck) Check() int32

Check runs the healthcheck function to update the healthcheck's status.

func (*StandardHealthcheck) Healthy

func (h *StandardHealthcheck) Healthy()

Healthy marks the healthcheck as healthy.

func (*StandardHealthcheck) IsUp

func (h *StandardHealthcheck) IsUp() bool

IsUp returns the healthcheck's status

func (*StandardHealthcheck) Status

func (h *StandardHealthcheck) Status() int32

Status returns the healthcheck's internal status value

func (*StandardHealthcheck) Unhealthy

func (h *StandardHealthcheck) Unhealthy()

Unhealthy marks the healthcheck as unhealthy.

type StandardRate

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

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

func (*StandardRate) Clear

func (g *StandardRate) Clear() (int64, float64)

Clear sets the DownCounter to zero.

func (*StandardRate) Name

func (g *StandardRate) Name() string

func (*StandardRate) RateName

func (g *StandardRate) RateName() string

func (*StandardRate) SetName

func (g *StandardRate) SetName(name string) Rate

func (*StandardRate) SetRateName

func (g *StandardRate) SetRateName(rateName string) Rate

func (*StandardRate) Snapshot

func (g *StandardRate) Snapshot() Rate

Snapshot returns a read-only copy of the Rate.

func (*StandardRate) Update

func (g *StandardRate) Update(v int64)

Update updates the Rate's value.

func (*StandardRate) UpdateTs

func (g *StandardRate) UpdateTs(v int64, ts int64)

UpdateTs updates the Rate's value.

func (*StandardRate) Values

func (g *StandardRate) Values() (int64, float64)

Value returns the Rate's current value.

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, string, map[string]string, interface{}) error, minLock bool) error

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) GetAll

func (r *StandardRegistry) GetAll() map[string]map[string]interface{}

GetAll metrics in the Registry

func (*StandardRegistry) GetOrRegister

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

Get an existing metric or creates and registers a new one. Threadsafe alternative to calling Get and Register on failure. The interface can be the metric to register if not found in registry, or a function returning the metric for lazy instantiation.

func (*StandardRegistry) GetOrRegisterT

func (r *StandardRegistry) GetOrRegisterT(name string, tagsMap map[string]string, i interface{}) interface{}

Get an existing metric or creates and registers a new one. Threadsafe alternative to calling Get and Register on failure. The interface can be the metric to register if not found in registry, or a function returning the metric for lazy instantiation.

func (*StandardRegistry) GetT

func (r *StandardRegistry) GetT(name string, tagsMap map[string]string) interface{}

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) RegisterT

func (r *StandardRegistry) RegisterT(name string, tagsMap map[string]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) RunHealthchecks

func (r *StandardRegistry) RunHealthchecks()

Run all registered healthchecks.

func (*StandardRegistry) Unregister

func (r *StandardRegistry) Unregister(name string)

Unregister the metric with the given name.

func (*StandardRegistry) UnregisterAll

func (r *StandardRegistry) UnregisterAll()

Unregister all metrics. (Mostly for testing.)

func (*StandardRegistry) UnregisterT

func (r *StandardRegistry) UnregisterT(name string, tagsMap map[string]string)

Unregister the metric with the given name.

type SumHistogramSnapshot added in v0.0.4

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

func (*SumHistogramSnapshot) Add added in v0.0.4

func (h *SumHistogramSnapshot) Add(v int64)

func (SumHistogramSnapshot) AddLabelPrefix added in v0.0.4

func (SumHistogramSnapshot) AddLabelPrefix(string) Histogram

func (*SumHistogramSnapshot) Clear added in v0.0.4

func (h *SumHistogramSnapshot) Clear() []uint64

func (*SumHistogramSnapshot) Interface added in v0.0.4

for static check compatbility with HistogramInterface

func (SumHistogramSnapshot) IsSummed added in v0.0.4

func (SumHistogramSnapshot) IsSummed() bool

func (*SumHistogramSnapshot) Labels added in v0.0.4

func (h *SumHistogramSnapshot) Labels() []string

func (*SumHistogramSnapshot) NameTotal added in v0.0.4

func (h *SumHistogramSnapshot) NameTotal() string

func (SumHistogramSnapshot) SetLabels added in v0.0.4

func (SumHistogramSnapshot) SetLabels([]string) Histogram

func (SumHistogramSnapshot) SetNameTotal added in v0.0.4

func (SumHistogramSnapshot) SetNameTotal(string) Histogram

func (*SumHistogramSnapshot) Snapshot added in v0.0.4

func (h *SumHistogramSnapshot) Snapshot() Histogram

func (*SumHistogramSnapshot) Values added in v0.0.4

func (h *SumHistogramSnapshot) Values() []uint64

func (*SumHistogramSnapshot) Weights added in v0.0.4

func (h *SumHistogramSnapshot) Weights() []int64

func (*SumHistogramSnapshot) WeightsAliases added in v0.0.4

func (h *SumHistogramSnapshot) WeightsAliases() []string

type UFixedHistogram

type UFixedHistogram struct {
	UHistogramStorage
	// contains filtered or unexported fields
}

A UFixedHistogram is implementation of UHistogram with fixed-size buckets.

func NewUFixedHistogram

func NewUFixedHistogram(startVal, endVal, width uint64) *UFixedHistogram

func (*UFixedHistogram) Add

func (h *UFixedHistogram) Add(v uint64)

func (*UFixedHistogram) AddLabelPrefix

func (h *UFixedHistogram) AddLabelPrefix(labelPrefix string) UHistogram

func (*UFixedHistogram) SetLabels

func (h *UFixedHistogram) SetLabels(labels []string) UHistogram

func (*UFixedHistogram) SetNameTotal

func (h *UFixedHistogram) SetNameTotal(total string) UHistogram

type UHistogram

type UHistogram interface {
	HistogramInterface
	SetLabels([]string) UHistogram
	AddLabelPrefix(string) UHistogram
	SetNameTotal(string) UHistogram
	Snapshot() UHistogram
	Add(v uint64)
	Weights() []uint64
}

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.

func GetOrRegisterUFixedHistogram

func GetOrRegisterUFixedHistogram(name string, r Registry, startVal, endVal, width uint64) UHistogram

GetOrRegisterHistogram returns an existing Histogram or constructs and registers a new FixedHistorgam.

func GetOrRegisterUFixedHistogramT

func GetOrRegisterUFixedHistogramT(name string, tagsMap map[string]string, r Registry, startVal, endVal, width uint64) UHistogram

GetOrRegisterHistogramT returns an existing Histogram or constructs and registers a new FixedHistorgam.

func GetOrRegisterUVHistogram

func GetOrRegisterUVHistogram(name string, r Registry, weights []uint64, names []string) UHistogram

func GetOrRegisterUVHistogramT

func GetOrRegisterUVHistogramT(name string, tagsMap map[string]string, r Registry, weights []uint64, names []string) UHistogram

func NewRegisteredUFixedHistogram

func NewRegisteredUFixedHistogram(name string, r Registry, startVal, endVal, width uint64) UHistogram

NewRegisteredFixedHistogram constructs and registers a new FixedHistogram.

func NewRegisteredUFixedHistogramT

func NewRegisteredUFixedHistogramT(name string, tagsMap map[string]string, r Registry, startVal, endVal, width uint64) UHistogram

NewRegisteredFixedHistogramT constructs and registers a new FixedHistogram.

func NewRegisteredUVHistogram

func NewRegisteredUVHistogram(name string, r Registry, weights []uint64, names []string) UHistogram

NewRegisteredVHistogram constructs and registers a new VHistogram.

func NewRegisteredUVHistogramT

func NewRegisteredUVHistogramT(name string, tagsMap map[string]string, r Registry, weights []uint64, names []string) UHistogram

NewRegisteredVHistogramT constructs and registers a new VHistogram.

type UHistogramSnapshot

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

func (*UHistogramSnapshot) Add

func (h *UHistogramSnapshot) Add(v uint64)

func (UHistogramSnapshot) AddLabelPrefix

func (UHistogramSnapshot) AddLabelPrefix(string) UHistogram

func (*UHistogramSnapshot) Clear

func (h *UHistogramSnapshot) Clear() []uint64

func (*UHistogramSnapshot) Interface

func (h *UHistogramSnapshot) Interface() HistogramInterface

for static check compatbility with HistogramInterface

func (*UHistogramSnapshot) IsSummed added in v0.0.4

func (h *UHistogramSnapshot) IsSummed() bool

func (*UHistogramSnapshot) Labels

func (h *UHistogramSnapshot) Labels() []string

func (*UHistogramSnapshot) NameTotal

func (h *UHistogramSnapshot) NameTotal() string

func (UHistogramSnapshot) SetLabels

func (UHistogramSnapshot) SetLabels([]string) UHistogram

func (UHistogramSnapshot) SetNameTotal

func (UHistogramSnapshot) SetNameTotal(string) UHistogram

func (*UHistogramSnapshot) Snapshot

func (h *UHistogramSnapshot) Snapshot() UHistogram

func (*UHistogramSnapshot) Values

func (h *UHistogramSnapshot) Values() []uint64

func (*UHistogramSnapshot) Weights

func (h *UHistogramSnapshot) Weights() []uint64

func (*UHistogramSnapshot) WeightsAliases

func (h *UHistogramSnapshot) WeightsAliases() []string

type UHistogramStorage

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

func (*UHistogramStorage) AddLabelPrefix

func (h *UHistogramStorage) AddLabelPrefix(labelPrefix string)

func (*UHistogramStorage) Clear

func (h *UHistogramStorage) Clear() []uint64

func (*UHistogramStorage) Interface

func (h *UHistogramStorage) Interface() HistogramInterface

for static check compatbility with HistogramInterface

func (*UHistogramStorage) IsSummed added in v0.0.4

func (h *UHistogramStorage) IsSummed() bool

func (*UHistogramStorage) Labels

func (h *UHistogramStorage) Labels() []string

func (*UHistogramStorage) NameTotal

func (h *UHistogramStorage) NameTotal() string

func (*UHistogramStorage) SetLabels

func (h *UHistogramStorage) SetLabels(labels []string)

func (*UHistogramStorage) SetNameTotal

func (h *UHistogramStorage) SetNameTotal(total string)

func (*UHistogramStorage) Snapshot

func (h *UHistogramStorage) Snapshot() UHistogram

func (*UHistogramStorage) Values

func (h *UHistogramStorage) Values() []uint64

func (*UHistogramStorage) Weights

func (h *UHistogramStorage) Weights() []uint64

func (*UHistogramStorage) WeightsAliases

func (h *UHistogramStorage) WeightsAliases() []string

type UVHistogram

type UVHistogram struct {
	UHistogramStorage
}

A UVHistogram is implementation of UHistogram with varibale-size buckets.

func NewUVHistogram

func NewUVHistogram(weights []uint64, labels []string) *UVHistogram

func (*UVHistogram) Add

func (h *UVHistogram) Add(v uint64)

func (*UVHistogram) AddLabelPrefix

func (h *UVHistogram) AddLabelPrefix(labelPrefix string) UHistogram

func (*UVHistogram) SetLabels

func (h *UVHistogram) SetLabels(labels []string) UHistogram

func (*UVHistogram) SetNameTotal

func (h *UVHistogram) SetNameTotal(total string) UHistogram

func (*UVHistogram) Snapshot

func (h *UVHistogram) Snapshot() UHistogram

func (*UVHistogram) Values

func (h *UVHistogram) Values() []uint64

type Updated

type Updated interface {
	Update()
}

Updated defines the metrics which need to be async updated with Tick.

type VHistogram

type VHistogram struct {
	HistogramStorage
}

A VHistogram is implementation of Histogram with varibale-size buckets.

func NewVHistogram

func NewVHistogram(weights []int64, labels []string) *VHistogram

func (*VHistogram) Add

func (h *VHistogram) Add(v int64)

func (*VHistogram) AddLabelPrefix

func (h *VHistogram) AddLabelPrefix(labelPrefix string) Histogram

func (*VHistogram) Interface

func (h *VHistogram) Interface() HistogramInterface

for static check compatbility with HistogramInterface

func (*VHistogram) SetLabels

func (h *VHistogram) SetLabels(labels []string) Histogram

func (*VHistogram) SetNameTotal

func (h *VHistogram) SetNameTotal(total string) Histogram

func (*VHistogram) Snapshot

func (h *VHistogram) Snapshot() Histogram

func (*VHistogram) Values

func (h *VHistogram) Values() []uint64

func (*VHistogram) WeightsAliases

func (h *VHistogram) WeightsAliases() []string

type VSumHistogram added in v0.0.4

type VSumHistogram struct {
	HistogramStorage
}

A VSumHistogram is implementation of prometheus-like Histogram with varibale-size buckets.

func NewVSumHistogram added in v0.0.4

func NewVSumHistogram(weights []int64, names []string) *VSumHistogram

func (*VSumHistogram) Add added in v0.0.4

func (h *VSumHistogram) Add(v int64)

func (*VSumHistogram) AddLabelPrefix added in v0.0.4

func (h *VSumHistogram) AddLabelPrefix(labelPrefix string) Histogram

func (*VSumHistogram) Interface added in v0.0.4

func (h *VSumHistogram) Interface() HistogramInterface

for static check compatbility with HistogramInterface

func (*VSumHistogram) IsSummed added in v0.0.4

func (h *VSumHistogram) IsSummed() bool

func (*VSumHistogram) SetLabels added in v0.0.4

func (h *VSumHistogram) SetLabels(labels []string) Histogram

func (*VSumHistogram) SetNameTotal added in v0.0.4

func (h *VSumHistogram) SetNameTotal(total string) Histogram

func (*VSumHistogram) Snapshot added in v0.0.4

func (h *VSumHistogram) Snapshot() Histogram

func (*VSumHistogram) Values added in v0.0.4

func (h *VSumHistogram) Values() []uint64

func (*VSumHistogram) WeightsAliases added in v0.0.4

func (h *VSumHistogram) WeightsAliases() []string

type ValTagged

type ValTagged struct {
	I       interface{}
	TagsMap map[string]string
}

Directories

Path Synopsis
Hook go-metrics into expvar on any /debug/metrics request, load all vars from the registry into expvar, and execute regular expvar handler
Hook go-metrics into expvar on any /debug/metrics request, load all vars from the registry into expvar, and execute regular expvar handler

Jump to

Keyboard shortcuts

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