mirror of
https://github.com/stakater/Reloader.git
synced 2026-08-21 21:16:27 +00:00
Previously, 9091 and 9090 both led to the same web server, meaning both /metrics and /live were reachable and fully functional through both. This commit changes that so that only port 9090 is used for both. Closes #381.
39 lines
849 B
Go
39 lines
849 B
Go
package metrics
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
"net/http"
|
|
)
|
|
|
|
type Collectors struct {
|
|
Reloaded *prometheus.CounterVec
|
|
}
|
|
|
|
func NewCollectors() Collectors {
|
|
reloaded := prometheus.NewCounterVec(
|
|
prometheus.CounterOpts{
|
|
Namespace: "reloader",
|
|
Name: "reload_executed_total",
|
|
Help: "Counter of reloads executed by Reloader.",
|
|
},
|
|
[]string{"success"},
|
|
)
|
|
|
|
//set 0 as default value
|
|
reloaded.With(prometheus.Labels{"success": "true"}).Add(0)
|
|
reloaded.With(prometheus.Labels{"success": "false"}).Add(0)
|
|
|
|
return Collectors{
|
|
Reloaded: reloaded,
|
|
}
|
|
}
|
|
|
|
func SetupPrometheusEndpoint() Collectors {
|
|
collectors := NewCollectors()
|
|
prometheus.MustRegister(collectors.Reloaded)
|
|
http.Handle("/metrics", promhttp.Handler())
|
|
|
|
return collectors
|
|
}
|