Added healthchecking via HTTP

Signed-off-by: Mathias Kaufmann <me@stei.gr>
This commit is contained in:
Mathias Kaufmann 2018-03-14 01:05:57 +01:00
parent c8e83bb840
commit 154aaa5243
1 changed files with 17 additions and 1 deletions

View File

@ -29,6 +29,7 @@ import (
"strings"
"time"
healthchecking "github.com/heptiolabs/healthcheck"
"github.com/namsral/flag"
proxyproto "github.com/Freeaqingme/go-proxyproto"
@ -38,6 +39,7 @@ import (
const (
PROXY_TIMEOUT = 5
HEALTCHECK_PORT = 8080
)
var (
@ -54,6 +56,7 @@ var (
proxyTimeout = flag.Uint("proxytimeout", PROXY_TIMEOUT, "Timeout when using proxy protocol")
metrics = flag.Bool("metrics", false, "Enable metrics export")
verbose = flag.Bool("v", false, "Enable verbose logging.")
healtcheck = flag.Bool("healthcheck", false, "Enable healthcheck endpoint.")
clients_tls_total = prometheus.NewCounter(
prometheus.CounterOpts{
@ -190,10 +193,23 @@ func Run() {
if *metrics {
go prom_export()
}
if *healtcheck {
go health_endpoint()
}
Processor(events, make(chan struct{}))
}
func health_endpoint() {
var (
health_bind = "0.0.0.0:8086"
)
health := healthchecking.NewHandler()
health.AddLivenessCheck("goroutine-threshold", healthchecking.GoroutineCountCheck(100))
log.Printf("Healthcheck listening on http://%s", health_bind)
http.ListenAndServe(health_bind, health)
}
func prom_export() {
prometheus.MustRegister(clients_tls_total)
prometheus.MustRegister(clients_irc_total)