Commit 95c8766f by Carl Bergquist Committed by GitHub

Usagestats: Exclude folders from total dashboard count (#31320)

Signed-off-by: bergquist <carl.bergquist@gmail.com>
parent 0e63dfaf
...@@ -126,6 +126,9 @@ var ( ...@@ -126,6 +126,9 @@ var (
// MStatTotalDashboards is a metric total amount of dashboards // MStatTotalDashboards is a metric total amount of dashboards
MStatTotalDashboards prometheus.Gauge MStatTotalDashboards prometheus.Gauge
// MStatTotalDashboards is a metric total amount of dashboards
MStatTotalFolders prometheus.Gauge
// MStatTotalUsers is a metric total amount of users // MStatTotalUsers is a metric total amount of users
MStatTotalUsers prometheus.Gauge MStatTotalUsers prometheus.Gauge
...@@ -412,6 +415,12 @@ func init() { ...@@ -412,6 +415,12 @@ func init() {
Namespace: ExporterName, Namespace: ExporterName,
}) })
MStatTotalFolders = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_folder",
Help: "total amount of folders",
Namespace: ExporterName,
})
MStatTotalUsers = prometheus.NewGauge(prometheus.GaugeOpts{ MStatTotalUsers = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_total_users", Name: "stat_total_users",
Help: "total amount of users", Help: "total amount of users",
...@@ -575,6 +584,7 @@ func initMetricVars() { ...@@ -575,6 +584,7 @@ func initMetricVars() {
MRenderingQueue, MRenderingQueue,
MAlertingActiveAlerts, MAlertingActiveAlerts,
MStatTotalDashboards, MStatTotalDashboards,
MStatTotalFolders,
MStatTotalUsers, MStatTotalUsers,
MStatActiveUsers, MStatActiveUsers,
MStatTotalOrgs, MStatTotalOrgs,
......
...@@ -265,6 +265,7 @@ func (uss *UsageStatsService) updateTotalStats() { ...@@ -265,6 +265,7 @@ func (uss *UsageStatsService) updateTotalStats() {
} }
metrics.MStatTotalDashboards.Set(float64(statsQuery.Result.Dashboards)) metrics.MStatTotalDashboards.Set(float64(statsQuery.Result.Dashboards))
metrics.MStatTotalFolders.Set(float64(statsQuery.Result.Folders))
metrics.MStatTotalUsers.Set(float64(statsQuery.Result.Users)) metrics.MStatTotalUsers.Set(float64(statsQuery.Result.Users))
metrics.MStatActiveUsers.Set(float64(statsQuery.Result.ActiveUsers)) metrics.MStatActiveUsers.Set(float64(statsQuery.Result.ActiveUsers))
metrics.MStatTotalPlaylists.Set(float64(statsQuery.Result.Playlists)) metrics.MStatTotalPlaylists.Set(float64(statsQuery.Result.Playlists))
......
...@@ -46,7 +46,6 @@ func GetSystemStats(query *models.GetSystemStatsQuery) error { ...@@ -46,7 +46,6 @@ func GetSystemStats(query *models.GetSystemStatsQuery) error {
sb.Write("SELECT ") sb.Write("SELECT ")
sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("user") + `) AS users,`) sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("user") + `) AS users,`)
sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("org") + `) AS orgs,`) sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("org") + `) AS orgs,`)
sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("dashboard") + `) AS dashboards,`)
sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("data_source") + `) AS datasources,`) sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("data_source") + `) AS datasources,`)
sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("star") + `) AS stars,`) sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("star") + `) AS stars,`)
sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("playlist") + `) AS playlists,`) sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("playlist") + `) AS playlists,`)
...@@ -55,6 +54,7 @@ func GetSystemStats(query *models.GetSystemStatsQuery) error { ...@@ -55,6 +54,7 @@ func GetSystemStats(query *models.GetSystemStatsQuery) error {
activeUserDeadlineDate := time.Now().Add(-activeUserTimeLimit) activeUserDeadlineDate := time.Now().Add(-activeUserTimeLimit)
sb.Write(`(SELECT COUNT(*) FROM `+dialect.Quote("user")+` WHERE last_seen_at > ?) AS active_users,`, activeUserDeadlineDate) sb.Write(`(SELECT COUNT(*) FROM `+dialect.Quote("user")+` WHERE last_seen_at > ?) AS active_users,`, activeUserDeadlineDate)
sb.Write(`(SELECT COUNT(id) FROM `+dialect.Quote("dashboard")+` WHERE is_folder = ?) AS dashboards,`, dialect.BooleanStr(false))
sb.Write(`(SELECT COUNT(id) FROM `+dialect.Quote("dashboard")+` WHERE is_folder = ?) AS folders,`, dialect.BooleanStr(true)) sb.Write(`(SELECT COUNT(id) FROM `+dialect.Quote("dashboard")+` WHERE is_folder = ?) AS folders,`, dialect.BooleanStr(true))
sb.Write(`( sb.Write(`(
...@@ -119,7 +119,7 @@ func GetAdminStats(query *models.GetAdminStatsQuery) error { ...@@ -119,7 +119,7 @@ func GetAdminStats(query *models.GetAdminStatsQuery) error {
) AS orgs, ) AS orgs,
( (
SELECT COUNT(*) SELECT COUNT(*)
FROM ` + dialect.Quote("dashboard") + ` FROM ` + dialect.Quote("dashboard") + `WHERE is_folder=` + dialect.BooleanStr(false) + `
) AS dashboards, ) AS dashboards,
( (
SELECT COUNT(*) SELECT COUNT(*)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment