add basic healthcheck
This commit is contained in:
parent
782812de4b
commit
17924e7bb6
8
stats.go
8
stats.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
@ -36,10 +37,17 @@ func init() {
|
||||||
type Stats struct {
|
type Stats struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For verifying the service is up
|
||||||
|
func healthHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Fprintf(w, "OK")
|
||||||
|
}
|
||||||
|
|
||||||
// NewStats returns new empty Stats object.
|
// NewStats returns new empty Stats object.
|
||||||
func NewStats(statsPort string) *Stats {
|
func NewStats(statsPort string) *Stats {
|
||||||
go func() {
|
go func() {
|
||||||
http.Handle("/metrics", promhttp.Handler())
|
http.Handle("/metrics", promhttp.Handler())
|
||||||
|
// Add most trivial healthcheck
|
||||||
|
http.HandleFunc("/health", healthHandler)
|
||||||
log.Fatal(http.ListenAndServe(statsPort, nil))
|
log.Fatal(http.ListenAndServe(statsPort, nil))
|
||||||
}()
|
}()
|
||||||
return &Stats{}
|
return &Stats{}
|
||||||
|
|
Loading…
Reference in New Issue