Exporting metrics
As already shown, exporting metrics from your own application is easy, at least in principle. All your application needs to do is offer an HTTP endpoint that returns arbitrary metrics that can then be saved in Prometheus. In practice, this gets more difficult, especially when you care about the status of the Go runtime (for example, CPU and memory usage, Goroutine count, and so on). For this reason, it is usually a good idea to use the Prometheus client library for Go, which takes care of collecting all possible Go runtime metrics.
As a matter of fact, Prometheus is itself written in Go and also uses its own client library to export metrics about the Go runtime (for example, the go_memstats_alloc_bytes
or process_cpu_seconds_total
metrics that you have worked with before).
Using the Prometheus client in your Go application
You can get the Prometheus client library using go get
, as follows:
$ go get -u github.com/prometheus/client_golang
In case your application uses a dependency...