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() { time.Sleep(10 * time.Millisecond) }) t.Update(1) fmt.Println(c.Snapshot().Count()) fmt.Println(t.Snapshot().Min())
Output: 17 1
Index ¶
- Constants
- Variables
- func CalculatePercentiles(values []int64, ps []float64) []float64
- func CaptureDebugGCStats(r Registry, d time.Duration)
- func CaptureDebugGCStatsOnce(r Registry)
- func CollectProcessMetrics(refresh time.Duration)
- func Each(f func(string, interface{}))
- func Get(name string) interface{}
- func GetOrRegister(name string, i interface{}) interface{}
- func Graphite(r Registry, d time.Duration, prefix string, addr *net.TCPAddr)
- func GraphiteOnce(c GraphiteConfig) error
- func GraphiteWithConfig(c GraphiteConfig)
- func Log(r Registry, freq time.Duration, l Logger)
- func LogScaled(r Registry, freq time.Duration, scale time.Duration, l Logger)
- func MustRegister(name string, i interface{})
- func OpenTSDB(r Registry, d time.Duration, prefix string, addr *net.TCPAddr)
- func OpenTSDBWithConfig(c OpenTSDBConfig)
- func ReadCPUStats(stats *CPUStats)
- func ReadDiskStats(stats *DiskStats) error
- func ReadRuntimeStats() *runtimeStats
- func Register(name string, i interface{}) error
- func RegisterDebugGCStats(r Registry)
- func RunHealthchecks()
- func RuntimeHistogramFromData(scale float64, hist *metrics.Float64Histogram) *runtimeHistogram
- func SamplePercentile(values []int64, p float64) float64
- func SampleVariance(mean float64, values []int64) float64
- func Syslog(r Registry, d time.Duration, w *syslog.Writer)
- func Unregister(name string)
- func Write(r Registry, d time.Duration, w io.Writer)
- func WriteJSON(r Registry, d time.Duration, w io.Writer)
- func WriteJSONOnce(r Registry, w io.Writer)
- func WriteOnce(r Registry, w io.Writer)
- type CPUStats
- type Config
- type Counter
- func GetOrRegisterCounter(name string, r Registry) Counter
- func GetOrRegisterCounterForced(name string, r Registry) Counter
- func NewCounter() Counter
- func NewCounterForced() Counter
- func NewRegisteredCounter(name string, r Registry) Counter
- func NewRegisteredCounterForced(name string, r Registry) Counter
- type CounterFloat64
- func GetOrRegisterCounterFloat64(name string, r Registry) CounterFloat64
- func GetOrRegisterCounterFloat64Forced(name string, r Registry) CounterFloat64
- func NewCounterFloat64() CounterFloat64
- func NewCounterFloat64Forced() CounterFloat64
- func NewRegisteredCounterFloat64(name string, r Registry) CounterFloat64
- func NewRegisteredCounterFloat64Forced(name string, r Registry) CounterFloat64
- type CounterFloat64Snapshot
- type CounterSnapshot
- type DiskStats
- type DuplicateMetric
- type EWMA
- type EWMASnapshot
- type ExpDecaySample
- type Gauge
- type GaugeFloat64
- type GaugeFloat64Snapshot
- type GaugeInfo
- type GaugeInfoSnapshot
- type GaugeInfoValue
- type GaugeSnapshot
- type GraphiteConfig
- type Healthcheck
- type Histogram
- type HistogramSnapshot
- type Logger
- type Meter
- type MeterSnapshot
- type NilCounter
- type NilCounterFloat64
- type NilEWMA
- type NilGauge
- type NilGaugeFloat64
- type NilGaugeInfo
- type NilHealthcheck
- type NilHistogram
- type NilMeter
- type NilResettingTimer
- func (NilResettingTimer) Count() int
- func (NilResettingTimer) Max() int64
- func (NilResettingTimer) Mean() float64
- func (NilResettingTimer) Min() int64
- func (NilResettingTimer) Percentiles([]float64) []float64
- func (n NilResettingTimer) Snapshot() ResettingTimerSnapshot
- func (NilResettingTimer) Time(f func())
- func (NilResettingTimer) Update(time.Duration)
- func (NilResettingTimer) UpdateSince(time.Time)
- func (NilResettingTimer) Values() []int64
- type NilSample
- type NilTimer
- type OpenTSDBConfig
- type PrefixedRegistry
- func (r *PrefixedRegistry) Each(fn func(string, interface{}))
- func (r *PrefixedRegistry) Get(name string) interface{}
- func (r *PrefixedRegistry) GetAll() map[string]map[string]interface{}
- func (r *PrefixedRegistry) GetOrRegister(name string, metric interface{}) interface{}
- func (r *PrefixedRegistry) MarshalJSON() ([]byte, error)
- func (r *PrefixedRegistry) Register(name string, metric interface{}) error
- func (r *PrefixedRegistry) RunHealthchecks()
- func (r *PrefixedRegistry) Unregister(name string)
- type Registry
- type ResettingTimer
- type ResettingTimerSnapshot
- type Sample
- type SampleSnapshot
- type StandardCounter
- type StandardCounterFloat64
- type StandardEWMA
- type StandardGauge
- type StandardGaugeFloat64
- type StandardGaugeInfo
- type StandardHealthcheck
- type StandardHistogram
- type StandardMeter
- type StandardRegistry
- func (r *StandardRegistry) Each(f func(string, interface{}))
- func (r *StandardRegistry) Get(name string) interface{}
- func (r *StandardRegistry) GetAll() map[string]map[string]interface{}
- func (r *StandardRegistry) GetOrRegister(name string, i interface{}) interface{}
- func (r *StandardRegistry) MarshalJSON() ([]byte, error)
- func (r *StandardRegistry) Register(name string, i interface{}) error
- func (r *StandardRegistry) RunHealthchecks()
- func (r *StandardRegistry) Unregister(name string)
- type StandardResettingTimer
- type StandardTimer
- type Stoppable
- type Timer
- type TimerSnapshot
- type UniformSample
Examples ¶
Constants ¶
const InitialResettingTimerSliceCap = 10
Initial slice capacity for the values stored in a ResettingTimer
Variables ¶
var ( DefaultRegistry = NewRegistry() EphemeralRegistry = NewRegistry() AccountingRegistry = NewRegistry() // registry used in swarm )
var DefaultConfig = Config{ Enabled: false, EnabledExpensive: false, HTTP: "127.0.0.1", Port: 6060, EnableInfluxDB: false, InfluxDBEndpoint: "http://localhost:8086", InfluxDBDatabase: "geth", InfluxDBUsername: "test", InfluxDBPassword: "test", InfluxDBTags: "host=localhost", EnableInfluxDBV2: false, InfluxDBToken: "test", InfluxDBBucket: "geth", InfluxDBOrganization: "geth", }
DefaultConfig is the default config for metrics used in go-ethereum.
var Enabled = false
Enabled 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 CalculatePercentiles ¶
CalculatePercentiles returns a slice of arbitrary percentiles of the slice of int64. This method returns interpolated results, so e.g. if there are only two values, [0, 10], a 50% percentile will land between them.
Note: As a side-effect, this method will also sort the slice of values. Note2: The input format for percentiles is NOT percent! To express 50%, use 0.5, not 50.
func CaptureDebugGCStats ¶
CaptureDebugGCStats captures 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)
CaptureDebugGCStatsOnce captures 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 CollectProcessMetrics ¶
CollectProcessMetrics periodically collects various metrics about the running process.
func Each ¶
func Each(f func(string, interface{}))
Each 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{}
GetOrRegister gets an existing metric or creates and registers a new one. Threadsafe alternative to calling Get and Register on failure.
func Graphite ¶
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 LogScaled ¶
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{})
MustRegister register the given metric under the given name. Panics if a metric by the given name is already registered.
func OpenTSDB ¶
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 ReadCPUStats ¶
func ReadCPUStats(stats *CPUStats)
ReadCPUStats retrieves the current CPU stats.
func ReadDiskStats ¶
ReadDiskStats retrieves the disk IO stats belonging to the current process.
func ReadRuntimeStats ¶
func ReadRuntimeStats() *runtimeStats
func Register ¶
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)
RegisterDebugGCStats registers 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 RuntimeHistogramFromData ¶
func RuntimeHistogramFromData(scale float64, hist *metrics.Float64Histogram) *runtimeHistogram
func SamplePercentile ¶
SamplePercentile returns an arbitrary percentile of the slice of int64.
func SampleVariance ¶
SampleVariance returns the variance of the slice of int64.
func Syslog ¶
Output each metric in the given registry to syslog periodically using the given syslogger.
func Write ¶
Write sorts writes each metric in the given registry periodically to the given io.Writer.
func WriteJSON ¶
WriteJSON writes metrics from the given registry periodically to the specified io.Writer as JSON.
func WriteJSONOnce ¶
WriteJSONOnce writes metrics from the given registry to the specified io.Writer as JSON.
Types ¶
type CPUStats ¶
type CPUStats struct { GlobalTime float64 // Time spent by the CPU working on all processes GlobalWait float64 // Time spent by waiting on disk for all processes LocalTime float64 // Time spent by the CPU working on this process }
CPUStats is the system and process CPU stats. All values are in seconds.
type Config ¶
type Config struct { Enabled bool `toml:",omitempty"` EnabledExpensive bool `toml:"-"` HTTP string `toml:",omitempty"` Port int `toml:",omitempty"` EnableInfluxDB bool `toml:",omitempty"` InfluxDBEndpoint string `toml:",omitempty"` InfluxDBDatabase string `toml:",omitempty"` InfluxDBUsername string `toml:",omitempty"` InfluxDBPassword string `toml:",omitempty"` InfluxDBTags string `toml:",omitempty"` EnableInfluxDBV2 bool `toml:",omitempty"` InfluxDBToken string `toml:",omitempty"` InfluxDBBucket string `toml:",omitempty"` InfluxDBOrganization string `toml:",omitempty"` }
Config contains the configuration for the metric collection.
type Counter ¶
type Counter interface { Clear() Dec(int64) Inc(int64) Snapshot() CounterSnapshot }
Counter hold an int64 value that can be incremented and decremented.
func GetOrRegisterCounter ¶
GetOrRegisterCounter returns an existing Counter or constructs and registers a new StandardCounter.
func GetOrRegisterCounterForced ¶
GetOrRegisterCounterForced returns an existing Counter or constructs and registers a new Counter no matter the global switch is enabled or not. Be sure to unregister the counter from the registry once it is of no use to allow for garbage collection.
func NewCounterForced ¶
func NewCounterForced() Counter
NewCounterForced constructs a new StandardCounter and returns it no matter if the global switch is enabled or not.
func NewRegisteredCounter ¶
NewRegisteredCounter constructs and registers a new StandardCounter.
func NewRegisteredCounterForced ¶
NewRegisteredCounterForced constructs and registers a new StandardCounter and launches a goroutine no matter the global switch is enabled or not. Be sure to unregister the counter from the registry once it is of no use to allow for garbage collection.
type CounterFloat64 ¶
type CounterFloat64 interface { Clear() Dec(float64) Inc(float64) Snapshot() CounterFloat64Snapshot }
CounterFloat64 holds a float64 value that can be incremented and decremented.
func GetOrRegisterCounterFloat64 ¶
func GetOrRegisterCounterFloat64(name string, r Registry) CounterFloat64
GetOrRegisterCounterFloat64 returns an existing CounterFloat64 or constructs and registers a new StandardCounterFloat64.
func GetOrRegisterCounterFloat64Forced ¶
func GetOrRegisterCounterFloat64Forced(name string, r Registry) CounterFloat64
GetOrRegisterCounterFloat64Forced returns an existing CounterFloat64 or constructs and registers a new CounterFloat64 no matter the global switch is enabled or not. Be sure to unregister the counter from the registry once it is of no use to allow for garbage collection.
func NewCounterFloat64 ¶
func NewCounterFloat64() CounterFloat64
NewCounterFloat64 constructs a new StandardCounterFloat64.
func NewCounterFloat64Forced ¶
func NewCounterFloat64Forced() CounterFloat64
NewCounterFloat64Forced constructs a new StandardCounterFloat64 and returns it no matter if the global switch is enabled or not.
func NewRegisteredCounterFloat64 ¶
func NewRegisteredCounterFloat64(name string, r Registry) CounterFloat64
NewRegisteredCounterFloat64 constructs and registers a new StandardCounterFloat64.
func NewRegisteredCounterFloat64Forced ¶
func NewRegisteredCounterFloat64Forced(name string, r Registry) CounterFloat64
NewRegisteredCounterFloat64Forced constructs and registers a new StandardCounterFloat64 and launches a goroutine no matter the global switch is enabled or not. Be sure to unregister the counter from the registry once it is of no use to allow for garbage collection.
type CounterFloat64Snapshot ¶
type CounterFloat64Snapshot interface {
Count() float64
}
type CounterSnapshot ¶
type CounterSnapshot interface {
Count() int64
}
type DiskStats ¶
type DiskStats struct { ReadCount int64 // Number of read operations executed ReadBytes int64 // Total number of bytes read WriteCount int64 // Number of write operations executed WriteBytes int64 // Total number of byte written }
DiskStats is the per process disk io stats.
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 { Snapshot() EWMASnapshot Tick() Update(int64) }
EWMAs continuously calculate an exponentially-weighted moving average based on an outside source of clock ticks.
func NewEWMA1 ¶
func NewEWMA1() EWMA
NewEWMA1 constructs a new EWMA for a one-minute moving average.
type EWMASnapshot ¶
type EWMASnapshot interface {
Rate() float64
}
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) SetRand ¶
func (s *ExpDecaySample) SetRand(prng *rand.Rand) Sample
SetRand sets the random source (useful in tests)
func (*ExpDecaySample) Snapshot ¶
func (s *ExpDecaySample) Snapshot() SampleSnapshot
Snapshot returns a read-only copy of the sample.
func (*ExpDecaySample) Update ¶
func (s *ExpDecaySample) Update(v int64)
Update samples a new value.
type Gauge ¶
type Gauge interface { Snapshot() GaugeSnapshot Update(int64) UpdateIfGt(int64) Dec(int64) Inc(int64) }
Gauge holds an int64 value that can be set arbitrarily.
func GetOrRegisterGauge ¶
GetOrRegisterGauge returns an existing Gauge or constructs and registers a new StandardGauge.
func NewRegisteredGauge ¶
NewRegisteredGauge constructs and registers a new StandardGauge.
type GaugeFloat64 ¶
type GaugeFloat64 interface { Snapshot() GaugeFloat64Snapshot Update(float64) }
GaugeFloat64 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 NewGaugeFloat64 ¶
func NewGaugeFloat64() GaugeFloat64
NewGaugeFloat64 constructs a new StandardGaugeFloat64.
func NewRegisteredGaugeFloat64 ¶
func NewRegisteredGaugeFloat64(name string, r Registry) GaugeFloat64
NewRegisteredGaugeFloat64 constructs and registers a new StandardGaugeFloat64.
type GaugeFloat64Snapshot ¶
type GaugeFloat64Snapshot interface {
Value() float64
}
type GaugeInfo ¶
type GaugeInfo interface { Update(GaugeInfoValue) Snapshot() GaugeInfoSnapshot }
GaugeInfo holds a GaugeInfoValue value that can be set arbitrarily.
func GetOrRegisterGaugeInfo ¶
GetOrRegisterGaugeInfo returns an existing GaugeInfo or constructs and registers a new StandardGaugeInfo.
func NewRegisteredGaugeInfo ¶
NewRegisteredGaugeInfo constructs and registers a new StandardGaugeInfo.
type GaugeInfoSnapshot ¶
type GaugeInfoSnapshot interface {
Value() GaugeInfoValue
}
type GaugeInfoValue ¶
GaugeInfoValue is a mapping of keys to values
func (GaugeInfoValue) String ¶
func (val GaugeInfoValue) String() string
type GaugeSnapshot ¶
type GaugeSnapshot interface {
Value() int64
}
GaugeSnapshot contains a readonly int64.
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 ¶
Healthcheck holds 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() Update(int64) Snapshot() HistogramSnapshot }
Histogram calculates distribution statistics from a series of int64 values.
func GetOrRegisterHistogram ¶
GetOrRegisterHistogram returns an existing Histogram or constructs and registers a new StandardHistogram.
func GetOrRegisterHistogramLazy ¶
GetOrRegisterHistogramLazy returns an existing Histogram or constructs and registers a new StandardHistogram.
func NewHistogram ¶
NewHistogram constructs a new StandardHistogram from a Sample.
type HistogramSnapshot ¶
type HistogramSnapshot interface { SampleSnapshot }
type Meter ¶
type Meter interface { Mark(int64) Snapshot() MeterSnapshot Stop() }
Meters count events to produce exponentially-weighted moving average rates at one-, five-, and fifteen-minutes and a mean rate.
func GetOrRegisterMeter ¶
GetOrRegisterMeter returns an existing Meter or constructs and registers a new StandardMeter. Be sure to unregister the meter from the registry once it is of no use to allow for garbage collection.
func NewInactiveMeter ¶
func NewInactiveMeter() Meter
NewInactiveMeter returns a meter but does not start any goroutines. This method is mainly intended for testing.
func NewMeter ¶
func NewMeter() Meter
NewMeter constructs a new StandardMeter and launches a goroutine. Be sure to call Stop() once the meter is of no use to allow for garbage collection.
func NewRegisteredMeter ¶
NewRegisteredMeter constructs and registers a new StandardMeter and launches a goroutine. Be sure to unregister the meter from the registry once it is of no use to allow for garbage collection.
type MeterSnapshot ¶
type NilCounter ¶
type NilCounter struct{}
NilCounter is a no-op Counter.
func (NilCounter) Clear ¶
func (NilCounter) Clear()
func (NilCounter) Dec ¶
func (NilCounter) Dec(i int64)
func (NilCounter) Inc ¶
func (NilCounter) Inc(i int64)
func (NilCounter) Snapshot ¶
func (NilCounter) Snapshot() CounterSnapshot
type NilCounterFloat64 ¶
type NilCounterFloat64 struct{}
func (NilCounterFloat64) Clear ¶
func (NilCounterFloat64) Clear()
func (NilCounterFloat64) Count ¶
func (NilCounterFloat64) Count() float64
func (NilCounterFloat64) Dec ¶
func (NilCounterFloat64) Dec(i float64)
func (NilCounterFloat64) Inc ¶
func (NilCounterFloat64) Inc(i float64)
func (NilCounterFloat64) Snapshot ¶
func (NilCounterFloat64) Snapshot() CounterFloat64Snapshot
type NilEWMA ¶
type NilEWMA struct{}
NilEWMA is a no-op EWMA.
func (NilEWMA) Snapshot ¶
func (NilEWMA) Snapshot() EWMASnapshot
type NilGauge ¶
type NilGauge struct{}
NilGauge is a no-op Gauge.
func (NilGauge) Snapshot ¶
func (NilGauge) Snapshot() GaugeSnapshot
func (NilGauge) UpdateIfGt ¶
type NilGaugeFloat64 ¶
type NilGaugeFloat64 struct{}
NilGaugeFloat64 is a no-op Gauge.
func (NilGaugeFloat64) Snapshot ¶
func (NilGaugeFloat64) Snapshot() GaugeFloat64Snapshot
func (NilGaugeFloat64) Update ¶
func (NilGaugeFloat64) Update(v float64)
func (NilGaugeFloat64) Value ¶
func (NilGaugeFloat64) Value() float64
type NilGaugeInfo ¶
type NilGaugeInfo struct{}
func (NilGaugeInfo) Snapshot ¶
func (NilGaugeInfo) Snapshot() GaugeInfoSnapshot
func (NilGaugeInfo) Update ¶
func (NilGaugeInfo) Update(v GaugeInfoValue)
func (NilGaugeInfo) Value ¶
func (NilGaugeInfo) Value() GaugeInfoValue
type NilHistogram ¶
type NilHistogram struct{}
NilHistogram is a no-op Histogram.
func (NilHistogram) Clear ¶
func (NilHistogram) Clear()
func (NilHistogram) Snapshot ¶
func (NilHistogram) Snapshot() HistogramSnapshot
func (NilHistogram) Update ¶
func (NilHistogram) Update(v int64)
type NilMeter ¶
type NilMeter struct{}
NilMeter is a no-op Meter.
func (NilMeter) Snapshot ¶
func (NilMeter) Snapshot() MeterSnapshot
type NilResettingTimer ¶
type NilResettingTimer struct{}
NilResettingTimer is a no-op ResettingTimer.
func (NilResettingTimer) Count ¶
func (NilResettingTimer) Count() int
func (NilResettingTimer) Max ¶
func (NilResettingTimer) Max() int64
func (NilResettingTimer) Mean ¶
func (NilResettingTimer) Mean() float64
func (NilResettingTimer) Min ¶
func (NilResettingTimer) Min() int64
func (NilResettingTimer) Percentiles ¶
func (NilResettingTimer) Percentiles([]float64) []float64
func (NilResettingTimer) Snapshot ¶
func (n NilResettingTimer) Snapshot() ResettingTimerSnapshot
func (NilResettingTimer) Time ¶
func (NilResettingTimer) Time(f func())
func (NilResettingTimer) Update ¶
func (NilResettingTimer) Update(time.Duration)
func (NilResettingTimer) UpdateSince ¶
func (NilResettingTimer) UpdateSince(time.Time)
func (NilResettingTimer) Values ¶
func (NilResettingTimer) Values() []int64
type NilSample ¶
type NilSample struct{}
NilSample is a no-op Sample.
func (NilSample) Snapshot ¶
func (NilSample) Snapshot() SampleSnapshot
type NilTimer ¶
type NilTimer struct{}
NilTimer is a no-op Timer.
func (NilTimer) Snapshot ¶
func (NilTimer) Snapshot() TimerSnapshot
func (NilTimer) UpdateSince ¶
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 PrefixedRegistry ¶
type PrefixedRegistry struct {
// contains filtered or unexported fields
}
func (*PrefixedRegistry) Each ¶
func (r *PrefixedRegistry) Each(fn func(string, interface{}))
Each 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) GetAll ¶
func (r *PrefixedRegistry) GetAll() map[string]map[string]interface{}
GetAll metrics in the Registry
func (*PrefixedRegistry) GetOrRegister ¶
func (r *PrefixedRegistry) GetOrRegister(name string, metric interface{}) interface{}
GetOrRegister 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 (r *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()
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.
type Registry ¶
type Registry interface { // Each 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{} // GetAll metrics in the Registry. GetAll() map[string]map[string]interface{} // GetOrRegister 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{} // Register the given metric under the given name. Register(string, interface{}) error // RunHealthchecks run all registered healthchecks. RunHealthchecks() // Unregister the metric with the given name. Unregister(string) }
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 to encourage other structs to implement the Registry API as appropriate.
func NewOrderedRegistry ¶
func NewOrderedRegistry() Registry
NewOrderedRegistry creates a new ordered registry (for testing).
func NewPrefixedRegistry ¶
type ResettingTimer ¶
type ResettingTimer interface { Snapshot() ResettingTimerSnapshot Time(func()) Update(time.Duration) UpdateSince(time.Time) }
ResettingTimer is used for storing aggregated values for timers, which are reset on every flush interval.
func GetOrRegisterResettingTimer ¶
func GetOrRegisterResettingTimer(name string, r Registry) ResettingTimer
GetOrRegisterResettingTimer returns an existing ResettingTimer or constructs and registers a new StandardResettingTimer.
func NewRegisteredResettingTimer ¶
func NewRegisteredResettingTimer(name string, r Registry) ResettingTimer
NewRegisteredResettingTimer constructs and registers a new StandardResettingTimer.
func NewResettingTimer ¶
func NewResettingTimer() ResettingTimer
NewResettingTimer constructs a new StandardResettingTimer
type ResettingTimerSnapshot ¶
type Sample ¶
type Sample interface { Snapshot() SampleSnapshot Clear() Update(int64) }
Samples maintain a statistically-significant selection of values from a stream.
func NewExpDecaySample ¶
NewExpDecaySample constructs a new exponentially-decaying sample with the given reservoir size and alpha.
func NewUniformSample ¶
NewUniformSample constructs a new uniform sample with the given reservoir size.
func ResettingSample ¶
ResettingSample converts an ordinary sample into one that resets whenever its snapshot is retrieved. This will break for multi-monitor systems, but when only a single metric is being pushed out, this ensure that low-frequency events don't skew th charts indefinitely.
type SampleSnapshot ¶
type StandardCounter ¶
StandardCounter is the standard implementation of a Counter and uses the sync/atomic package to manage a single int64 value.
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() CounterSnapshot
Snapshot returns a read-only copy of the counter.
type StandardCounterFloat64 ¶
type StandardCounterFloat64 struct {
// contains filtered or unexported fields
}
StandardCounterFloat64 is the standard implementation of a CounterFloat64 and uses the atomic to manage a single float64 value.
func (*StandardCounterFloat64) Clear ¶
func (c *StandardCounterFloat64) Clear()
Clear sets the counter to zero.
func (*StandardCounterFloat64) Dec ¶
func (c *StandardCounterFloat64) Dec(v float64)
Dec decrements the counter by the given amount.
func (*StandardCounterFloat64) Inc ¶
func (c *StandardCounterFloat64) Inc(v float64)
Inc increments the counter by the given amount.
func (*StandardCounterFloat64) Snapshot ¶
func (c *StandardCounterFloat64) Snapshot() CounterFloat64Snapshot
Snapshot returns a read-only copy of the counter.
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) Snapshot ¶
func (a *StandardEWMA) Snapshot() EWMASnapshot
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) Dec ¶
func (g *StandardGauge) Dec(i int64)
Dec decrements the gauge's current value by the given amount.
func (*StandardGauge) Inc ¶
func (g *StandardGauge) Inc(i int64)
Inc increments the gauge's current value by the given amount.
func (*StandardGauge) Snapshot ¶
func (g *StandardGauge) Snapshot() GaugeSnapshot
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) UpdateIfGt ¶
func (g *StandardGauge) UpdateIfGt(v int64)
UpdateIfGt updates the gauge's value if v is larger then the current value.
type StandardGaugeFloat64 ¶
type StandardGaugeFloat64 struct {
// contains filtered or unexported fields
}
StandardGaugeFloat64 is the standard implementation of a GaugeFloat64 and uses atomic to manage a single float64 value.
func (*StandardGaugeFloat64) Snapshot ¶
func (g *StandardGaugeFloat64) Snapshot() GaugeFloat64Snapshot
Snapshot returns a read-only copy of the gauge.
func (*StandardGaugeFloat64) Update ¶
func (g *StandardGaugeFloat64) Update(v float64)
Update updates the gauge's value.
type StandardGaugeInfo ¶
type StandardGaugeInfo struct {
// contains filtered or unexported fields
}
StandardGaugeInfo is the standard implementation of a GaugeInfo and uses sync.Mutex to manage a single string value.
func (*StandardGaugeInfo) Snapshot ¶
func (g *StandardGaugeInfo) Snapshot() GaugeInfoSnapshot
Snapshot returns a read-only copy of the gauge.
func (*StandardGaugeInfo) Update ¶
func (g *StandardGaugeInfo) Update(v GaugeInfoValue)
Update updates the gauge's 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) Snapshot ¶
func (h *StandardHistogram) Snapshot() HistogramSnapshot
Snapshot returns a read-only copy of the histogram.
func (*StandardHistogram) Update ¶
func (h *StandardHistogram) Update(v int64)
Update samples a new value.
type StandardMeter ¶
type StandardMeter struct {
// contains filtered or unexported fields
}
StandardMeter is the standard implementation of a Meter.
func (*StandardMeter) Mark ¶
func (m *StandardMeter) Mark(n int64)
Mark records the occurrence of n events.
func (*StandardMeter) Snapshot ¶
func (m *StandardMeter) Snapshot() MeterSnapshot
Snapshot returns a read-only copy of the meter.
func (*StandardMeter) Stop ¶
func (m *StandardMeter) Stop()
Stop stops the meter, Mark() will be a no-op if you use it after being stopped.
type StandardRegistry ¶
type StandardRegistry struct {
// contains filtered or unexported fields
}
StandardRegistry the standard implementation of a Registry uses sync.map of names to metrics.
func (*StandardRegistry) Each ¶
func (r *StandardRegistry) Each(f func(string, interface{}))
Each 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) 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{}
GetOrRegister 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()
RunHealthchecks run all registered healthchecks.
func (*StandardRegistry) Unregister ¶
func (r *StandardRegistry) Unregister(name string)
Unregister the metric with the given name.
type StandardResettingTimer ¶
type StandardResettingTimer struct {
// contains filtered or unexported fields
}
StandardResettingTimer is the standard implementation of a ResettingTimer. and Meter.
func (*StandardResettingTimer) Snapshot ¶
func (t *StandardResettingTimer) Snapshot() ResettingTimerSnapshot
Snapshot resets the timer and returns a read-only copy of its contents.
func (*StandardResettingTimer) Time ¶
func (t *StandardResettingTimer) Time(f func())
Record the duration of the execution of the given function.
func (*StandardResettingTimer) Update ¶
func (t *StandardResettingTimer) Update(d time.Duration)
Record the duration of an event.
func (*StandardResettingTimer) UpdateSince ¶
func (t *StandardResettingTimer) UpdateSince(ts time.Time)
Record the duration of an event that started at a time and ends now.
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) Snapshot ¶
func (t *StandardTimer) Snapshot() TimerSnapshot
Snapshot returns a read-only copy of the timer.
func (*StandardTimer) Time ¶
func (t *StandardTimer) Time(f func())
Time record the duration of the execution of the given function.
func (*StandardTimer) Update ¶
func (t *StandardTimer) Update(d time.Duration)
Update the duration of an event, in nanoseconds.
func (*StandardTimer) UpdateSince ¶
func (t *StandardTimer) UpdateSince(ts time.Time)
UpdateSince update the duration of an event that started at a time and ends now. The record uses nanoseconds.
type Stoppable ¶
type Stoppable interface {
Stop()
}
Stoppable defines the metrics which has to be stopped.
type Timer ¶
type Timer interface { Snapshot() TimerSnapshot Stop() Time(func()) UpdateSince(time.Time) Update(time.Duration) }
Timer capture the duration and rate of events.
func GetOrRegisterTimer ¶
GetOrRegisterTimer returns an existing Timer or constructs and registers a new StandardTimer. Be sure to unregister the meter from the registry once it is of no use to allow for garbage collection.
Example ¶
m := "account.create.latency" t := GetOrRegisterTimer(m, nil) t.Update(47) fmt.Println(t.Snapshot().Max())
Output: 47
func NewCustomTimer ¶
NewCustomTimer constructs a new StandardTimer from a Histogram and a Meter. Be sure to call Stop() once the timer is of no use to allow for garbage collection.
func NewRegisteredTimer ¶
NewRegisteredTimer constructs and registers a new StandardTimer. Be sure to unregister the meter from the registry once it is of no use to allow for garbage collection.
type TimerSnapshot ¶
type TimerSnapshot interface { HistogramSnapshot MeterSnapshot }
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) SetRand ¶
func (s *UniformSample) SetRand(prng *rand.Rand) Sample
SetRand sets the random source (useful in tests)
func (*UniformSample) Snapshot ¶
func (s *UniformSample) Snapshot() SampleSnapshot
Snapshot returns a read-only copy of the sample.
Source Files ¶
- config.go
- counter.go
- counter_float64.go
- cpu.go
- cpu_enabled.go
- cputime_unix.go
- debug.go
- disk.go
- disk_linux.go
- ewma.go
- gauge.go
- gauge_float64.go
- gauge_info.go
- graphite.go
- healthcheck.go
- histogram.go
- inactive.go
- json.go
- log.go
- meter.go
- metrics.go
- opentsdb.go
- registry.go
- resetting_sample.go
- resetting_timer.go
- runtimehistogram.go
- sample.go
- syslog.go
- timer.go
- writer.go
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 |
Package prometheus exposes go-metrics into a Prometheus format.
|
Package prometheus exposes go-metrics into a Prometheus format. |