Files
multica/server/internal/metrics/server.go
devv-eve f864a07bd5 feat: add server Prometheus metrics endpoint
Add Prometheus metrics endpoint with local-bind listener support and baseline metrics collectors.
2026-04-28 14:29:01 +08:00

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,
}
}