mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-06 14:00:09 +02:00
Add Prometheus metrics endpoint with local-bind listener support and baseline metrics collectors.
30 lines
743 B
Go
30 lines
743 B
Go
package metrics
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
)
|
|
|
|
func NewHandler(gatherer prometheus.Gatherer) http.Handler {
|
|
mux := http.NewServeMux()
|
|
mux.Handle("/metrics", promhttp.HandlerFor(gatherer, promhttp.HandlerOpts{
|
|
EnableOpenMetrics: true,
|
|
ErrorHandling: promhttp.HTTPErrorOnError,
|
|
}))
|
|
return mux
|
|
}
|
|
|
|
func NewServer(addr string, gatherer prometheus.Gatherer) *http.Server {
|
|
return &http.Server{
|
|
Addr: addr,
|
|
Handler: NewHandler(gatherer),
|
|
ReadHeaderTimeout: 5 * time.Second,
|
|
ReadTimeout: 10 * time.Second,
|
|
WriteTimeout: 10 * time.Second,
|
|
IdleTimeout: 30 * time.Second,
|
|
}
|
|
}
|