Merge pull request #30 from martinlindhe/health

exporter: add /health endpoint. fixes #25
This commit is contained in:
Martin Lindhe
2016-09-27 14:51:24 +02:00
committed by GitHub

View File

@@ -3,6 +3,7 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"io"
"net/http" "net/http"
"os" "os"
"sort" "sort"
@@ -158,6 +159,7 @@ func main() {
prometheus.MustRegister(nodeCollector) prometheus.MustRegister(nodeCollector)
http.Handle(*metricsPath, prometheus.Handler()) http.Handle(*metricsPath, prometheus.Handler())
http.HandleFunc("/health", healthCheck)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, *metricsPath, http.StatusMovedPermanently) 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 { func keys(m map[string]collector.Collector) []string {
ret := make([]string, 0, len(m)) ret := make([]string, 0, len(m))
for key, _ := range m { for key := range m {
ret = append(ret, key) ret = append(ret, key)
} }
return ret return ret