FILE / ScuroNeko/mtg

stats/stats.go

Исходный файл и его история в репозитории.
FILE d32ab34e602af95aeb34b198ec722067b680b0af
Files
mtg/stats/stats.go
T

42 lines
681 B
Go

package stats
import (
"context"
"fmt"
"net"
"net/http"
"github.com/9seconds/mtg/config"
)
var Stats Interface
func Init(ctx context.Context) error {
mux := http.NewServeMux()
stats := []Interface{newStatsPrometheus(mux)}
if config.C.StatsdAddr != nil {
stats = append(stats, newStatsStatsd())
}
listener, err := net.Listen("tcp", config.C.StatsBind.String())
if err != nil {
return fmt.Errorf("cannot initialize stats server: %w", err)
}
srv := http.Server{
Handler: mux,
}
go srv.Serve(listener) // nolint: errcheck
go func() {
<-ctx.Done()
srv.Shutdown(context.Background()) // nolint: errcheck
}()
Stats = multiStats(stats)
return nil
}