27 lines
718 B
Go
27 lines
718 B
Go
package metrics
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/collectors"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
// Metrics establish metrics for an application.
|
|
func Metrics() {
|
|
// Register standart metrics.
|
|
appRegistry := prometheus.NewRegistry()
|
|
appRegistry.MustRegister(collectors.NewGoCollector())
|
|
appRegistry.MustRegister(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}))
|
|
|
|
//// Endpoint for metrics.
|
|
http.Handle("/metrics", promhttp.HandlerFor(appRegistry, promhttp.HandlerOpts{}))
|
|
|
|
// Start server.
|
|
err := http.ListenAndServe(":9111", nil)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
}
|