From d3611a2799ab751539135b124f950ae9605133cf Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 8 Apr 2019 20:51:06 +0300 Subject: [PATCH] Mention how to expose metrics on the `/metrics` page --- README.md | 6 ++++++ metrics.go | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cea4984..277ae78 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/metrics.go b/metrics.go index 8d844f4..3deb43f 100644 --- a/metrics.go +++ b/metrics.go @@ -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()