Add health check and self reporting of health

This avoids panicing and instead provides an HTTP endpoint to report health
This commit is contained in:
Ian Fijolek
2024-04-03 11:23:26 -07:00
parent 01cca50532
commit 0a36da79d6
5 changed files with 261 additions and 28 deletions
+2 -7
View File
@@ -1,7 +1,6 @@
package main
import (
"fmt"
"net/http"
"github.com/prometheus/client_golang/prometheus"
@@ -107,11 +106,7 @@ func (metrics *MinitorMetrics) CountAlert(monitor string, alert string) {
).Inc()
}
// ServeMetrics starts an http server with a Prometheus metrics handler
func ServeMetrics() {
// HandleMetrics add Prometheus metrics handler to default http server
func HandleMetrics() {
http.Handle("/metrics", promhttp.Handler())
host := fmt.Sprintf(":%d", MetricsPort)
_ = http.ListenAndServe(host, nil)
}