metrics

package module
v0.0.0-...-5ca65ca Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2017 License: BSD-2-Clause-Views Imports: 21 Imported by: 0

README

go-metrics

travis build status

Go port of Coda Hale's Metrics library: https://github.com/dropwizard/metrics.

Documentation: http://godoc.org/github.com/rcrowley/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 := NewRegistry()
g := metrics.NewRegisteredFunctionalGauge("cache-evictions", r, func() int64 { return cache.getEvictionsCount() })

s := metrics.NewExpDecaySample(1028, 0.015) // or metrics.NewUniformSample(1028)
h := metrics.NewHistogram(s)
metrics.Register("baz", h)
h.Update(47)

m := metrics.NewMeter()
metrics.Register("quux", m)
m.Mark(47)

t := metrics.NewTimer()
metrics.Register("bang", t)
t.Time(func() {})
t.Update(47)

Register() is not threadsafe. For threadsafe metric registration use GetOrRegister:

t := metrics.GetOrRegisterTimer("account.create.latency", nil)
t.Time(func() {})
t.Update(47)

Add Meter Types:

增加了两个类型,这两个类型的Register都需要传入参数。同时,写入influxdb时,需要配合使用 github.com/guotie/go-metrics-influxdb

DataMap

DataMap用来记录一系列值的关系和关系的历史变化情况, 并能设置入库间隔时间。

DataMap使用方法如下:

  1. 注册或者获取DataMap,注册时,需要传入一个参数 DataMapOption,定义如下:
type DataMapOption struct {
	Prefix        string
	Interval      time.Duration
	Periods       map[string]time.Duration
	KeyTypes      map[string]reflect.Type
	KeyPeriod     time.Duration // 自变量入库间隔
	DependentVars map[string]*DependentVar
}

其中:

  • Prefix: DataMap的名字
  • Interval: DataMap的入库间隔
  • Periods: DataMap记录的历史值间隔
  • keyTyps: 自变量列表
  • KeyPeriod: 自变量入库间隔
  • DependentVars: 所有需要通过自变量来计算得到的因变量的列表

DependentVar定义如下:

// DependentVar depend var
type DependentVar struct {
	Name     string
	Func     interface{} // 计算规则
	Typ      reflect.Type
	Period   time.Duration
	lastSnap time.Time // 上次snapshot时间
}

其中:

  • Name: 因变量的名字
  • Func: 计算该因变量的函数
  • Typ: 因变量的类型
  • Period:因变量的入库间隔
  • lastSnap: 上次snapshot时间

用法示例如下:


var (
	minute  = time.Minute
	periods = map[string]time.Duration{
		metrics.MS1:  metrics.M1,
		metrics.MS5:  metrics.M5,
		metrics.MS15: metrics.M15,
		metrics.MS30: metrics.M30,
		metrics.HS1:  metrics.H1,
		metrics.DS1:  metrics.D1,
	}

	gaugeType      = reflect.TypeOf(&metrics.StandardCondInt{})
	gaugeFloatType = reflect.TypeOf(&metrics.StandardCondFloat{})

	//  value(k1, curr) / value(k2, curr)
	// ( value(k1, curr) - value(k1, period) ) / ( value(k2, curr) - value(k2, period) )
	relRateFn = func(k1, k2, period string) func(metrics.DataMap) float64 {
		return func(g metrics.DataMap) float64 {
			if period == "" {
				return float64(g.ValueInt64(k1)) / float64(g.ValueInt64(k2))
			}
			// k1当前值
			k1c := g.ValueInt64(k1)
			// k1历史值
			k1p, ok := g.ValueHistory(k1, period)
			if !ok {
				k1p = int64(0)
				return 0.0
			}

			// k2当前值
			k2c := g.ValueInt64(k2)
			// k2历史值
			k2p, ok := g.ValueHistory(k2, period)
			if !ok {
				k2p = int64(0)
				return 0.0
			}

			return float64(k1c-k1p.(int64)) / float64(k2c-k2p.(int64))
		}
	}
	// 返回relRateFn绝对值
	absRelRateFn = func(k1, k2, period string) func(metrics.DataMap) float64 {
		return func(g metrics.DataMap) float64 {
			if period == "" {
				return float64(g.ValueInt64(k1)) / float64(g.ValueInt64(k2))
			}
			// k1当前值
			k1c := g.ValueInt64(k1)
			// k1历史值
			k1p, ok := g.ValueHistory(k1, period)
			if !ok {
				k1p = int64(0)
				return 0.0
			}

			// k2当前值
			k2c := g.ValueInt64(k2)
			// k2历史值
			k2p, ok := g.ValueHistory(k2, period)
			if !ok {
				k2p = int64(0)
				return 0.0
			}

			ret := float64(k1c-k1p.(int64)) / float64(k2c-k2p.(int64))
			if ret < 0 {
				return 0.0
			}
			return ret
		}
	}

	waitTmoRate = func(period string) func(metrics.DataMap) float64 {
		return relRateFn("wait_timeout", "pdpc_total", period)
	}
	updateTmoRate = func(period string) func(metrics.DataMap) float64 {
		return relRateFn("update_waiting_timeout", "update_total", period)
	}

	pdpOpt = &metrics.DataMapOption{
		Interval: minute,
		Periods:  periods,
		DependentVars: map[string]*metrics.DependentVar{
			"wait_tmo_rate": &metrics.DependentVar{
				Func:   waitTmoRate(""),
				Typ:    gaugeFloatType,
				Period: metrics.M1,
			},
			"wait_tmo_rate_1m": &metrics.DependentVar{
				Func:   waitTmoRate(metrics.MS1),
				Typ:    gaugeFloatType,
				Period: metrics.M1,
			},
			"wait_tmo_rate_5m": &metrics.DependentVar{
				Func:   waitTmoRate(metrics.MS5),
				Typ:    gaugeFloatType,
				Period: metrics.M5,
			},
			"wait_tmo_rate_15m": &metrics.DependentVar{
				Func:   waitTmoRate(metrics.MS15),
				Typ:    gaugeFloatType,
				Period: metrics.M15,
			},
			"wait_tmo_rate_30m": &metrics.DependentVar{
				Func:   waitTmoRate(metrics.MS30),
				Typ:    gaugeFloatType,
				Period: metrics.M30,
			},
			"wait_tmo_rate_1h": &metrics.DependentVar{
				Func:   waitTmoRate(metrics.HS1),
				Typ:    gaugeFloatType,
				Period: metrics.H1,
			},
			"wait_tmo_rate_1d": &metrics.DependentVar{
				Func:   waitTmoRate(metrics.DS1),
				Typ:    gaugeFloatType,
				Period: metrics.D1,
			},

			"update_tmo_rate_1m": &metrics.DependentVar{
				Func:   updateTmoRate(metrics.MS1),
				Typ:    gaugeFloatType,
				Period: metrics.M1,
			},
			"update_tmo_rate_5m": &metrics.DependentVar{
				Func:   updateTmoRate(metrics.MS5),
				Typ:    gaugeFloatType,
				Period: metrics.M5,
			},
			"update_tmo_rate_15m": &metrics.DependentVar{
				Func:   updateTmoRate(metrics.MS15),
				Typ:    gaugeFloatType,
				Period: metrics.M15,
			},
			"update_tmo_rate_30m": &metrics.DependentVar{
				Func:   updateTmoRate(metrics.MS30),
				Typ:    gaugeFloatType,
				Period: metrics.M30,
			},
			"update_tmo_rate_1h": &metrics.DependentVar{
				Func:   updateTmoRate(metrics.HS1),
				Typ:    gaugeFloatType,
				Period: metrics.H1,
			},
			"update_tmo_rate_1d": &metrics.DependentVar{
				Func:   updateTmoRate(metrics.DS1),
				Typ:    gaugeFloatType,
				Period: metrics.D1,
			},
		},

		KeyTypes: map[string]reflect.Type{
			"pdpc_online":    gaugeType,
			"wait_list":      gaugeType,
			"update_waiting": gaugeType,
			"pdpc_failed":    gaugeType,
			"update_failed":  gaugeType,
			"pdpu_failed":    gaugeType,
			"ue_failed":      gaugeType,
		},
		KeyPeriod: time.Minute,
	}
)

