From 154aaa524397e024373d4f3ec2b0972532d0e9b6 Mon Sep 17 00:00:00 2001 From: Mathias Kaufmann Date: Wed, 14 Mar 2018 01:05:57 +0100 Subject: [PATCH] Added healthchecking via HTTP Signed-off-by: Mathias Kaufmann --- goircd.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/goircd.go b/goircd.go index 128dcf3..e30db55 100644 --- a/goircd.go +++ b/goircd.go @@ -29,6 +29,7 @@ import ( "strings" "time" + healthchecking "github.com/heptiolabs/healthcheck" "github.com/namsral/flag" proxyproto "github.com/Freeaqingme/go-proxyproto" @@ -37,7 +38,8 @@ import ( ) const ( - PROXY_TIMEOUT = 5 + 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)