Mention how to expose metrics on the /metrics
page
This commit is contained in:
parent
ab79b3496c
commit
d3611a2799
@ -38,6 +38,12 @@ func requestHandler() {
|
|||||||
requestsTotal.Inc()
|
requestsTotal.Inc()
|
||||||
requestDuration.UpdateDuration(startTime)
|
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.
|
See [docs](http://godoc.org/github.com/VictoriaMetrics/metrics) for more info.
|
||||||
|
11
metrics.go
11
metrics.go
@ -1,7 +1,7 @@
|
|||||||
// Package metrics implements Prometheus-compatible metrics for applications.
|
// Package metrics implements Prometheus-compatible metrics for applications.
|
||||||
//
|
//
|
||||||
// This package is similar to https://github.com/prometheus/client_golang ,
|
// This package is lightweight alternative to https://github.com/prometheus/client_golang
|
||||||
// but is simpler to use and is more lightweight.
|
// with simpler API and small dependencies.
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -154,6 +154,13 @@ type metric interface {
|
|||||||
//
|
//
|
||||||
// If exposeProcessMetrics is true, then various `go_*` metrics are exposed
|
// If exposeProcessMetrics is true, then various `go_*` metrics are exposed
|
||||||
// for the current process.
|
// 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) {
|
func WritePrometheus(w io.Writer, exposeProcessMetrics bool) {
|
||||||
// Export user-defined metrics.
|
// Export user-defined metrics.
|
||||||
metricsMapLock.Lock()
|
metricsMapLock.Lock()
|
||||||
|
Loading…
Reference in New Issue
Block a user