Skip to content

Instantly share code, notes, and snippets.

@drichelson
Created March 11, 2016 03:32
Show Gist options
  • Save drichelson/15de70b9576b1f3a640e to your computer and use it in GitHub Desktop.
Save drichelson/15de70b9576b1f3a640e to your computer and use it in GitHub Desktop.
Demonstration of go-metrics json output
package main
import (
"encoding/json"
"fmt"
"github.com/rcrowley/go-metrics"
)
func main() {
// PrefixedRegistry
prefixedRegistry := metrics.NewPrefixedRegistry("prefix")
counter1 := metrics.NewCounter()
prefixedRegistry.Register("counter1", counter1)
counter1.Inc(1)
jsonBytes, _ := json.Marshal(prefixedRegistry)
//output: {}
fmt.Println(string(jsonBytes))
// DefaultRegistry- implemented as StandardRegistry
registry := metrics.DefaultRegistry
counter2 := metrics.NewCounter()
registry.Register("counter2", counter2)
counter2.Inc(1)
jsonBytes, _ = json.Marshal(registry)
//output: {"counter2":{"count":1}}
fmt.Println(string(jsonBytes))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment