Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

stats.go 930B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package stats
  2. import (
  3. "context"
  4. "fmt"
  5. "net"
  6. "net/http"
  7. "github.com/9seconds/mtg/config"
  8. )
  9. var Stats Interface
  10. func Init(ctx context.Context) error {
  11. mux := http.NewServeMux()
  12. instancePrometheus, err := newStatsPrometheus(mux)
  13. if err != nil {
  14. return fmt.Errorf("cannot initialize prometheus: %w", err)
  15. }
  16. stats := []Interface{instancePrometheus}
  17. if config.C.StatsdAddr != nil {
  18. instanceStatsd, err := newStatsStatsd()
  19. if err != nil {
  20. return fmt.Errorf("cannot inialize statsd: %w", err)
  21. }
  22. stats = append(stats, instanceStatsd)
  23. }
  24. listener, err := net.Listen("tcp", config.C.StatsBind.String())
  25. if err != nil {
  26. return fmt.Errorf("cannot initialize stats server: %w", err)
  27. }
  28. srv := http.Server{
  29. Handler: mux,
  30. }
  31. go srv.Serve(listener) // nolint: errcheck
  32. go func() {
  33. <-ctx.Done()
  34. srv.Shutdown(context.Background()) // nolint: errcheck
  35. }()
  36. Stats = multiStats(stats)
  37. return nil
  38. }