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

Signed-off-by: bergquist <carl.bergquist@gmail.com>
This commit is contained in:
Carl Bergquist 2021-02-18 15:32:47 +01:00 committed by GitHub
parent 0e63dfafbe
commit 95c8766f86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -126,6 +126,9 @@ var (
// MStatTotalDashboards is a metric total amount of dashboards
MStatTotalDashboards prometheus.Gauge
// MStatTotalDashboards is a metric total amount of dashboards
MStatTotalFolders prometheus.Gauge
// MStatTotalUsers is a metric total amount of users
MStatTotalUsers prometheus.Gauge
@ -412,6 +415,12 @@ func init() {
Namespace: ExporterName,
})
MStatTotalFolders = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_folder",
Help: "total amount of folders",
Namespace: ExporterName,
})
MStatTotalUsers = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_total_users",
Help: "total amount of users",
@ -575,6 +584,7 @@ func initMetricVars() {
MRenderingQueue,
MAlertingActiveAlerts,
MStatTotalDashboards,
MStatTotalFolders,
MStatTotalUsers,
MStatActiveUsers,
MStatTotalOrgs,

View File

@ -265,6 +265,7 @@ func (uss *UsageStatsService) updateTotalStats() {
}
metrics.MStatTotalDashboards.Set(float64(statsQuery.Result.Dashboards))
metrics.MStatTotalFolders.Set(float64(statsQuery.Result.Folders))
metrics.MStatTotalUsers.Set(float64(statsQuery.Result.Users))
metrics.MStatActiveUsers.Set(float64(statsQuery.Result.ActiveUsers))
metrics.MStatTotalPlaylists.Set(float64(statsQuery.Result.Playlists))

View File

@ -46,7 +46,6 @@ func GetSystemStats(query *models.GetSystemStatsQuery) error {
sb.Write("SELECT ")
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("dashboard") + `) AS dashboards,`)
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("playlist") + `) AS playlists,`)
@ -55,6 +54,7 @@ func GetSystemStats(query *models.GetSystemStatsQuery) error {
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(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(`(
@ -119,7 +119,7 @@ func GetAdminStats(query *models.GetAdminStatsQuery) error {
) AS orgs,
(
SELECT COUNT(*)
FROM ` + dialect.Quote("dashboard") + `
FROM ` + dialect.Quote("dashboard") + `WHERE is_folder=` + dialect.BooleanStr(false) + `
) AS dashboards,
(
SELECT COUNT(*)