// convertInt64
func (d *Device) convertInt64(m map[string]interface{}, name string) int64 {
	val, ok := m[name]
	if !ok {
		glog.Warn("convertInt64: province: %s device %d Not found key %s\n",
			d.Province, d.Pid, name)
		return 0
	}
	return int64(val.(float64))
}

// convertFloat64
func (d *Device) convertFloat64(m map[string]interface{}, name string) float64 {
	val, ok := m[name]
	if !ok {
		glog.Warn("convertInt64: province: %s device %d Not found key %s\n",
			d.Province, d.Pid, name)
		return 0.0
	}
	return val.(float64)
}

func (d *Device) processPDP(record map[string]interface{}) {
	dm := metrics.GetOrRegisterDataMap("pdp-"+d.Addr, d.r, pdpOpt)

	dm.UpdateInt64("pdpc_total", d.convertInt64(record, "pdpc_total"))
	dm.UpdateInt64("pdpc_failed", d.convertInt64(record, "pdpc_failed"))
	dm.UpdateInt64("pdpc_online", d.convertInt64(record, "pdpc_online"))
	dm.UpdateInt64("wait_list", d.convertInt64(record, "wait_list"))
	dm.UpdateInt64("wait_timeout", d.convertInt64(record, "wait_timeout"))
	dm.UpdateInt64("update_total", d.convertInt64(record, "update_total"))
	dm.UpdateInt64("update_failed", d.convertInt64(record, "update_failed"))
	dm.UpdateInt64("update_waiting", d.convertInt64(record, "update_waiting"))
	dm.UpdateInt64("update_waiting_timeout", d.convertInt64(record, "update_waiting_timeout"))
	dm.UpdateInt64("pdpu_failed", d.convertInt64(record, "pdpu_failed"))
	dm.UpdateInt64("sec_failed", d.convertInt64(record, "sec_failed"))
	dm.UpdateInt64("ue_failed", d.convertInt64(record, "ue_failed"))
}

PeriodCounter

pc: = metrics.GetOrRegisterPeriodCounter("periodCounter", nil)
pc.SetPeriod(metrics.M1)  // 1 minute
pc.SetPeriod(metrics.M5)  // 5 minute
pc.SetPeriod(metrics.M15) // 15 minute
pc.SetPeriod(metrics.H1)  // 1 hour
pc.SetPeriod(metrics.D1)  // 1 day

pc.Inc(60)
pc.Inc(100)

delta, rate := pc.LatestPeriodCountRate(metrics.M1)
delta, rate = pc.LatestPeriodCountRate(metrics.M5)
delta, rate = pc.LatestPeriodCountRate(metrics.M15)
delta, rate = pc.LatestPeriodCountRate(metrics.H1)
....

This will report period count and rate

GaugeMap

这个是一种可以计算数值历史和数值之间关系的数据类型,数据关系的计算通过设置自定义函数来完成, 非常灵活。

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/cyberdelia/go-metrics-graphite"

addr, _ := net.ResolveTCPAddr("tcp", "127.0.0.1:2003")
go graphite.Graphite(metrics.DefaultRegistry, 10e9, "metrics", addr)

Periodically emit every metric into InfluxDB:

NOTE: this has been pulled out of the library due to constant fluctuations in the InfluxDB API. In fact, all client libraries are on their way out. see issues #121 and #124 for progress and details.

import "github.com/guotie/go-metrics-influxdb"

go influxdb.Influxdb(metrics.DefaultRegistry, 10e9, &influxdb.Config{
    Host:     "127.0.0.1:8086",
    Database: "metrics",
    Username: "test",
    Password: "test",
})

Periodically upload every metric to Librato using the Librato client:

Note: the client included with this repository under the librato package has been deprecated and moved to the repository linked above.

import "github.com/mihasya/go-metrics-librato"

go librato.Librato(metrics.DefaultRegistry,
    10e9,                  // interval
    "example@example.com", // account owner email address
    "token",               // Librato API token
    "hostname",            // source
    []float64{0.95},       // percentiles to send
    time.Millisecond,      // time unit
)

Periodically emit every metric to StatHat:

import "github.com/rcrowley/go-metrics/stathat"

go stathat.Stathat(metrics.DefaultRegistry, 10e9, "example@example.com")

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/rcrowley/go-metrics/exp"

exp.Exp(metrics.DefaultRegistry)

Installation

go get github.com/rcrowley/go-metrics

StatHat support additionally requires their Go client:

go get github.com/stathat/go

Publishing Metrics

Clients are available for the following destinations:

Documentation

Overview

Go port of Coda Hale's Metrics library

<https://github.com/rcrowley/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:

17
1

Index

Examples

Constants

View Source
const (
	// MS1 1 minute
	MS1 = "1m"
	// MS5 5 minute
	MS5 = "5m"
	// MS15 15 minute
	MS15 = "15m"
	// MS30 30 minute
	MS30 = "30m"

	// H1 60 minute, 1 hour
	HS1 = "1h"
	// D1 1 day
	DS1 = "1d"
)

period counter是一个统计一段时间的总和和速率的计数器 例如, 统计5分钟,15分钟,30分钟,60分钟,1天的http请求总量和速率

注意: report 的间隔时间需要小于1分钟

Variables

View Source
var (
	M1  = time.Minute
	M5  = time.Minute * 5
	M15 = time.Minute * 15
	M30 = time.Minute * 30
	H1  = time.Hour
	D1  = time.Hour * 24
)
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 CaptureDebugGCStats

func CaptureDebugGCStats(r Registry, d time.Duration)

Capture new values for the Go garbage collector statistics exported in debug.GCStats. This is designed to be called as a goroutine.

func CaptureDebugGCStatsOnce

func CaptureDebugGCStatsOnce(r Registry)

Capture new values for the Go garbage collector statistics exported in debug.GCStats. This is designed to be called in a background goroutine. Giving a registry which has not been given to RegisterDebugGCStats will panic.

Be careful (but much less so) with this because debug.ReadGCStats calls the C function runtime·lock(runtime·mheap) which, while not a stop-the-world operation, isn't something you want to be doing all the time.

func CaptureRuntimeMemStats

