Skip to content

Commit

Permalink
Added metrics for prometheus alerting capability
Browse files Browse the repository at this point in the history
Signed-off-by: nicklesimba <[email protected]>
  • Loading branch information
nicklesimba committed Jun 9, 2022
1 parent 24ebe8c commit 134ed85
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cmd/controlloop/controlloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"time"
Expand All @@ -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 (
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand Down

0 comments on commit 134ed85

Please sign in to comment.