MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / startMonitoringServer

Function startMonitoringServer

cmd/workers.go:538–578  ·  view source on GitHub ↗
(conf *config.Configuration)

Source from the content-addressed store, hash-verified

536}
537
538func startMonitoringServer(conf *config.Configuration) *http.Server {
539 redisOption, _ := redis_db.ParseRedisURL(conf.Redis.Dns, conf.Redis.SkipTLSVerify)
540 asynqmonHandler := asynqmon.New(asynqmon.Options{
541 RootPath: "/monitoring",
542 RedisConnOpt: asynq.RedisClientOpt{
543 Addr: redisOption.Addr,
544 Password: redisOption.Password,
545 DB: redisOption.DB,
546 TLSConfig: redisOption.TLSConfig,
547 PoolSize: conf.Redis.PoolSize,
548 },
549 })
550
551 monitoringMux := http.NewServeMux()
552
553 monitoringMux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
554 w.Header().Set("Content-Type", "application/json")
555 w.WriteHeader(http.StatusOK)
556 _, _ = fmt.Fprintf(w, `{"status": "UP", "service": "worker"}`)
557 })
558
559 monitoringMux.Handle("/monitoring/", asynqmonHandler)
560 if h := trace.MetricsHandler(); h != nil {
561 monitoringMux.Handle("/metrics", middleware.MetricsAuthHandler(conf.Server.Secure, conf.Server.MetricsBearerToken, h))
562 }
563
564 monitoringAddr := fmt.Sprintf(":%s", conf.Queue.MonitoringPort)
565 srv := &http.Server{
566 Addr: monitoringAddr,
567 Handler: monitoringMux,
568 }
569
570 go func() {
571 logrus.Errorf("Worker monitoring server listening on %s (health: /health, dashboard: /monitoring)", monitoringAddr)
572 if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
573 logrus.Fatalf("could not start monitoring server: %v", err)
574 }
575 }()
576
577 return srv
578}

Callers 1

workerCommandsFunction · 0.85

Calls 2

MetricsAuthHandlerFunction · 0.92
SetMethod · 0.65

Tested by

no test coverage detected