diff --git a/README.md b/README.md index 0d04e05..abc181a 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,7 @@ If you are still using the legacy [Access scopes][access-scopes], the `https://w | `web.systemd-socket` | No | | Use systemd socket activation listeners instead of port listeners (Linux only). | | `web.stackdriver-telemetry-path` | No | `/metrics` | Path under which to expose Stackdriver metrics. | | `web.telemetry-path` | No | `/metrics` | Path under which to expose Prometheus metrics | +| `web.health-check-path` | No | `/heath` | Path under which to expose health check | ### TLS and basic authentication diff --git a/stackdriver_exporter.go b/stackdriver_exporter.go index 4fc1c0a..33a6f3e 100644 --- a/stackdriver_exporter.go +++ b/stackdriver_exporter.go @@ -55,6 +55,10 @@ var ( "web.stackdriver-telemetry-path", "Path under which to expose Stackdriver metrics.", ).Default("/metrics").String() + healthCheckPath = kingpin.Flag( + "web.health-check-path", "Path under which to expose health check.", + ).Default("/health").String() + projectID = kingpin.Flag( "google.project-id", "DEPRECATED - Comma seperated list of Google Project IDs. Use 'google.project-ids' instead.", ).String() @@ -275,6 +279,8 @@ func main() { kingpin.HelpFlag.Short('h') kingpin.Parse() + http.HandleFunc(*healthCheckPath, healthCheckHandler) + logger := promslog.New(promslogConfig) if *projectID != "" { logger.Warn("The google.project-id flag is deprecated and will be replaced by google.project-ids.") @@ -432,3 +438,8 @@ func parseMetricExtraFilters() []collectors.MetricFilter { } return extraFilters } + +func healthCheckHandler(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte("OK")) +}