mirror of
https://github.com/OliveTin/OliveTin
synced 2026-05-04 13:10:38 +00:00
32 lines
749 B
Go
32 lines
749 B
Go
package httpservers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
config "github.com/OliveTin/OliveTin/internal/config"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/collectors"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func StartPrometheus(cfg *config.Config) {
|
|
if !cfg.Prometheus.Enabled {
|
|
return
|
|
}
|
|
|
|
if !cfg.Prometheus.DefaultGoMetrics {
|
|
prometheus.Unregister(collectors.NewGoCollector())
|
|
}
|
|
|
|
http.Handle("/", promhttp.Handler())
|
|
err := http.ListenAndServe(cfg.ListenAddressPrometheus, nil)
|
|
|
|
if err != nil {
|
|
log.WithFields(log.Fields{
|
|
"address": cfg.ListenAddressPrometheus,
|
|
"error": err,
|
|
}).Warnf("Failed to start Prometheus server")
|
|
}
|
|
}
|