mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-22 03:37:43 +00:00
report statistics about account and device counts
This commit is contained in:
parent
fd18ea551e
commit
d563ad26f1
1 changed files with 25 additions and 0 deletions
|
@ -106,6 +106,7 @@ func main() {
|
|||
|
||||
s := gocron.NewScheduler(time.UTC)
|
||||
s.Every(1).Second().Do(func() { enqueueAccounts(ctx, logger, statsd, pool, redisConn, notificationsQueue) })
|
||||
s.Every(1).Minute().Do(func() { reportStats(ctx, logger, statsd, pool, redisConn) })
|
||||
s.StartAsync()
|
||||
|
||||
signals := make(chan os.Signal, 1)
|
||||
|
@ -122,6 +123,30 @@ func main() {
|
|||
s.Stop()
|
||||
}
|
||||
|
||||
func reportStats(ctx context.Context, logger *logrus.Logger, statsd *statsd.Client, pool *pgxpool.Pool, redisConn *redis.Client) {
|
||||
var (
|
||||
count int64
|
||||
|
||||
metrics = []struct {
|
||||
query string
|
||||
name string
|
||||
}{
|
||||
{"SELECT COUNT(*) FROM accounts", "apollo.registrations.accounts"},
|
||||
{"SELECT COUNT(*) FROM devices", "apollo.registrations.devices"},
|
||||
}
|
||||
)
|
||||
|
||||
for _, metric := range metrics {
|
||||
pool.QueryRow(ctx, metric.query).Scan(&count)
|
||||
statsd.Gauge(metric.name, float64(count), []string{}, 1)
|
||||
|
||||
logger.WithFields(logrus.Fields{
|
||||
"count": count,
|
||||
"metric": metric.name,
|
||||
}).Debug("fetched metrics")
|
||||
}
|
||||
}
|
||||
|
||||
func enqueueAccounts(ctx context.Context, logger *logrus.Logger, statsd *statsd.Client, pool *pgxpool.Pool, redisConn *redis.Client, queue rmq.Queue) {
|
||||
start := time.Now()
|
||||
|
||||
|
|
Loading…
Reference in a new issue