mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-22 15:30:59 +00:00
add healthcheck endpoint
Signed-off-by: Yaron Idan <yaronidan@gmail.com>
This commit is contained in:
parent
da85f9d207
commit
f0c7abebb1
1 changed files with 12 additions and 0 deletions
12
main.go
12
main.go
|
@ -15,6 +15,7 @@ package main
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
|
@ -250,6 +251,7 @@ func main() {
|
|||
var (
|
||||
listenAddress = kingpin.Flag("web.listen-address", "The address on which to expose the web interface and generated Prometheus metrics.").Default(":9102").String()
|
||||
enableLifecycle = kingpin.Flag("web.enable-lifecycle", "Enable shutdown and reload via HTTP request.").Default("false").Bool()
|
||||
enableHealthEndpoint = kingpin.Flag("web.enable-health-path", "Enable health check via HTTP request.").Default("true").Bool()
|
||||
metricsEndpoint = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
|
||||
statsdListenUDP = kingpin.Flag("statsd.listen-udp", "The UDP address on which to receive statsd metric lines. \"\" disables it.").Default(":9125").String()
|
||||
statsdListenTCP = kingpin.Flag("statsd.listen-tcp", "The TCP address on which to receive statsd metric lines. \"\" disables it.").Default(":9125").String()
|
||||
|
@ -494,6 +496,16 @@ func main() {
|
|||
})
|
||||
}
|
||||
|
||||
if *enableHealthEndpoint {
|
||||
mux.HandleFunc("/-/healthy", func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == http.MethodGet {
|
||||
level.Debug(logger).Log("msg", "Received health check")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
fmt.Fprintf(w, "Statsd Exporter is Healthy.\n")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
go serveHTTP(mux, *listenAddress, logger)
|
||||
|
||||
signals := make(chan os.Signal, 1)
|
||||
|
|
Loading…
Reference in a new issue