Official Go implementation of the Ethereum protocol
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
go-ethereum/metrics
Martin HS 7a625d3a08 build: update to golangci-lint 1.61.0 (#30587) 4 days ago
..
exp metrics: refactor metrics (#28035) 1 year ago
influxdb metrics/influxdb: skip float64-precision-dependent tests on arm64 (#29047) 8 months ago
internal metrics: refactor metrics (#28035) 1 year ago
prometheus cmd, core, metrics: always report expensive metrics (#29191) 9 months ago
testdata metrics: refactor metrics (#28035) 1 year ago
FORK.md metrics: pull library and introduce ResettingTimer and InfluxDB reporter (#15910) 7 years ago
LICENSE metrics: pull library and introduce ResettingTimer and InfluxDB reporter (#15910) 7 years ago
README.md metrics: remove librato (#29624) 7 months ago
config.go cmd, core, metrics: always report expensive metrics (#29191) 9 months ago
counter.go all: fix docstring names (#28923) 10 months ago
counter_float64.go metrics: refactor metrics (#28035) 1 year ago
counter_float_64_test.go metrics: refactor metrics (#28035) 1 year ago
counter_test.go metrics: refactor metrics (#28035) 1 year ago
cpu.go metrics: improve accuracy of CPU gauges (#26793) 2 years ago
cpu_disabled.go all: add go:build lines (#23468) 3 years ago
cpu_enabled.go metrics: improve accuracy of CPU gauges (#26793) 2 years ago
cputime_nop.go metrics: improve accuracy of CPU gauges (#26793) 2 years ago
cputime_unix.go metrics: improve accuracy of CPU gauges (#26793) 2 years ago
debug.go metrics: fix function comment (#29843) 6 months ago
debug_test.go metrics: pull library and introduce ResettingTimer and InfluxDB reporter (#15910) 7 years ago
disk.go all: fix license headers one more time 9 years ago
disk_linux.go all: fix ineffectual assignments and remove uses of crypto.Sha3 8 years ago
disk_nop.go accounts,cmd,console,les,metrics: refactor some errors checked by (ST1005) go-staticcheck (#28532) 1 year ago
ewma.go metrics: refactor metrics (#28035) 1 year ago
ewma_test.go metrics: refactor metrics (#28035) 1 year ago
gauge.go all: fix mismatched names in comments (#29348) 8 months ago
gauge_float64.go all: fix docstring names (#28923) 10 months ago
gauge_float64_test.go accounts,cmd,console,les,metrics: refactor some errors checked by (ST1005) go-staticcheck (#28532) 1 year ago
gauge_info.go all: fix docstring names (#28923) 10 months ago
gauge_info_test.go metrics: refactor metrics (#28035) 1 year ago
gauge_test.go metrics: refactor metrics (#28035) 1 year ago
graphite.go metrics: refactor metrics (#28035) 1 year ago
graphite_test.go metrics: pull library and introduce ResettingTimer and InfluxDB reporter (#15910) 7 years ago
healthcheck.go all: fix docstring names (#28923) 10 months ago
histogram.go all: fix docstring names (#28923) 10 months ago
histogram_test.go metrics: refactor metrics (#28035) 1 year ago
inactive.go metrics: refactor metrics (#28035) 1 year ago
init_test.go metrics: pull library and introduce ResettingTimer and InfluxDB reporter (#15910) 7 years ago
json.go metrics: fix docstrings (#29279) 8 months ago
json_test.go build: update to golangci-lint 1.61.0 (#30587) 4 days ago
log.go metrics: refactor metrics (#28035) 1 year ago
memory.md metrics: pull library and introduce ResettingTimer and InfluxDB reporter (#15910) 7 years ago
meter.go all: fix mismatched names in comments (#29348) 8 months ago
meter_test.go metrics: refactor metrics (#28035) 1 year ago
metrics.go all: fix mismatched names in comments (#29348) 8 months ago
metrics_test.go metrics: refactor metrics (#28035) 1 year ago
opentsdb.go metrics: refactor metrics (#28035) 1 year ago
opentsdb_test.go metrics: refactor metrics (#28035) 1 year ago
registry.go metrics: fix docstrings (#29279) 8 months ago
registry_test.go metrics: refactor metrics (#28035) 1 year ago
resetting_sample.go metrics: refactor metrics (#28035) 1 year ago
resetting_timer.go metrics: refactor metrics (#28035) 1 year ago
resetting_timer_test.go metrics: refactor metrics (#28035) 1 year ago
runtimehistogram.go metrics: refactor metrics (#28035) 1 year ago
runtimehistogram_test.go metrics: refactor metrics (#28035) 1 year ago
sample.go all: fix various typos (#29542) 7 months ago
sample_test.go metrics: add test for `SampleSnapshot.Sum` (#29831) 6 months ago
syslog.go metrics: refactor metrics (#28035) 1 year ago
timer.go metrics: fix docstrings (#29279) 8 months ago
timer_test.go metrics: refactor metrics (#28035) 1 year ago
validate.sh metrics: pull library and introduce ResettingTimer and InfluxDB reporter (#15910) 7 years ago
writer.go all: remove dependency on golang.org/exp (#29314) 8 months ago
writer_test.go all: remove dependency on golang.org/exp (#29314) 8 months ago

README.md

go-metrics

travis build status

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

Documentation: https://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)

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

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

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

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

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

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

Periodically emit every metric to Graphite using the Graphite client:


import "github.com/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/vrischmann/go-metrics-influxdb"

go influxdb.InfluxDB(metrics.DefaultRegistry,
  10e9, 
  "127.0.0.1:8086", 
  "database-name", 
  "username", 
  "password"
)

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: