Metrics library and aggregation daemon for Go
Pull request Compare This branch is 12 commits ahead, 99 commits behind samuel:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

go-metrics is a library for aggregating data into metrics (counts, gauges, histograms) as well as a daemon server to collect data and forward to visualization services.

It can be used to embed in an application for tracking internal app metrics, and then reporting out.

Or the daemon server can collect data over UDP requests, and send metrics to Librato or Stathat .

See the Metricsd folder for how to send to Stathat/librato.

Example of usage embedding the metrics in your application :

import ""
import "time"

func init() {
    go metrics.RunMetricsHeartbeat(10 ,60 * time.Second)

func hello(w http.ResponseWriter, r *http.Request) {
    // update a counter
    metrics.UpdateCounterf("my_requests_size", len(r.Body))
    io.WriteString(w, "hello")

A more elaborate example, registering recievers to get a callback, and custom metrics functions:

import ""
import "time"

var myVarName float64 = 2000
var curUsers int

func init() {
    metrics.AddSnapshotReceiver(func(snap metrics.Snapshot){


    go metrics.RunMetricsHeartbeat(0, time.Second * 60)

func metricsData(snap *metrics.Snapshot) {
    snap.Ints["my_custom_value"] = uint64(myVarName) 
    snap.Ints["requests_peruser"] = snap.Ints["my_requests"] / uint64(curUsers)  

func foo(r http.Request) {
    myVarName += len(r.Body)

// how to use the snapshot data
func checkCapacity(snap) {
    if rate, ok := snap.Ints["my_requests"]; ok {
        if rate > 10000 {