This is a reporter for the go-metrics that will posts metrics to Prometheus.
Note: this codebase is very young and might contain bugs.
It is a very minimal module with no external dependencies other that the go-metrics module. This module does not require the standard Prometheus go client which itself is quite a large module containing lots of other code not related to exposing metrics to Prometheus.
This module is quite small so feel free to internalize it into your codebase and adjust it to your needs.
import "github.com/rcrowley/go-metrics"
import "github.com/LasseJacobs/go-metrics-prometheus"
http.Handle("/metrics", prometheus.MakePrometheusHandler(nil, nil))
fmt.Printf("Starting server at port 8080\n")
if err := http.ListenAndServe(":8080", nil); err != nil {
log.Fatal(err)
}
See example/simple-server
for a full working example. Alternatively you can run docker-compose up --build
, this will start a
test web-app that exposes some metrics, and a prometheus server that will monitor these metrics.
By supplying nil
to the MakePrometheusHandler
the default metrics registry will be used.
You can verify that it is working by going to: localhost:8080/metrics
.
Note that if you do not expose any metrics, as is the case in this example, this page will be empty.
go get -u github.com/LasseJacobs/go-metrics-prometheus
running go tidy might be required:
go mode tidy