Browse Source

stats: send amount of stars as stats

bergquist 8 years ago
parent
commit
ee973a977b
3 changed files with 63 additions and 58 deletions
  1. 1 0
      pkg/metrics/metrics.go
  2. 1 0
      pkg/models/stats.go
  3. 61 58
      pkg/services/sqlstore/stats.go

+ 1 - 0
pkg/metrics/metrics.go

@@ -379,6 +379,7 @@ func sendUsageStats() {
 	metrics["stats.alerts.count"] = statsQuery.Result.Alerts
 	metrics["stats.active_users.count"] = statsQuery.Result.ActiveUsers
 	metrics["stats.datasources.count"] = statsQuery.Result.Datasources
+	metrics["stats.stars.count"] = statsQuery.Result.Stars
 
 	dsStats := models.GetDataSourceStatsQuery{}
 	if err := bus.Dispatch(&dsStats); err != nil {

+ 1 - 0
pkg/models/stats.go

@@ -8,6 +8,7 @@ type SystemStats struct {
 	Orgs        int64
 	Playlists   int64
 	Alerts      int64
+	Stars       int64
 }
 
 type DataSourceStats struct {

+ 61 - 58
pkg/services/sqlstore/stats.go

@@ -30,31 +30,34 @@ func GetSystemStats(query *m.GetSystemStatsQuery) error {
 	var rawSql = `SELECT
 			(
 				SELECT COUNT(*)
-        FROM ` + dialect.Quote("user") + `
-      ) AS users,
+		FROM ` + dialect.Quote("user") + `
+	  ) AS users,
 			(
 				SELECT COUNT(*)
-        FROM ` + dialect.Quote("org") + `
-      ) AS orgs,
-      (
-        SELECT COUNT(*)
-        FROM ` + dialect.Quote("dashboard") + `
-      ) AS dashboards,
-			(
-        SELECT COUNT(*)
-        FROM ` + dialect.Quote("data_source") + `
-      ) AS datasources,
-      (
-        SELECT COUNT(*)
-        FROM ` + dialect.Quote("playlist") + `
-      ) AS playlists,
-      (
-        SELECT COUNT(*)
-        FROM ` + dialect.Quote("alert") + `
-      ) AS alerts,
+		FROM ` + dialect.Quote("org") + `
+	  ) AS orgs,
+	  (
+		SELECT COUNT(*)
+		FROM ` + dialect.Quote("dashboard") + `
+	  ) AS dashboards,
+		(
+		SELECT COUNT(*)
+		FROM ` + dialect.Quote("data_source") + `
+	  ) AS datasources,
+	  (
+		SELECT COUNT(*) FROM ` + dialect.Quote("star") + `
+	  ) AS stars,
+	  (
+		SELECT COUNT(*)
+		FROM ` + dialect.Quote("playlist") + `
+	  ) AS playlists,
+	  (
+		SELECT COUNT(*)
+		FROM ` + dialect.Quote("alert") + `
+	  ) AS alerts,
 			(
 				SELECT COUNT(*) FROM ` + dialect.Quote("user") + ` where last_seen_at > ?
-      ) as active_users
+	  ) as active_users
 			`
 
 	activeUserDeadlineDate := time.Now().Add(-activeUserTimeLimit)
@@ -70,46 +73,46 @@ func GetSystemStats(query *m.GetSystemStatsQuery) error {
 
 func GetAdminStats(query *m.GetAdminStatsQuery) error {
 	var rawSql = `SELECT
-      (
-        SELECT COUNT(*)
-        FROM ` + dialect.Quote("user") + `
-      ) AS users,
-      (
-        SELECT COUNT(*)
-        FROM ` + dialect.Quote("org") + `
-      ) AS orgs,
-      (
-        SELECT COUNT(*)
-        FROM ` + dialect.Quote("dashboard") + `
-      ) AS dashboards,
-      (
-        SELECT COUNT(*)
-        FROM ` + dialect.Quote("dashboard_snapshot") + `
-      ) AS snapshots,
-      (
-        SELECT COUNT( DISTINCT ( ` + dialect.Quote("term") + ` ))
-        FROM ` + dialect.Quote("dashboard_tag") + `
-      ) AS tags,
-      (
-        SELECT COUNT(*)
-        FROM ` + dialect.Quote("data_source") + `
-      ) AS datasources,
-      (
-        SELECT COUNT(*)
-        FROM ` + dialect.Quote("playlist") + `
-      ) AS playlists,
-      (
-        SELECT COUNT(*) FROM ` + dialect.Quote("star") + `
-      ) AS stars,
-      (
-        SELECT COUNT(*)
-        FROM ` + dialect.Quote("alert") + `
-      ) AS alerts,
+	  (
+		SELECT COUNT(*)
+		FROM ` + dialect.Quote("user") + `
+	  ) AS users,
+	  (
+		SELECT COUNT(*)
+		FROM ` + dialect.Quote("org") + `
+	  ) AS orgs,
+	  (
+		SELECT COUNT(*)
+		FROM ` + dialect.Quote("dashboard") + `
+	  ) AS dashboards,
+	  (
+		SELECT COUNT(*)
+		FROM ` + dialect.Quote("dashboard_snapshot") + `
+	  ) AS snapshots,
+	  (
+		SELECT COUNT( DISTINCT ( ` + dialect.Quote("term") + ` ))
+		FROM ` + dialect.Quote("dashboard_tag") + `
+	  ) AS tags,
+	  (
+		SELECT COUNT(*)
+		FROM ` + dialect.Quote("data_source") + `
+	  ) AS datasources,
+	  (
+		SELECT COUNT(*)
+		FROM ` + dialect.Quote("playlist") + `
+	  ) AS playlists,
+	  (
+		SELECT COUNT(*) FROM ` + dialect.Quote("star") + `
+	  ) AS stars,
+	  (
+		SELECT COUNT(*)
+		FROM ` + dialect.Quote("alert") + `
+	  ) AS alerts,
 			(
 				SELECT COUNT(*)
-        from ` + dialect.Quote("user") + ` where last_seen_at > ?
+		from ` + dialect.Quote("user") + ` where last_seen_at > ?
 			) as active_users
-      `
+	  `
 
 	activeUserDeadlineDate := time.Now().Add(-activeUserTimeLimit)