func CaptureRuntimeMemStats(r Registry, 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(r Registry)

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(string, interface{}))

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{}, cb interface{}) interface{}

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

func Graphite

func Graphite(r Registry, d time.Duration, prefix string, addr *net.TCPAddr)

Graphite is a blocking exporter function which reports metrics in r to a graphite server located at addr, flushing them every d duration and prepending metric names with prefix.

Example
addr, _ := net.ResolveTCPAddr("net", ":2003")
go Graphite(DefaultRegistry, 1*time.Second, "some.prefix", addr)
Output:

func GraphiteOnce

func GraphiteOnce(c GraphiteConfig) error

GraphiteOnce performs a single submission to Graphite, returning a non-nil error on failed connections. This can be used in a loop similar to GraphiteWithConfig for custom error handling.

func GraphiteWithConfig

func GraphiteWithConfig(c GraphiteConfig)

GraphiteWithConfig is a blocking exporter function just like Graphite, but it takes a GraphiteConfig instead.

Example
addr, _ := net.ResolveTCPAddr("net", ":2003")
go GraphiteWithConfig(GraphiteConfig{
	Addr:          addr,
	Registry:      DefaultRegistry,
	FlushInterval: 1 * time.Second,
	DurationUnit:  time.Millisecond,
	Percentiles:   []float64{0.5, 0.75, 0.99, 0.999},
})
Output:

func Log

func Log(r Registry, freq time.Duration, l Logger)

func LogScaled

func LogScaled(r Registry, freq time.Duration, scale time.Duration, l Logger)

Output each metric in the given registry periodically using the given logger. Print timings in `scale` units (eg time.Millisecond) rather than nanos.

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 OpenTSDB

func OpenTSDB(r Registry, d time.Duration, prefix string, addr *net.TCPAddr)

OpenTSDB is a blocking exporter function which reports metrics in r to a TSDB server located at addr, flushing them every d duration and prepending metric names with prefix.

Example
addr, _ := net.ResolveTCPAddr("net", ":2003")
go OpenTSDB(DefaultRegistry, 1*time.Second, "some.prefix", addr)
Output:

func OpenTSDBWithConfig

func OpenTSDBWithConfig(c OpenTSDBConfig)

OpenTSDBWithConfig is a blocking exporter function just like OpenTSDB, but it takes a OpenTSDBConfig instead.

Example
addr, _ := net.ResolveTCPAddr("net", ":2003")
go OpenTSDBWithConfig(OpenTSDBConfig{
	Addr:          addr,
	Registry:      DefaultRegistry,
	FlushInterval: 1 * time.Second,
	DurationUnit:  time.Millisecond,
})
Output:

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 RegisterDebugGCStats

func RegisterDebugGCStats(r Registry)

Register metrics for the Go garbage collector statistics exported in debug.GCStats. The metrics are named by their fully-qualified Go symbols, i.e. debug.GCStats.PauseTotal.

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 RunHealthchecks

func RunHealthchecks()

Run all registered healthchecks.

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.

func Syslog

func Syslog(r Registry, d time.Duration, w *syslog.Writer)

Output each metric in the given registry to syslog periodically using the given syslogger.

func Unregister

func Unregister(name string)

Unregister the metric with the given name.

func Write

func Write(r Registry, d time.Duration, w io.Writer)

Write sorts writes each metric in the given registry periodically to the given io.Writer.

func WriteJSON

func WriteJSON(r Registry, d time.Duration, w io.Writer)

WriteJSON writes metrics from the given registry periodically to the specified io.Writer as JSON.

func WriteJSONOnce

func WriteJSONOnce(r Registry, w io.Writer)

WriteJSONOnce writes metrics from the given registry to the specified io.Writer as JSON.

func WriteOnce

func WriteOnce(r Registry, w io.Writer)

WriteOnce sorts and writes metrics in the given registry to the given io.Writer.

Types

type CondFloat

type CondFloat interface {
	Snapshot() CondFloat
	Update(float64)
	Value() float64
	Writable() bool // 是否需要写入
}

CondFloat hold an int64 value that can be set arbitrarily.

func GetOrRegisterCondFloat

func GetOrRegisterCondFloat(name string, r Registry, period time.Duration) CondFloat

GetOrRegisterCondFloat returns an existing Int or constructs and registers a new StandardContInt.

func NewCondFloat

func NewCondFloat(period time.Duration) CondFloat

NewCondFloat constructs a new StandardCondFloat.

type CondFloatSnapshot

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

CondFloatSnapshot is a read-only copy of another Int.

func (*CondFloatSnapshot) Snapshot

func (g *CondFloatSnapshot) Snapshot() CondFloat

Snapshot returns the snapshot.

func (*CondFloatSnapshot) Update

func (g *CondFloatSnapshot) Update(float64)

Update panics.

func (*CondFloatSnapshot) Value

func (g *CondFloatSnapshot) Value() float64

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

func (*CondFloatSnapshot) Writable

func (g *CondFloatSnapshot) Writable() bool

Writable returns the value should write to db

type CondInt

type CondInt interface {
	Snapshot() CondInt
	Update(int64)
	Value() int64
	Writable() bool // 是否需要写入
}

CondInt hold an int64 value that can be set arbitrarily.

func GetOrRegisterCondInt

func GetOrRegisterCondInt(name string, r Registry, period time.Duration) CondInt

GetOrRegisterCondInt returns an existing Int or constructs and registers a new StandardContInt.

func NewCondInt

func NewCondInt(period time.Duration) CondInt

NewCondInt constructs a new StandardCondInt.

type CondIntSnapshot

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

CondIntSnapshot is a read-only copy of another Int.

func (*CondIntSnapshot) Snapshot

func (g *CondIntSnapshot) Snapshot() CondInt

Snapshot returns the snapshot.

func (*CondIntSnapshot) Update

func (g *CondIntSnapshot) Update(int64)

Update panics.

func (*CondIntSnapshot) Value

func (g *CondIntSnapshot) Value() int64

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

func (*CondIntSnapshot) Writable

func (g *CondIntSnapshot) Writable() bool

Writable returns the value should write to db

type Counter

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

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

func GetOrRegisterCounter

func GetOrRegisterCounter(name string, r Registry) Counter

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

type CounterSnapshot

type CounterSnapshot int64

CounterSnapshot is a read-only copy of another Counter.

func (CounterSnapshot) Clear

func (CounterSnapshot) Clear()

Clear panics.

func (CounterSnapshot) Count

func (c CounterSnapshot) Count() int64

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

func (CounterSnapshot) Dec

func (CounterSnapshot) Dec(int64)

Dec panics.

func (CounterSnapshot) Inc

func (CounterSnapshot) Inc(int64)

Inc panics.

func (CounterSnapshot) Snapshot

func (c CounterSnapshot) Snapshot() Counter

Snapshot returns the snapshot.

type DataMap

