Mention how to expose metrics on the /metrics page

This commit is contained in:
Aliaksandr Valialkin 2019-04-08 20:51:06 +03:00
parent ab79b3496c
commit d3611a2799
2 changed files with 15 additions and 2 deletions

View File

@ -38,6 +38,12 @@ func requestHandler() {
requestsTotal.Inc()
requestDuration.UpdateDuration(startTime)
}
// ...
// Register `/metrics` handler for exposing the registered metrics.
http.HandleFunc("/metrics", func(w http.ResponseWriter, req *http.Request) {
metrics.WritePrometheus(w, true)
})
```
See [docs](http://godoc.org/github.com/VictoriaMetrics/metrics) for more info.

View File

@ -1,7 +1,7 @@
// Package metrics implements Prometheus-compatible metrics for applications.
//
// This package is similar to https://github.com/prometheus/client_golang ,
// but is simpler to use and is more lightweight.
// This package is lightweight alternative to https://github.com/prometheus/client_golang
// with simpler API and small dependencies.
package metrics
import (
@ -154,6 +154,13 @@ type metric interface {
//
// If exposeProcessMetrics is true, then various `go_*` metrics are exposed
// for the current process.
//
// The WritePrometheus func is usually called inside "/metrics" handler:
//
// http.HandleFunc("/metrics", func(w http.ResponseWriter, req *http.Request) {
// metrics.WritePrometheus(w, true)
// })
//
func WritePrometheus(w io.Writer, exposeProcessMetrics bool) {
// Export user-defined metrics.
metricsMapLock.Lock()