Rolling 1 week stats

This commit is contained in:
idanoo 2023-02-13 18:39:44 +13:00
parent 17b1f261a0
commit 88ee8ac2a7
Signed by: idanoo
GPG key ID: 387387CDBC02F132
2 changed files with 22 additions and 4 deletions

View file

@ -22,7 +22,8 @@ var (
MASTODON_CLIENT_PASSWORD string
// UserCount metric name
METRICNAME_USERCOUNT = "userCount"
METRICNAME_USERCOUNT = "userCount"
METRICNAME_1W_USERCOUNT = "userCount1W"
// This is hardcoded because.. well configs are annoying
SERVICE_LINKS = map[string]string{
@ -44,9 +45,10 @@ var (
MATRIX_IDENTIFIDER = "matrix"
// Mastodon
MASTODON_DB_SCHEMA string
MASTODON_USER_QUERY = "SELECT count(*) FROM users WHERE disabled = False AND confirmed_at IS NOT NULL AND approved = True;"
MASTODON_IDENTIFIER = "mastodon"
MASTODON_DB_SCHEMA string
MASTODON_USER_QUERY = "SELECT count(*) FROM users WHERE disabled = False AND confirmed_at IS NOT NULL AND approved = True;"
MASTODON_1W_ACTIVE_USER_QUERY = "SELECT count(*) FROM users WHERE disabled = False AND confirmed_at IS NOT NULL AND approved = True AND current_sign_in_at >= now() - interval '1 week';"
MASTODON_IDENTIFIER = "mastodon"
// Mobilizon
MOBILIZON_DB_SCHEMA string

View file

@ -86,6 +86,22 @@ func getUserCounts() ([]metric, error) {
log.Printf("%s user count: %d", MASTODON_IDENTIFIER, userCount)
metrics = append(metrics, m)
}
// Extra metrics for DB only
userCount1W, err := runIntQuery(MASTODON_DB_SCHEMA, MASTODON_1W_ACTIVE_USER_QUERY)
if err != nil {
log.Println(err)
} else {
customMetrics := []metric{
{
Service: MATRIX_IDENTIFIDER,
MetricName: METRICNAME_1W_USERCOUNT,
MetricValue: userCount1W,
},
}
_ = persistMetrics(customMetrics)
}
}
if MOBILIZON_DB_SCHEMA != "" {