metric

Minimal metrics for Go (counter/gauge/histogram). No dependencies. Compatible with expvar. Web UI included.

Github星跟踪图

metric

Build Status
GoDoc
Go Report Card

Package provides simple uniform interface for metrics such as counters,
gauges and histograms. It keeps track of metrics in runtime and can be used for
some basic web service instrumentation in Go, where complex tools such as
Prometheus or InfluxDB are not required.

It is compatible with expvar package, that is
also commonly used for monitoring.

Usage

// Create new metric. All metrics may take time frames if you want them to keep
// history. If no time frames are given the metric only keeps track of a single
// current value.
c := metric.NewCounter("15m10s") // 15 minutes of history with 10 second precision
// Increment counter
c.Add(1)
// Return JSON with all recorded counter values
c.String() // Or json.Marshal(c)

// With expvar

// Register a metric
expvar.Publish("latency", metric.NewHistogram("5m1s", "15m30s", "1h1m"))
// Register HTTP handler to visualize metrics
http.Handle("/debug/metrics", metric.Handler(metric.Exposed))

// Measure time and update the metric
start := time.Now()
...
expvar.Get("latency").(metric.Metric).Add(time.Since(start).Seconds())

Metrics are thread-safe and can be updated from background goroutines.

Web UI

Nothing fancy, really, but still better than reading plain JSON. No javascript,
only good old HTML, CSS and SVG.

web ui

Of course you may customize a list of metrics to show in the web UI.

If you need precise values - you may use /debug/vars HTTP endpoint provided
by expvar.

License

Code is distributed under MIT license, feel free to use it in your proprietary
projects as well.

主要指标

概览
名称与所有者zserge/metric
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2018-05-23 11:25:51
推送于2019-12-20 04:43:31
最后一次提交2019-04-29 21:25:10
发布数1
最新版本名称v0.1.0 (发布于 )
第一版名称v0.1.0 (发布于 )
用户参与
星数363
关注者数7
派生数29
提交数24
已启用问题?
问题数4
打开的问题数4
拉请求数3
打开的拉请求数0
关闭的拉请求数2
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?