From 6fdda6c360e2b7851a7807484e121b73edd14100 Mon Sep 17 00:00:00 2001 From: Daniel Mason Date: Mon, 1 May 2023 21:40:06 +1200 Subject: [PATCH] Add calckey --- cmd/gomastodonstats/main.go | 1 + internal/gomastodonstats/consts.go | 5 +++++ internal/gomastodonstats/metrics.go | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/cmd/gomastodonstats/main.go b/cmd/gomastodonstats/main.go index c0efdbc..5e71ca7 100644 --- a/cmd/gomastodonstats/main.go +++ b/cmd/gomastodonstats/main.go @@ -78,6 +78,7 @@ func main() { gms.MOBILIZON_DB_SCHEMA = os.Getenv("MOBILIZON_DB_SCHEMA") gms.PEERTUBE_DB_SCHEMA = os.Getenv("PEERTUBE_DB_SCHEMA") gms.BOOKWYRM_DB_SCHEMA = os.Getenv("BOOKWYRM_DB_SCHEMA") + gms.CALCKEY_DB_SCHEMA = os.Getenv("CALCKEY_DB_SCHEMA") gms.Run() } diff --git a/internal/gomastodonstats/consts.go b/internal/gomastodonstats/consts.go index 934b6c5..18f8f6f 100644 --- a/internal/gomastodonstats/consts.go +++ b/internal/gomastodonstats/consts.go @@ -65,4 +65,9 @@ var ( BOOKWYRM_DB_SCHEMA string BOOKWYRM_USER_QUERY = "SELECT count(*) FROM bookwyrm_user WHERE local = True AND is_active = True;" BOOKWYRM_IDENTIFIER = "bookwyrm" + + // Calckey + CALCKEY_DB_SCHEMA string + CALCKEY_USER_QUERY = `SELECT count(*) FROM "user" WHERE "isDeleted" = False and "host" IS NULL;` + CALCKEY_IDENTIFIER = "calckey" ) diff --git a/internal/gomastodonstats/metrics.go b/internal/gomastodonstats/metrics.go index a49443b..af7fe49 100644 --- a/internal/gomastodonstats/metrics.go +++ b/internal/gomastodonstats/metrics.go @@ -155,6 +155,23 @@ func getUserCounts() ([]metric, error) { } } + if CALCKEY_DB_SCHEMA != "" { + userCount, err := runIntQuery(CALCKEY_DB_SCHEMA, CALCKEY_USER_QUERY) + if err != nil { + log.Println(err) + } else { + m := metric{ + Service: CALCKEY_IDENTIFIER, + MetricName: METRICNAME_USERCOUNT, + MetricValue: userCount, + PreviousDayMetricValue: getLastMetric(CALCKEY_IDENTIFIER), + PreviousWeekMetricValue: getLastWeekMetric(CALCKEY_IDENTIFIER), + } + log.Printf("%s user count: %d", CALCKEY_IDENTIFIER, userCount) + metrics = append(metrics, m) + } + } + return metrics, nil }