package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
"time"
)
var prometheusMetrics *logger.PrometheusMetrics
func main() {
go initPrometheus(prom)
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
}
func initPrometheus(url string) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
i := 0
pusher := push.New(url, "verulink_test").Grouping("instance", "test")
prometheusMetrics = logger.NewPrometheusMetrics()
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
fmt.Println("Stopping metric push...")
return
case <-ticker.C:
prometheusMetrics.AddInPackets("machine1", i)
gatherer := prometheus.Gatherers{
prometheusMetrics.Registry,
}
fmt.Println("Attempting to push metrics...")
if err := pusher.Gatherer(gatherer).Push(); err != nil {
fmt.Printf("Error pushing metrics to Pushgateway: %s\n", err)
} else {
fmt.Println("Metrics pushed successfully.")
}
i++
}
}
}