package main // import "git.fromouter.space/crunchy-rocks/clessy/stats" import ( "flag" "net/http" "strconv" "strings" "git.fromouter.space/hamcha/tg" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) func process(broker *tg.Broker, update tg.APIUpdate) { if update.Message != nil { opTotalMsg.Inc() // Check if it's a chat if update.Message.Chat != nil { opMsgPerChat.With(prometheus.Labels{ "chatid": strconv.FormatInt(update.Message.Chat.ChatID, 10), "user": update.Message.User.Username, }).Inc() } if update.Message.Text != nil { if strings.HasPrefix(*update.Message.Text, "/") { opCommand.With(prometheus.Labels{ "command": strings.SplitN(*update.Message.Text, " ", 2)[0], }) } } } } func main() { brokerAddr := flag.String("broker", "localhost:7314", "Broker address:port") flag.Parse() registerMetrics() broker, err := tg.ConnectToBroker(*brokerAddr) assert(err) defer broker.Close() go func() { http.Handle("/metrics", promhttp.Handler()) http.ListenAndServe(":2112", nil) }() assert(tg.RunBrokerClient(broker, process)) } func assert(err error) { if err != nil { panic(err) } }