Libraries
go get github.com/prometheus/client_golang/prometheus go get github.com/prometheus/client_golang/prometheus/promauto go get github.com/prometheus/client_golang/prometheus/promhttp
Sample Code
package main import ( "net/http" "time" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promhttp" ) func recordMetrics() { go func() { for { opsProcessed.Inc() time.Sleep(2 * time.Second) } }() } var ( opsProcessed = promauto.NewCounter(prometheus.CounterOpts{ Name: "myapp_processed_ops_total", Help: "The total number of processed events", }) ) func main() { recordMetrics() http.Handle("/metrics", promhttp.Handler()) http.ListenAndServe(":2112", nil) }
Access the Metric
curl http://localhost:2112/metrics
References
Reference | URL |
---|---|
INSTRUMENTING A GO APPLICATION FOR PROMETHEUS | https://prometheus.io/docs/guides/go-application/ |