github.com/koko1123/flow-go-1@v0.29.6/module/metrics/example/setup.go (about)

     1  package example
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"os/signal"
     7  	"syscall"
     8  
     9  	"github.com/rs/zerolog"
    10  	"github.com/rs/zerolog/log"
    11  
    12  	"github.com/koko1123/flow-go-1/module/metrics"
    13  )
    14  
    15  func WithMetricsServer(f func(logger zerolog.Logger)) {
    16  	logger := zerolog.New(os.Stderr).With().Timestamp().Logger()
    17  	port := 3030
    18  	server := metrics.NewServer(logger, uint(port))
    19  	exitSig := make(chan os.Signal, 1)
    20  	signal.Notify(exitSig, os.Interrupt, syscall.SIGTERM)
    21  
    22  	<-server.Ready()
    23  
    24  	go f(logger)
    25  
    26  	fmt.Printf("server is ready, port: %v\n", port)
    27  	fmt.Printf("launch prometheus server: \n" +
    28  		"prometheus --config.file=../flow-go/module/metrics/test/prometheus.yml\n" +
    29  		"then open http://localhost:9090 to monitor the collected metrics\n")
    30  
    31  	<-exitSig
    32  	log.Warn().Msg("component startup aborted")
    33  	os.Exit(1)
    34  }