Collecting metrics
In addition to general information about your app, it can be helpful to emit metrics that are app specific. For example, we might want to collect timing data or keep track of the number of times an event occurs.
This recipe will use the github.com/rcrowley/go-metrics
package to collect metrics and expose them via an endpoint. There are various exporter tools to export metrics to places such as Prometheus and InfluxDB, also written in Go.
Getting ready
Configure your environment according to these steps:
- Refer to the Getting ready section of the Using service discovery with Consul recipe in this chapter.
- Run the
go get github.com/rcrowley/go-metrics
command.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create the
chapter10/metrics
directory and navigate to it. - Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter10/metrics, or use this as an exercise to write some of your own code.
- Create a file...