Skip to content

Commit 134ed85

Browse files
committed
Added metrics for prometheus alerting capability
Signed-off-by: nicklesimba <[email protected]>
1 parent 24ebe8c commit 134ed85

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cmd/controlloop/controlloop.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package main
33
import (
44
"flag"
55
"fmt"
6+
"log"
7+
"net/http"
68
"os"
79
"os/signal"
810
"time"
@@ -26,6 +28,8 @@ import (
2628
"github.com/k8snetworkplumbingwg/whereabouts/pkg/controlloop"
2729
"github.com/k8snetworkplumbingwg/whereabouts/pkg/logging"
2830
"github.com/k8snetworkplumbingwg/whereabouts/pkg/reconciler"
31+
"github.com/prometheus/client_golang/prometheus"
32+
"github.com/prometheus/client_golang/prometheus/promhttp"
2933
)
3034

3135
const (
@@ -62,6 +66,24 @@ func main() {
6266

6367
networkController.Start(stopChan)
6468

69+
reconcilerSuccessTotal := prometheus.NewCounter(prometheus.CounterOpts{
70+
Name: "reconciler_success_total",
71+
Help: "Increments upon successful run of IP reconciler",
72+
})
73+
74+
reconcilerAttempted := prometheus.NewCounter(prometheus.CounterOpts{
75+
Name: "reconciler_attempted",
76+
Help: "Increments after each attempt of an IP reconciler run",
77+
})
78+
79+
prometheus.MustRegister(reconcilerSuccessTotal, reconcilerAttempted)
80+
81+
http.Handle("/metrics", promhttp.Handler())
82+
83+
go func() {
84+
log.Fatal(http.ListenAndServe(":1984", nil))
85+
}()
86+
6587
s := gocron.NewScheduler(time.UTC)
6688
s.Cron("0 30 4 1/1 * ? *").Do(func() { // every day at 4:30 UTC (user configurable cron expression)
6789
reconciler.InvokeIPReconciler(returnErr)
@@ -74,7 +96,9 @@ func main() {
7496
s.Stop()
7597
return
7698
case err := <-returnErr:
99+
reconcilerAttempted.Inc()
77100
if err == nil {
101+
reconcilerSuccessTotal.Inc()
78102
logging.Verbosef("reconciler success")
79103
} else {
80104
logging.Verbosef("reconciler failure")

0 commit comments

Comments
 (0)