mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-02 00:26:35 +00:00
Merge pull request #30 from martinlindhe/health
exporter: add /health endpoint. fixes #25
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user