type DataMap interface {
	Snapshot(r Registry) []interface{}

	UpdateInt64(string, int64)     // 设置自变量的值 int64
	UpdateFloat64(string, float64) // 设置自变量的值 float64

	// Value函数无锁
	Value(string) interface{}    // 自变量的值
	ValueInt64(string) int64     // 自变量的值int64
	ValueFloat64(string) float64 // 自变量的值float64
	ValueHistory(string, string) (interface{}, bool)

	Periods() []string       // 保存那些历史数据
	Keys() []string          // 自变量列表
	DependentKeys() []string // 因变量列表

	SetPeriods(map[string]time.Duration)                              // 历史数据
	SetKeyType(string, reflect.Type, bool)                            // 设置 key type, 自变量
	SetDependentVar(string, interface{}, reflect.Type, time.Duration) // 因变量
}

DataMap hold an int64 value that can be set arbitrarily. DataMap保存一组数据, 和这组数据的历史数据, 并设置可以计算数据关系的函数来计算因变量的值

func GetOrRegisterDataMap

func GetOrRegisterDataMap(name string, r Registry, opt *DataMapOption) DataMap

GetOrRegisterDataMap returns an existing datamap or constructs and registers a new StandardDataMap.

func NewDataMap

func NewDataMap(prefix string, opt *DataMapOption) DataMap

NewDataMap constructs a new StandardDataMap.

func NewRegisteredDataMap

func NewRegisteredDataMap(name string, r Registry, opt *DataMapOption) DataMap

NewRegisteredDataMap constructs and registers a new StandardDataMap.

type DataMapOption

type DataMapOption struct {
	Prefix        string
	Interval      time.Duration
	Periods       map[string]time.Duration
	KeyTypes      map[string]reflect.Type
	KeyPeriod     time.Duration // 自变量入库间隔
	DependentVars map[string]*DependentVar
}

DataMapOption datamap options option of DataMap

type DependentVar

type DependentVar struct {
	Name   string
	Func   interface{} // 计算规则
	Typ    reflect.Type
	Period time.Duration
	// contains filtered or unexported fields
}

DependentVar depend var

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 EWMA

type EWMA interface {
	Rate() float64
	Snapshot() EWMA
	Tick()
	Update(int64)
}

EWMAs continuously calculate an exponentially-weighted moving average based on an outside source of clock ticks.

func NewEWMA

func NewEWMA(alpha float64) EWMA

NewEWMA constructs a new EWMA with the given alpha.

func NewEWMA1

func NewEWMA1() EWMA

NewEWMA1 constructs a new EWMA for a one-minute moving average.

func NewEWMA15

func NewEWMA15() EWMA

NewEWMA15 constructs a new EWMA for a fifteen-minute moving average.

func NewEWMA5

func NewEWMA5() EWMA

NewEWMA5 constructs a new EWMA for a five-minute moving average.

type EWMASnapshot

type EWMASnapshot float64

EWMASnapshot is a read-only copy of another EWMA.

func (EWMASnapshot) Rate

func (a EWMASnapshot) Rate() float64

Rate returns the rate of events per second at the time the snapshot was taken.

func (EWMASnapshot) Snapshot

func (a EWMASnapshot) Snapshot() EWMA

Snapshot returns the snapshot.

func (EWMASnapshot) Tick

func (EWMASnapshot) Tick()

Tick panics.

func (EWMASnapshot) Update

func (EWMASnapshot) Update(int64)

Update panics.

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

func (s *ExpDecaySample) Snapshot() Sample

Snapshot returns a read-only copy of the sample.

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 FloatValueFunc

type FloatValueFunc func(DataMap) float64

FloatValueFunc func which return float64

type FunctionalGauge

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

FunctionalGauge returns value from given function

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
	Update(int64)
	Value() int64
}

Gauges hold an int64 value that can be set arbitrarily.

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, nil)
g.Update(47)
fmt.Println(g.Value()) 
Output:

47

func NewFunctionalGauge

func NewFunctionalGauge(f func() int64) Gauge

NewFunctionalGauge constructs a new FunctionalGauge.

func NewGauge

func NewGauge() Gauge

NewGauge constructs a new StandardGauge.

func NewRegisteredFunctionalGauge

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

NewRegisteredFunctionalGauge constructs and registers a new StandardGauge.

func NewRegisteredGauge

func NewRegisteredGauge(name string, r Registry) Gauge

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

func GetOrRegisterGaugeFloat64

func GetOrRegisterGaugeFloat64(name string, r Registry) GaugeFloat64

GetOrRegisterGaugeFloat64 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 NewRegisteredGaugeFloat64

func NewRegisteredGaugeFloat64(name string, r Registry) GaugeFloat64

NewRegisteredGaugeFloat64 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) 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 GraphiteConfig

type GraphiteConfig struct {
	Addr          *net.TCPAddr  // Network address to connect to
	Registry      Registry      // Registry to be exported
	FlushInterval time.Duration // Flush interval
	DurationUnit  time.Duration // Time conversion unit for durations
	Prefix        string        // Prefix to be prepended to metric names
	Percentiles   []float64     // Percentiles to export from timers and histograms
}

GraphiteConfig provides a container with configuration parameters for the Graphite exporter

type Healthcheck

type Healthcheck interface {
	Check()
	Error() error
	Healthy()
	Unhealthy(error)
}

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

func NewHealthcheck

func NewHealthcheck(f func(Healthcheck)) Healthcheck

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

type Histogram

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

Histograms calculate distribution statistics from a series of int64 values.

func GetOrRegisterHistogram

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

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

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 HistogramSnapshot

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

HistogramSnapshot is a read-only copy of another Histogram.

func (*HistogramSnapshot) Clear

func (*HistogramSnapshot) Clear()

Clear panics.

func (*HistogramSnapshot) Count

func (h *HistogramSnapshot) Count() int64

Count returns the number of samples recorded at the time the snapshot was taken.

func (*HistogramSnapshot) Max

func (h *HistogramSnapshot) Max() int64

Max returns the maximum value in the sample at the time the snapshot was taken.

func (*HistogramSnapshot) Mean

func (h *HistogramSnapshot) Mean() float64

Mean returns the mean of the values in the sample at the time the snapshot was taken.

func (*HistogramSnapshot) Min

func (h *HistogramSnapshot) Min() int64

Min returns the minimum value in the sample at the time the snapshot was taken.

func (*HistogramSnapshot) Percentile

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

Percentile returns an arbitrary percentile of values in the sample at the time the snapshot was taken.

func (*HistogramSnapshot) Percentiles

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

Percentiles returns a slice of arbitrary percentiles of values in the sample at the time the snapshot was taken.

func (*HistogramSnapshot) Sample

func (h *HistogramSnapshot) Sample() Sample

Sample returns the Sample underlying the histogram.

func (*HistogramSnapshot) Snapshot

func (h *HistogramSnapshot) Snapshot() Histogram

Snapshot returns the snapshot.

func (*HistogramSnapshot) StdDev

func (h *HistogramSnapshot) StdDev() float64

StdDev returns the standard deviation of the values in the sample at the time the snapshot was taken.

func (*HistogramSnapshot) Sum

func (h *HistogramSnapshot) Sum() int64

Sum returns the sum in the sample at the time the snapshot was taken.

func (*HistogramSnapshot) Update

func (*HistogramSnapshot) Update(int64)

Update panics.

func (*HistogramSnapshot) Variance

func (h *HistogramSnapshot) Variance() float64

Variance returns the variance of inputs at the time the snapshot was taken.

type IntValueFunc

type IntValueFunc func(DataMap) int64

