From 88863c11072b8f3f4670e3e15a23837fc92782e3 Mon Sep 17 00:00:00 2001 From: Martin Lindhe Date: Tue, 27 Sep 2016 14:37:12 +0200 Subject: [PATCH] exporter: add /health endpoint. fixes #25 --- exporter.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/exporter.go b/exporter.go index c403f319..88c9be79 100644 --- a/exporter.go +++ b/exporter.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "io" "net/http" "os" "sort" @@ -158,6 +159,7 @@ func main() { prometheus.MustRegister(nodeCollector) http.Handle(*metricsPath, prometheus.Handler()) + http.HandleFunc("/health", healthCheck) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, *metricsPath, http.StatusMovedPermanently) }) @@ -180,9 +182,14 @@ func main() { } } +func healthCheck(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + io.WriteString(w, `{"status":"ok"}`) +} + func keys(m map[string]collector.Collector) []string { ret := make([]string, 0, len(m)) - for key, _ := range m { + for key := range m { ret = append(ret, key) } return ret