From cf725b21737f2a481df1d3a714b056ded97e8b69 Mon Sep 17 00:00:00 2001 From: Victor Marmol Date: Sat, 30 Aug 2014 00:52:25 -0700 Subject: [PATCH] Add a /healthz endpoint to cAdvisor. Fixes #181 --- cadvisor.go | 6 ++++++ healthz/healthz.go | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 healthz/healthz.go diff --git a/cadvisor.go b/cadvisor.go index 7f4ae1eb..cd0b1f60 100644 --- a/cadvisor.go +++ b/cadvisor.go @@ -24,6 +24,7 @@ import ( "github.com/google/cadvisor/api" "github.com/google/cadvisor/container/docker" "github.com/google/cadvisor/container/raw" + "github.com/google/cadvisor/healthz" "github.com/google/cadvisor/info" "github.com/google/cadvisor/manager" "github.com/google/cadvisor/pages" @@ -60,6 +61,11 @@ func main() { glog.Fatalf("raw registration failed: %v.", err) } + // Basic health handler. + if err := healthz.RegisterHandler(); err != nil { + glog.Fatalf("failed to register healthz handler: %s", err) + } + // Handler for static content. http.HandleFunc(static.StaticResource, func(w http.ResponseWriter, r *http.Request) { err := static.HandleRequest(w, r.URL) diff --git a/healthz/healthz.go b/healthz/healthz.go new file mode 100644 index 00000000..2c9f0e21 --- /dev/null +++ b/healthz/healthz.go @@ -0,0 +1,16 @@ +package healthz + +import ( + "net/http" +) + +func handleHealthz(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("ok")) +} + +// Register simple HTTP /healthz handler to return "ok". +func RegisterHandler() error { + http.HandleFunc("/healthz", handleHealthz) + return nil +}