IntValueFunc func return int64

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

type Meter

type Meter interface {
	Count() int64
	Mark(int64)
	Rate1() float64
	Rate5() float64
	Rate15() float64
	RateMean() float64
	Snapshot() Meter
}

Meters count events to produce exponentially-weighted moving average rates at one-, five-, and fifteen-minutes and a mean rate.

func GetOrRegisterMeter

func GetOrRegisterMeter(name string, r Registry) Meter

GetOrRegisterMeter returns an existing Meter or constructs and registers a new StandardMeter.

func NewMeter

func NewMeter() Meter

NewMeter constructs a new StandardMeter and launches a goroutine.

func NewRegisteredMeter

func NewRegisteredMeter(name string, r Registry) Meter

NewMeter constructs and registers a new StandardMeter and launches a goroutine.

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

func (*MeterSnapshot) Mark(n int64)

Mark panics.

func (*MeterSnapshot) Rate1

func (m *MeterSnapshot) Rate1() float64

Rate1 returns the one-minute moving average rate of events per second at the time the snapshot was taken.

func (*MeterSnapshot) Rate15

func (m *MeterSnapshot) Rate15() float64

Rate15 returns the fifteen-minute moving average rate of events per second at the time the snapshot was taken.

func (*MeterSnapshot) Rate5

func (m *MeterSnapshot) Rate5() float64

Rate5 returns the five-minute moving average rate of events per second at the time the snapshot was taken.

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 NilCounter

type NilCounter struct{}

NilCounter is a no-op Counter.

func (NilCounter) Clear

func (NilCounter) Clear()

Clear is a no-op.

func (NilCounter) Count

func (NilCounter) Count() int64

Count is a no-op.

func (NilCounter) Dec

func (NilCounter) Dec(i int64)

Dec is a no-op.

func (NilCounter) Inc

func (NilCounter) Inc(i int64)

Inc is a no-op.

func (NilCounter) Snapshot

func (NilCounter) Snapshot() Counter

Snapshot is a no-op.

type NilEWMA

type NilEWMA struct{}

NilEWMA is a no-op EWMA.

func (NilEWMA) Rate

func (NilEWMA) Rate() float64

Rate is a no-op.

func (NilEWMA) Snapshot

func (NilEWMA) Snapshot() EWMA

Snapshot is a no-op.

func (NilEWMA) Tick

func (NilEWMA) Tick()

Tick is a no-op.

func (NilEWMA) Update

func (NilEWMA) Update(n int64)

Update is a no-op.

type NilGauge

type NilGauge struct{}

NilGauge is a no-op Gauge.

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

Check is a no-op.

func (NilHealthcheck) Error

func (NilHealthcheck) Error() error

Error is a no-op.

func (NilHealthcheck) Healthy

func (NilHealthcheck) Healthy()

Healthy is a no-op.

func (NilHealthcheck) Unhealthy

func (NilHealthcheck) Unhealthy(error)

Unhealthy is a no-op.

type NilHistogram

type NilHistogram struct{}

NilHistogram is a no-op Histogram.

func (NilHistogram) Clear

func (NilHistogram) Clear()

Clear is a no-op.

func (NilHistogram) Count

func (NilHistogram) Count() int64

Count is a no-op.

func (NilHistogram) Max

func (NilHistogram) Max() int64

Max is a no-op.

func (NilHistogram) Mean

func (NilHistogram) Mean() float64

Mean is a no-op.

func (NilHistogram) Min

func (NilHistogram) Min() int64

Min is a no-op.

func (NilHistogram) Percentile

func (NilHistogram) Percentile(p float64) float64

Percentile is a no-op.

func (NilHistogram) Percentiles

func (NilHistogram) Percentiles(ps []float64) []float64

Percentiles is a no-op.

func (NilHistogram) Sample

func (NilHistogram) Sample() Sample

Sample is a no-op.

func (NilHistogram) Snapshot

func (NilHistogram) Snapshot() Histogram

Snapshot is a no-op.

func (NilHistogram) StdDev

func (NilHistogram) StdDev() float64

StdDev is a no-op.

func (NilHistogram) Sum

func (NilHistogram) Sum() int64

Sum is a no-op.

func (NilHistogram) Update

func (NilHistogram) Update(v int64)

Update is a no-op.

func (NilHistogram) Variance

func (NilHistogram) Variance() float64

Variance is a no-op.

type NilMeter

type NilMeter struct{}

NilMeter is a no-op Meter.

func (NilMeter) Count

func (NilMeter) Count() int64

Count is a no-op.

func (NilMeter) Mark

func (NilMeter) Mark(n int64)

Mark is a no-op.

func (NilMeter) Rate1

func (NilMeter) Rate1() float64

Rate1 is a no-op.

func (NilMeter) Rate15

func (NilMeter) Rate15() float64

Rate15is a no-op.

func (NilMeter) Rate5

func (NilMeter) Rate5() float64

Rate5 is a no-op.

func (NilMeter) RateMean

func (NilMeter) RateMean() float64

RateMean is a no-op.

func (NilMeter) Snapshot

func (NilMeter) Snapshot() Meter

Snapshot is a no-op.

type NilSample

type NilSample struct{}

NilSample is a no-op Sample.

func (NilSample) Clear

func (NilSample) Clear()

Clear is a no-op.

func (NilSample) Count

func (NilSample) Count() int64

Count is a no-op.

func (NilSample) Max

func (NilSample) Max() int64

Max is a no-op.

func (NilSample) Mean

func (NilSample) Mean() float64

Mean is a no-op.

func (NilSample) Min

func (NilSample) Min() int64

Min is a no-op.

func (NilSample) Percentile

func (NilSample) Percentile(p float64) float64

Percentile is a no-op.

func (NilSample) Percentiles

func (NilSample) Percentiles(ps []float64) []float64

Percentiles is a no-op.

func (NilSample) Size

func (NilSample) Size() int

Size is a no-op.

func (NilSample) Snapshot

func (NilSample) Snapshot() Sample

Sample is a no-op.

func (NilSample) StdDev

func (NilSample) StdDev() float64

StdDev is a no-op.

func (NilSample) Sum

func (NilSample) Sum() int64

Sum is a no-op.

func (NilSample) Update

func (NilSample) Update(v int64)

Update is a no-op.

func (NilSample) Values

func (NilSample) Values() []int64

Values is a no-op.

func (NilSample) Variance

func (NilSample) Variance() float64

Variance is a no-op.

type NilTimer

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

NilTimer is a no-op Timer.

func (NilTimer) Count

func (NilTimer) Count() int64

Count is a no-op.

func (NilTimer) Max

func (NilTimer) Max() int64

Max is a no-op.

func (NilTimer) Mean

func (NilTimer) Mean() float64

Mean is a no-op.

func (NilTimer) Min

func (NilTimer) Min() int64

Min is a no-op.

func (NilTimer) Percentile

func (NilTimer) Percentile(p float64) float64

Percentile is a no-op.

func (NilTimer) Percentiles

func (NilTimer) Percentiles(ps []float64) []float64

Percentiles is a no-op.

func (NilTimer) Rate1

func (NilTimer) Rate1() float64

Rate1 is a no-op.

