Skip to content

Commit a0d529d

Browse files
committed
Add custom health check endpoint
Signed-off-by: Povilas Vaitkus <[email protected]>
1 parent 231987c commit a0d529d

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ If you are still using the legacy [Access scopes][access-scopes], the `https://w
9999
| `web.systemd-socket` | No | | Use systemd socket activation listeners instead of port listeners (Linux only). |
100100
| `web.stackdriver-telemetry-path` | No | `/metrics` | Path under which to expose Stackdriver metrics. |
101101
| `web.telemetry-path` | No | `/metrics` | Path under which to expose Prometheus metrics |
102+
| `web.health-check-path` | No | `/heath` | Path under which to expose health check |
102103

103104
### TLS and basic authentication
104105

stackdriver_exporter.go

+11
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ var (
5555
"web.stackdriver-telemetry-path", "Path under which to expose Stackdriver metrics.",
5656
).Default("/metrics").String()
5757

58+
healthCheckPath = kingpin.Flag(
59+
"web.health-check-path", "Path under which to expose health check.",
60+
).Default("/health").String()
61+
5862
projectID = kingpin.Flag(
5963
"google.project-id", "DEPRECATED - Comma seperated list of Google Project IDs. Use 'google.project-ids' instead.",
6064
).String()
@@ -275,6 +279,8 @@ func main() {
275279
kingpin.HelpFlag.Short('h')
276280
kingpin.Parse()
277281

282+
http.HandleFunc(*healthCheckPath, healthCheckHandler)
283+
278284
logger := promslog.New(promslogConfig)
279285
if *projectID != "" {
280286
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 {
432438
}
433439
return extraFilters
434440
}
441+
442+
func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
443+
w.WriteHeader(http.StatusOK)
444+
w.Write([]byte("OK"))
445+
}

0 commit comments

Comments
 (0)