diff --git a/cmd/controlloop/controlloop.go b/cmd/controlloop/controlloop.go index fd78b2b26..0655dc1a6 100644 --- a/cmd/controlloop/controlloop.go +++ b/cmd/controlloop/controlloop.go @@ -3,6 +3,8 @@ package main import ( "flag" "fmt" + "log" + "net/http" "os" "os/signal" "time" @@ -26,6 +28,8 @@ import ( "github.com/k8snetworkplumbingwg/whereabouts/pkg/controlloop" "github.com/k8snetworkplumbingwg/whereabouts/pkg/logging" "github.com/k8snetworkplumbingwg/whereabouts/pkg/reconciler" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promhttp" ) const ( @@ -62,6 +66,24 @@ func main() { networkController.Start(stopChan) + reconcilerSuccessTotal := prometheus.NewCounter(prometheus.CounterOpts{ + Name: "reconciler_success_total", + Help: "Increments upon successful run of IP reconciler", + }) + + reconcilerAttempted := prometheus.NewCounter(prometheus.CounterOpts{ + Name: "reconciler_attempted", + Help: "Increments after each attempt of an IP reconciler run", + }) + + prometheus.MustRegister(reconcilerSuccessTotal, reconcilerAttempted) + + http.Handle("/metrics", promhttp.Handler()) + + go func() { + log.Fatal(http.ListenAndServe(":1984", nil)) + }() + s := gocron.NewScheduler(time.UTC) s.Cron("0 30 4 1/1 * ? *").Do(func() { // every day at 4:30 UTC (user configurable cron expression) reconciler.InvokeIPReconciler(returnErr) @@ -74,7 +96,9 @@ func main() { s.Stop() return case err := <-returnErr: + reconcilerAttempted.Inc() if err == nil { + reconcilerSuccessTotal.Inc() logging.Verbosef("reconciler success") } else { logging.Verbosef("reconciler failure")