@@ -6,10 +6,12 @@ import (
66 "GoGeizhalsBot/internal/config"
77 "GoGeizhalsBot/internal/database"
88 "GoGeizhalsBot/internal/geizhals"
9+ "GoGeizhalsBot/internal/prometheus"
910 "fmt"
1011 "log"
1112 "net/http"
1213 "net/url"
14+ "time"
1315
1416 "github.com/PaulSonOfLars/gotgbot/v2/ext/handlers/filters/message"
1517
@@ -218,6 +220,7 @@ func showPriceagentDetail(b *gotgbot.Bot, ctx *ext.Context) error {
218220 },
219221 }
220222
223+ // Check if the initial message contained a photo, if yes, we're coming from the price history graph
221224 if len (cb .Message .Photo ) > 0 {
222225 bot .DeleteMessage (ctx .EffectiveChat .Id , cb .Message .MessageId )
223226
@@ -344,6 +347,7 @@ func deletePriceagentHandler(b *gotgbot.Bot, ctx *ext.Context) error {
344347}
345348
346349func newUserHandler (_ * gotgbot.Bot , ctx * ext.Context ) error {
350+ prometheus .TotalUserInteractions .Inc ()
347351 // Create user in databse if they don't exist already
348352 if ! ctx .EffectiveSender .IsUser () {
349353 return nil
@@ -480,5 +484,22 @@ func Start(botConfig config.Config) {
480484
481485 log .Printf ("Bot has been started as @%s...\n " , bot .User .Username )
482486
487+ if botConfig .Prometheus .Enabled {
488+ // Periodically update the metrics from the database
489+ go func () {
490+ for {
491+ prometheus .TotalUniquePriceagentsValue = database .GetPriceAgentCount ()
492+ prometheus .TotalUniqueUsersValue = database .GetUserCount ()
493+ prometheus .TotalUniqueWishlistPriceagentsValue = database .GetPriceAgentWishlistCount ()
494+ prometheus .TotalUniqueProductPriceagentsValue = database .GetPriceAgentProductCount ()
495+ time .Sleep (time .Second * 60 )
496+ }
497+ }()
498+
499+ exportAddr := fmt .Sprintf ("%s:%d" , botConfig .Prometheus .ExportIP , botConfig .Prometheus .ExportPort )
500+ log .Printf ("Starting prometheus exporter on %s...\n " , exportAddr )
501+ prometheus .StartPrometheusExporter (exportAddr )
502+ }
503+
483504 updater .Idle ()
484505}
0 commit comments