stats: send amount of stars as stats

This commit is contained in:
bergquist 2018-01-23 22:51:05 +01:00
parent ea988a37dd
commit ee973a977b
3 changed files with 63 additions and 58 deletions

View File

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

View File

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

View File

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