Browse Source

Adds readiness and liveness endpoints.

master
Christian Fritz 4 years ago
parent
commit
1cf0dfb5ae
No known key found for this signature in database GPG Key ID: AB40486FCA9FA29C
  1. 2
      go.mod
  2. 17
      health.go
  3. 6
      main.go

2
go.mod

@ -3,7 +3,9 @@ module github.com/sberk42/fritzbox_exporter
go 1.15
require (
github.com/heptiolabs/healthcheck v0.0.0-20180807145615-6ff867650f40
github.com/namsral/flag v1.7.4-pre
github.com/prometheus/client_golang v1.10.0
golang.org/x/text v0.3.6
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 // indirect
)

17
health.go

@ -0,0 +1,17 @@
package main
import (
"github.com/heptiolabs/healthcheck"
"time"
)
// createHealthChecks will create the readiness and liveness endpoints and add the check functions.
func createHealthChecks(gatewayUrl string) healthcheck.Handler {
health := healthcheck.NewHandler()
health.AddReadinessCheck("FRITZ!Box connection",
healthcheck.HTTPGetCheck(gatewayUrl+"/any.xml", time.Duration(3)*time.Second))
health.AddLivenessCheck("go-routines", healthcheck.GoroutineCountCheck(100))
return health
}

6
main.go

@ -847,8 +847,14 @@ func main() {
prometheus.MustRegister(collectLuaResultsLoaded)
}
healthChecks := createHealthChecks(*flagGatewayURL)
http.Handle("/metrics", promhttp.Handler())
fmt.Printf("metrics available at http://%s/metrics\n", *flagAddr)
http.HandleFunc("/ready", healthChecks.ReadyEndpoint)
fmt.Printf("readyness check available at http://%s/ready\n", *flagAddr)
http.HandleFunc("/live", healthChecks.LiveEndpoint)
fmt.Printf("liveness check available at http://%s/live\n", *flagAddr)
log.Fatal(http.ListenAndServe(*flagAddr, nil))
}

Loading…
Cancel
Save