PaulSonOfLars/gotgbot

Question: metricsBot

svscorp opened this issue · 2 comments

Hi @PaulSonOfLars

I got enthusiastic about your example of metricsBot, indeed would be good to expose some prom metrics for scraping.

However, if I am using the webhook strategy, so

  1. webhookOpts := ext.WebhookOpts{
    ListenAddr: "ip:" + port,
    SecretToken: token,
    }
  2. updater.StartWebhook(bot, webhookPath, webhookOpts)
  3. updater.SetAllBotWebhooks

How do I enable metrics to sit, i.e. on metricsPath?

I understand by using your example, by adding Processor into dispatcher and starting monitorDispatcherBuffer, it will collect metrics. The question is, how to expose it on another path, that will give metrics on GET request, and not telegram messages to webhook.

I am trying this approach:

        webhookOpts := &ext.AddWebhookOpts{
		SecretToken: someSecret,
	}

        updaterSubpath := "/bots/"
	err = updater.AddWebhook(b, "webhook/, webhookOpts)
	
        // by the way, in your example for webapp bot this I believe is outdated: 
        // updater.AddWebhook(b, b.Token, &ext.AddWebhookOpts{SecretToken: webhookSecret})

	if err != nil {
		panic("failed to add webhook: " + err.Error())
	}

	err = updater.SetAllBotWebhooks( APP_BASE_URL + updaterSubpath , &gotgbot.SetWebhookOpts{
		MaxConnections:     100,
		DropPendingUpdates: true,
		SecretToken:        webhookOpts.SecretToken,
	})
	if err != nil {
		panic("failed to set webhook: " + err.Error())
	}

	mux := http.NewServeMux()
	mux.HandleFunc("/metrics", metrics())
	mux.HandleFunc(updaterSubpath, updater.GetHandlerFunc(updaterSubpath))

	server := http.Server{
		Handler: mux,
		Addr:    "0.0.0.0:8000",
	}

	if err := server.ListenAndServe(); err != nil {
		panic("failed to listen and serve: " + err.Error())
	}

While the metrics endpoint is reachable and returning some response. So I will try to proceed with this.

All good :)