diff --git a/pkg/infra/usagestats/statscollector/service.go b/pkg/infra/usagestats/statscollector/service.go index 092ba4ce54c..a4273548e2f 100644 --- a/pkg/infra/usagestats/statscollector/service.go +++ b/pkg/infra/usagestats/statscollector/service.go @@ -161,6 +161,12 @@ func (s *Service) collectSystemStats(ctx context.Context) (map[string]interface{ m["stats.active_data_keys.count"] = statsResult.ActiveDataKeys m["stats.public_dashboards.count"] = statsResult.PublicDashboards m["stats.correlations.count"] = statsResult.Correlations + if statsResult.DatabaseCreatedTime != nil { + m["stats.database.created.time"] = statsResult.DatabaseCreatedTime.Unix() + } + if statsResult.DatabaseDriver != "" { + m["stats.database.driver"] = statsResult.DatabaseDriver + } ossEditionCount := 1 enterpriseEditionCount := 0 diff --git a/pkg/services/stats/models.go b/pkg/services/stats/models.go index 1c0e4b93630..ea6ae9eecb3 100644 --- a/pkg/services/stats/models.go +++ b/pkg/services/stats/models.go @@ -1,5 +1,7 @@ package stats +import "time" + type SystemStats struct { Dashboards int64 DashboardBytesTotal int64 @@ -45,6 +47,10 @@ type SystemStats struct { ActiveDataKeys int64 PublicDashboards int64 Correlations int64 + DatabaseCreatedTime *time.Time + + // name of the driver + DatabaseDriver string } type DataSourceStats struct { diff --git a/pkg/services/stats/statsimpl/stats.go b/pkg/services/stats/statsimpl/stats.go index 081f21075b5..1377dc8932c 100644 --- a/pkg/services/stats/statsimpl/stats.go +++ b/pkg/services/stats/statsimpl/stats.go @@ -63,10 +63,10 @@ func notServiceAccount(dialect migrator.Dialect) string { } func (ss *sqlStatsService) GetSystemStats(ctx context.Context, query *stats.GetSystemStatsQuery) (result *stats.SystemStats, err error) { + dialect := ss.db.GetDialect() err = ss.db.WithDbSession(ctx, func(dbSession *db.Session) error { sb := &db.SQLBuilder{} sb.Write("SELECT ") - dialect := ss.db.GetDialect() sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("user") + ` WHERE ` + notServiceAccount(dialect) + `) AS users,`) sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("org") + `) AS orgs,`) sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("data_source") + `) AS datasources,`) @@ -127,6 +127,7 @@ func (ss *sqlStatsService) GetSystemStats(ctx context.Context, query *stats.GetS sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("data_keys") + `) AS data_keys,`) sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("data_keys") + `WHERE active = true) AS active_data_keys,`) sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("dashboard_public") + `) AS public_dashboards,`) + sb.Write(`(SELECT MIN(timestamp) FROM ` + dialect.Quote("migration_log") + `) AS database_created_time,`) sb.Write(ss.roleCounterSQL(ctx)) @@ -138,8 +139,11 @@ func (ss *sqlStatsService) GetSystemStats(ctx context.Context, query *stats.GetS result = &stats + result.DatabaseDriver = dialect.DriverName() + return nil }) + return result, err } diff --git a/pkg/services/stats/statsimpl/stats_test.go b/pkg/services/stats/statsimpl/stats_test.go index f2d1c840efd..3aa828f108a 100644 --- a/pkg/services/stats/statsimpl/stats_test.go +++ b/pkg/services/stats/statsimpl/stats_test.go @@ -41,6 +41,8 @@ func TestIntegrationStatsDataAccess(t *testing.T) { assert.Equal(t, int64(0), result.LibraryVariables) assert.Equal(t, int64(0), result.APIKeys) assert.Equal(t, int64(2), result.Correlations) + assert.NotNil(t, result.DatabaseCreatedTime) + assert.Equal(t, db.Dialect.DriverName(), result.DatabaseDriver) }) t.Run("Get system user count stats should not results in error", func(t *testing.T) {