func (NilTimer) Rate15

func (NilTimer) Rate15() float64

Rate15 is a no-op.

func (NilTimer) Rate5

func (NilTimer) Rate5() float64

Rate5 is a no-op.

func (NilTimer) RateMean

func (NilTimer) RateMean() float64

RateMean is a no-op.

func (NilTimer) Snapshot

func (NilTimer) Snapshot() Timer

Snapshot is a no-op.

func (NilTimer) StdDev

func (NilTimer) StdDev() float64

StdDev is a no-op.

func (NilTimer) Sum

func (NilTimer) Sum() int64

Sum is a no-op.

func (NilTimer) Time

func (NilTimer) Time(func())

Time is a no-op.

func (NilTimer) Update

func (NilTimer) Update(time.Duration)

Update is a no-op.

func (NilTimer) UpdateSince

func (NilTimer) UpdateSince(time.Time)

UpdateSince is a no-op.

func (NilTimer) Variance

func (NilTimer) Variance() float64

Variance is a no-op.

type OpenTSDBConfig

type OpenTSDBConfig struct {
	Addr          *net.TCPAddr  // Network address to connect to
	Registry      Registry      // Registry to be exported
	FlushInterval time.Duration // Flush interval
	DurationUnit  time.Duration // Time conversion unit for durations
	Prefix        string        // Prefix to be prepended to metric names
}

OpenTSDBConfig provides a container with configuration parameters for the OpenTSDB exporter

type PeriodCounter

type PeriodCounter interface {
	Clear()
	Inc(int64)
	Count() int64
	LatestPeriodCountRate(string) (int64, float64)

	Periods() []string
	SetPeriod(string, time.Duration)
	SetPeriods(map[string]time.Duration)
	Snapshot() PeriodCounter
	Writable() bool
}

PeriodCounter Period Counter

func GetOrRegisterPeriodCounter

func GetOrRegisterPeriodCounter(name string, r Registry, cb interface{}) PeriodCounter

GetOrRegisterPeriodCounter returns an existing Counter or constructs and registers a new StandardCounter. cb should be type of map[string]time.Duration

func NewPeriodCounter

func NewPeriodCounter(cb interface{}) PeriodCounter

NewPeriodCounter constructs a new StandardPeriodCounter. cb should be type of map[string]time.Duration

func NewRegisteredPeriodCounter

func NewRegisteredPeriodCounter(name string, r Registry, cb interface{}) PeriodCounter

NewRegisteredPeriodCounter constructs and registers a new StandardPeriodCounter. cb is period

type PeriodCounterSnapshot

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

PeriodCounterSnapshot is a read-only copy of another PeriodCounter.

func (*PeriodCounterSnapshot) Clear

func (*PeriodCounterSnapshot) Clear()

Clear panics.

func (*PeriodCounterSnapshot) Count

func (pcs *PeriodCounterSnapshot) Count() int64

Count return count

func (*PeriodCounterSnapshot) Inc

Inc panics.

func (*PeriodCounterSnapshot) LatestPeriodCountRate

func (pcs *PeriodCounterSnapshot) LatestPeriodCountRate(period string) (int64, float64)

LatestPeriodCountRate return period count and rate of the period

func (*PeriodCounterSnapshot) Periods

func (pcs *PeriodCounterSnapshot) Periods() []string

Periods return periods of snapshot

func (*PeriodCounterSnapshot) SetPeriod

SetPeriod panics.

func (*PeriodCounterSnapshot) SetPeriods

func (*PeriodCounterSnapshot) SetPeriods(map[string]time.Duration)

SetPeriods panics.

func (*PeriodCounterSnapshot) Snapshot

func (pcs *PeriodCounterSnapshot) Snapshot() PeriodCounter

Snapshot returns the snapshot.

func (*PeriodCounterSnapshot) Writable

func (pcs *PeriodCounterSnapshot) Writable() bool

Writable return should insert to db

type PrefixedRegistry

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

func (*PrefixedRegistry) Each

func (r *PrefixedRegistry) Each(fn func(string, interface{}))

Call the given function for each registered metric.

func (*PrefixedRegistry) Get

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

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

func (*PrefixedRegistry) GetOrRegister

func (r *PrefixedRegistry) GetOrRegister(name string, metric interface{}, cb interface{}) interface{}

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

func (*PrefixedRegistry) MarshalJSON

func (p *PrefixedRegistry) MarshalJSON() ([]byte, error)

func (*PrefixedRegistry) Register

func (r *PrefixedRegistry) Register(name string, metric interface{}) error

Register the given metric under the given name. The name will be prefixed.

func (*PrefixedRegistry) RunHealthchecks

func (r *PrefixedRegistry) RunHealthchecks()

Run all registered healthchecks.

func (*PrefixedRegistry) Unregister

func (r *PrefixedRegistry) Unregister(name string)

Unregister the metric with the given name. The name will be prefixed.

func (*PrefixedRegistry) UnregisterAll

func (r *PrefixedRegistry) UnregisterAll()

