diff --git a/internal/gomastodonstats/consts.go b/internal/gomastodonstats/consts.go index 72dfab3..76f4f4b 100644 --- a/internal/gomastodonstats/consts.go +++ b/internal/gomastodonstats/consts.go @@ -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 diff --git a/internal/gomastodonstats/metrics.go b/internal/gomastodonstats/metrics.go index a228049..f24caf3 100644 --- a/internal/gomastodonstats/metrics.go +++ b/internal/gomastodonstats/metrics.go @@ -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 != "" {