Unregister all metrics. (Mostly for testing.)

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{}

	// Gets 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(string, interface{}, interface{}) interface{}

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

	// Run all registered healthchecks.
	RunHealthchecks()

	// Unregister the metric with the given name.
	Unregister(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 NewPrefixedChildRegistry

func NewPrefixedChildRegistry(parent Registry, prefix string) Registry

func NewPrefixedRegistry

func NewPrefixedRegistry(prefix string) Registry

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
	Snapshot() Sample
	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.

func NewUniformSample

func NewUniformSample(reservoirSize int) Sample

NewUniformSample constructs a new uniform sample with the given reservoir size.

type SampleSnapshot

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

SampleSnapshot is a read-only copy of another Sample.

func NewSampleSnapshot

func NewSampleSnapshot(count int64, values []int64) *SampleSnapshot

func (*SampleSnapshot) Clear

func (*SampleSnapshot) Clear()

Clear panics.

func (*SampleSnapshot) Count

func (s *SampleSnapshot) Count() int64

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

func (*SampleSnapshot) Max

func (s *SampleSnapshot) Max() int64

Max returns the maximal value at the time the snapshot was taken.

func (*SampleSnapshot) Mean

func (s *SampleSnapshot) Mean() float64

Mean returns the mean value at the time the snapshot was taken.

func (*SampleSnapshot) Min

func (s *SampleSnapshot) Min() int64

Min returns the minimal value at the time the snapshot was taken.

func (*SampleSnapshot) Percentile

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

Percentile returns an arbitrary percentile of values at the time the snapshot was taken.

func (*SampleSnapshot) Percentiles

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

Percentiles returns a slice of arbitrary percentiles of values at the time the snapshot was taken.

func (*SampleSnapshot) Size

func (s *SampleSnapshot) Size() int

Size returns the size of the sample at the time the snapshot was taken.

func (*SampleSnapshot) Snapshot

func (s *SampleSnapshot) Snapshot() Sample

Snapshot returns the snapshot.

func (*SampleSnapshot) StdDev

func (s *SampleSnapshot) StdDev() float64

StdDev returns the standard deviation of values at the time the snapshot was taken.

func (*SampleSnapshot) Sum

func (s *SampleSnapshot) Sum() int64

Sum returns the sum of values at the time the snapshot was taken.

func (*SampleSnapshot) Update

func (*SampleSnapshot) Update(int64)

Update panics.

func (*SampleSnapshot) Values

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

Values returns a copy of the values in the sample.

func (*SampleSnapshot) Variance

func (s *SampleSnapshot) Variance() float64

Variance returns the variance of values at the time the snapshot was taken.

type StandardCondFloat

type StandardCondFloat struct {
	sync.Mutex
	// contains filtered or unexported fields
}

StandardCondFloat is the standard implementation of a Int and uses the sync/atomic package to manage a single float64 value.

func (*StandardCondFloat) Snapshot

func (g *StandardCondFloat) Snapshot() CondFloat

Snapshot returns a read-only copy of the Int.

func (*StandardCondFloat) Update

func (g *StandardCondFloat) Update(v float64)

Update updates the gauge's value.

func (*StandardCondFloat) Value

func (g *StandardCondFloat) Value() float64

Value returns the gauge's current value.

func (*StandardCondFloat) Writable

func (g *StandardCondFloat) Writable() bool

Writable return if the gauge should write to db current

type StandardCondInt

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

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

func (*StandardCondInt) Snapshot

func (g *StandardCondInt) Snapshot() CondInt

Snapshot returns a read-only copy of the Int.

func (*StandardCondInt) Update

func (g *StandardCondInt) Update(v int64)

Update updates the gauge's value.

func (*StandardCondInt) Value

func (g *StandardCondInt) Value() int64

Value returns the gauge's current value.

func (*StandardCondInt) Writable

func (g *StandardCondInt) Writable() bool

Writable return if the gauge should write to db current

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

func (c *StandardCounter) Snapshot() Counter

Snapshot returns a read-only copy of the counter.

type StandardDataMap

type StandardDataMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

func (*StandardDataMap) DependentKeys

func (g *StandardDataMap) DependentKeys() []string

DependentKeys return keys

func (*StandardDataMap) Keys

func (g *StandardDataMap) Keys() []string

Keys return keys

func (*StandardDataMap) Periods

func (g *StandardDataMap) Periods() []string

Periods return periods

func (*StandardDataMap) Prefix

func (g *StandardDataMap) Prefix() string

Prefix prefix of datamap

func (*StandardDataMap) SetDependentVar

func (g *StandardDataMap) SetDependentVar(key string, fn interface{}, typ reflect.Type, period time.Duration)

SetDependentVar set IntValueFunc

func (*StandardDataMap) SetKeyType

func (g *StandardDataMap) SetKeyType(key string, ty reflect.Type, isDependent bool)

SetKeyType 设置 key type

func (*StandardDataMap) SetPeriods

func (g *StandardDataMap) SetPeriods(p map[string]time.Duration)

SetPeriods set periods

func (*StandardDataMap) Snapshot

func (g *StandardDataMap) Snapshot(r Registry) []interface{}

Snapshot returns a read-only copy of the gauge. 根据key的类型,输入相应的 meter 同时, snapshot 需要判断是否需要计算历史数据

func (*StandardDataMap) UpdateFloat64

func (g *StandardDataMap) UpdateFloat64(key string, v float64)

UpdateFloat64 updates the gauge's value.

func (*StandardDataMap) UpdateInt64

func (g *StandardDataMap) UpdateInt64(key string, v int64)

UpdateInt64 updates the gauge's value.

func (*StandardDataMap) Value

func (g *StandardDataMap) Value(key string) interface{}

Value returns the gauge's current value. caller should lock

func (*StandardDataMap) ValueFloat64

func (g *StandardDataMap) ValueFloat64(key string) float64

ValueFloat64 return the gauge's float64 value of key. caller should lock

func (*StandardDataMap) ValueHistory

func (g *StandardDataMap) ValueHistory(key, period string) (interface{}, bool)

ValueHistory 历史值 caller should lock

func (*StandardDataMap) ValueInt64

func (g *StandardDataMap) ValueInt64(key string) int64

ValueInt64 get int64 value caller should lock

type StandardEWMA

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

StandardEWMA is the standard implementation of an EWMA and tracks the number of uncounted events and processes them on each tick. It uses the sync/atomic package to manage uncounted events.

func (*StandardEWMA) Rate

func (a *StandardEWMA) Rate() float64

Rate returns the moving average rate of events per second.

func (*StandardEWMA) Snapshot

func (a *StandardEWMA) Snapshot() EWMA

Snapshot returns a read-only copy of the EWMA.

func (*StandardEWMA) Tick

func (a *StandardEWMA) Tick()

Tick ticks the clock to update the moving average. It assumes it is called every five seconds.

func (*StandardEWMA) Update

func (a *StandardEWMA) Update(n int64)

Update adds n uncounted events.

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

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

func (*StandardHealthcheck) Error

func (h *StandardHealthcheck) Error() error

Error returns the healthcheck's status, which will be nil if it is healthy.

func (*StandardHealthcheck) Healthy

func (h *StandardHealthcheck) Healthy()

Healthy marks the healthcheck as healthy.

func (*StandardHealthcheck) Unhealthy

func (h *StandardHealthcheck) Unhealthy(err error)

Unhealthy marks the healthcheck as unhealthy. The error is stored and may be retrieved by the Error method.

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

func (h *StandardHistogram) Snapshot() Histogram

Snapshot returns a read-only copy of 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 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) Mark

func (m *StandardMeter) Mark(n int64)

Mark records the occurance of n events.

func (*StandardMeter) Rate1

func (m *StandardMeter) Rate1() float64

Rate1 returns the one-minute moving average rate of events per second.

func (*StandardMeter) Rate15

func (m *StandardMeter) Rate15() float64

Rate15 returns the fifteen-minute moving average rate of events per second.

func (*StandardMeter) Rate5

func (m *StandardMeter) Rate5() float64

Rate5 returns the five-minute moving average rate of events per second.

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 StandardPeriodCounter

type StandardPeriodCounter struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

StandardPeriodCounter 默认 PeriodCounter 实现

func (*StandardPeriodCounter) Clear

func (pc *StandardPeriodCounter) Clear()

Clear clear count and latestCounts

func (*StandardPeriodCounter) Count

func (pc *StandardPeriodCounter) Count() int64

Count get count

func (*StandardPeriodCounter) Inc

func (pc *StandardPeriodCounter) Inc(i int64)

Inc inc count

func (*StandardPeriodCounter) LatestPeriodCountRate

func (pc *StandardPeriodCounter) LatestPeriodCountRate(period string) (int64, float64)

LatestPeriodCountRate get latest period count rate

func (*StandardPeriodCounter) Periods

func (pc *StandardPeriodCounter) Periods() (periods []string)

Periods get periods of PeriodCounter

func (*StandardPeriodCounter) SetPeriod

func (pc *StandardPeriodCounter) SetPeriod(p string, du time.Duration)

SetPeriod set period

func (*StandardPeriodCounter) SetPeriods

func (pc *StandardPeriodCounter) SetPeriods(ps map[string]time.Duration)

SetPeriods set periods

func (*StandardPeriodCounter) Snapshot

func (pc *StandardPeriodCounter) Snapshot() PeriodCounter

Snapshot snapshot of StandardPeriodCounter

func (*StandardPeriodCounter) Writable

func (pc *StandardPeriodCounter) Writable() bool

Writable return should insert to db

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

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

Gets 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) MarshalJSON

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

MarshalJSON returns a byte slice containing a JSON representation of all the metrics in the Registry.

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

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

func (t *StandardTimer) Count() int64

Count returns the number of events recorded.

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

func (t *StandardTimer) Percentile(p float64) float64

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

func (*StandardTimer) Percentiles

func (t *StandardTimer) Percentiles(ps []float64) []float64

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

func (*StandardTimer) Rate1

func (t *StandardTimer) Rate1() float64

Rate1 returns the one-minute moving average rate of events per second.

func (*StandardTimer) Rate15

func (t *StandardTimer) Rate15() float64

Rate15 returns the fifteen-minute moving average rate of events per second.

func (*StandardTimer) Rate5

func (t *StandardTimer) Rate5() float64

Rate5 returns the five-minute moving average rate of events per second.

func (*StandardTimer) RateMean

func (t *StandardTimer) RateMean() float64

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

func (*StandardTimer) Snapshot

func (t *StandardTimer) Snapshot() Timer

Snapshot returns a read-only copy of the timer.

func (*StandardTimer) StdDev

func (t *StandardTimer) StdDev() float64

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

func (*StandardTimer) Sum

func (t *StandardTimer) Sum() int64

Sum returns the sum in the sample.

func (*StandardTimer) Time

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

Record the duration of the execution of the given function.

func (*StandardTimer) Update

func (t *StandardTimer) Update(d time.Duration)

Record the duration of an event.

func (*StandardTimer) UpdateSince

func (t *StandardTimer) UpdateSince(ts time.Time)

Record the duration of an event that started at a time and ends now.

func (*StandardTimer) Variance

func (t *StandardTimer) Variance() float64

Variance returns the variance of the values in the sample.

type Timer

type Timer interface {
	Count() int64
	Max() int64
	Mean() float64
	Min() int64
	Percentile(float64) float64
	Percentiles([]float64) []float64
	Rate1() float64
	Rate5() float64
	Rate15() float64
	RateMean() float64
	Snapshot() Timer
	StdDev() float64
	Sum() int64
	Time(func())
	Update(time.Duration)
	UpdateSince(time.Time)
	Variance() float64
}

Timers capture the duration and rate of events.

func GetOrRegisterTimer

func GetOrRegisterTimer(name string, r Registry) Timer

GetOrRegisterTimer returns an existing Timer or constructs and registers a new StandardTimer.

Example
m := "account.create.latency"
t := GetOrRegisterTimer(m, nil)
t.Update(47)
fmt.Println(t.Max()) 
Output:

47

func NewCustomTimer

func NewCustomTimer(h Histogram, m Meter) Timer

NewCustomTimer constructs a new StandardTimer from a Histogram and a Meter.

func NewRegisteredTimer

func NewRegisteredTimer(name string, r Registry) Timer

NewRegisteredTimer constructs and registers a new StandardTimer.

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.

type TimerSnapshot

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

TimerSnapshot is a read-only copy of another Timer.

func (*TimerSnapshot) Count

func (t *TimerSnapshot) Count() int64

Count returns the number of events recorded at the time the snapshot was taken.

func (*TimerSnapshot) Max

func (t *TimerSnapshot) Max() int64

Max returns the maximum value at the time the snapshot was taken.

func (*TimerSnapshot) Mean

func (t *TimerSnapshot) Mean() float64

Mean returns the mean value at the time the snapshot was taken.

func (*TimerSnapshot) Min

func (t *TimerSnapshot) Min() int64

Min returns the minimum value at the time the snapshot was taken.

func (*TimerSnapshot) Percentile

func (t *TimerSnapshot) Percentile(p float64) float64

Percentile returns an arbitrary percentile of sampled values at the time the snapshot was taken.

func (*TimerSnapshot) Percentiles

func (t *TimerSnapshot) Percentiles(ps []float64) []float64

Percentiles returns a slice of arbitrary percentiles of sampled values at the time the snapshot was taken.

func (*TimerSnapshot) Rate1

func (t *TimerSnapshot) Rate1() float64

Rate1 returns the one-minute moving average rate of events per second at the time the snapshot was taken.

func (*TimerSnapshot) Rate15

func (t *TimerSnapshot) Rate15() float64

Rate15 returns the fifteen-minute moving average rate of events per second at the time the snapshot was taken.

func (*TimerSnapshot) Rate5

func (t *TimerSnapshot) Rate5() float64

Rate5 returns the five-minute moving average rate of events per second at the time the snapshot was taken.

func (*TimerSnapshot) RateMean

func (t *TimerSnapshot) RateMean() float64

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

func (*TimerSnapshot) Snapshot

func (t *TimerSnapshot) Snapshot() Timer

Snapshot returns the snapshot.

func (*TimerSnapshot) StdDev

func (t *TimerSnapshot) StdDev() float64

StdDev returns the standard deviation of the values at the time the snapshot was taken.

func (*TimerSnapshot) Sum

func (t *TimerSnapshot) Sum() int64

Sum returns the sum at the time the snapshot was taken.

func (*TimerSnapshot) Time

func (*TimerSnapshot) Time(func())

Time panics.

func (*TimerSnapshot) Update

func (*TimerSnapshot) Update(time.Duration)

Update panics.

func (*TimerSnapshot) UpdateSince

func (*TimerSnapshot) UpdateSince(time.Time)

UpdateSince panics.

func (*TimerSnapshot) Variance

func (t *TimerSnapshot) Variance() float64

Variance returns the variance of the values at the time the snapshot was taken.

type UniformSample

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

A uniform sample using Vitter's Algorithm R.

<http://www.cs.umd.edu/~samir/498/vitter.pdf>

func (*UniformSample) Clear

func (s *UniformSample) Clear()

Clear clears all samples.

func (*UniformSample) Count

func (s *UniformSample) Count() int64

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

func (*UniformSample) Max

func (s *UniformSample) 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 (*UniformSample) Mean

func (s *UniformSample) Mean() float64

Mean returns the mean of the values in the sample.

func (*UniformSample) Min

func (s *UniformSample) 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 (*UniformSample) Percentile

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

Percentile returns an arbitrary percentile of values in the sample.

func (*UniformSample) Percentiles

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

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

func (*UniformSample) Size

func (s *UniformSample) Size() int

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

func (*UniformSample) Snapshot

func (s *UniformSample) Snapshot() Sample

Snapshot returns a read-only copy of the sample.

func (*UniformSample) StdDev

func (s *UniformSample) StdDev() float64

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

func (*UniformSample) Sum

func (s *UniformSample) Sum() int64

Sum returns the sum of the values in the sample.

func (*UniformSample) Update

func (s *UniformSample) Update(v int64)

Update samples a new value.

func (*UniformSample) Values

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

Values returns a copy of the values in the sample.

func (*UniformSample) Variance

func (s *UniformSample) Variance() float64

Variance returns the variance of the values in the sample.

Directories

Path Synopsis
cmd
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
Metrics output to StatHat.
Metrics output to StatHat.

Jump to

Keyboard shortcuts

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