PublicDashboards: collect stats for public dashboards (#50553)

* PublicDashboards: collect stats for public dashboards
This commit is contained in:
Ezequiel Victorero 2022-06-23 12:02:57 -03:00 committed by GitHub
parent eceb21e72d
commit 4c4d6fd425
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 0 deletions

View File

@ -187,6 +187,9 @@ var (
// StatsTotalDataKeys is a metric of total number of data keys stored in Grafana.
StatsTotalDataKeys *prometheus.GaugeVec
// MStatTotalPublicDashboards is a metric total amount of public dashboards
MStatTotalPublicDashboards prometheus.Gauge
)
func init() {
@ -550,6 +553,12 @@ func init() {
Help: "total amount of data keys in the database",
Namespace: ExporterName,
}, []string{"active"})
MStatTotalPublicDashboards = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_public_dashboard",
Help: "total amount of public dashboards",
Namespace: ExporterName,
})
}
// SetBuildInformation sets the build information for this binary
@ -644,5 +653,6 @@ func initMetricVars() {
StatsTotalLibraryPanels,
StatsTotalLibraryVariables,
StatsTotalDataKeys,
MStatTotalPublicDashboards,
)
}

View File

@ -154,6 +154,7 @@ func (s *Service) collectSystemStats(ctx context.Context) (map[string]interface{
m["stats.api_keys.count"] = statsQuery.Result.APIKeys
m["stats.data_keys.count"] = statsQuery.Result.DataKeys
m["stats.active_data_keys.count"] = statsQuery.Result.ActiveDataKeys
m["stats.public_dashboards.count"] = statsQuery.Result.PublicDashboards
ossEditionCount := 1
enterpriseEditionCount := 0
@ -344,6 +345,8 @@ func (s *Service) updateTotalStats(ctx context.Context) bool {
inactiveDataKeys := statsQuery.Result.DataKeys - statsQuery.Result.ActiveDataKeys
metrics.StatsTotalDataKeys.With(prometheus.Labels{"active": "false"}).Set(float64(inactiveDataKeys))
metrics.MStatTotalPublicDashboards.Set(float64(statsQuery.Result.PublicDashboards))
dsStats := models.GetDataSourceStatsQuery{}
if err := s.sqlstore.GetDataSourceStats(ctx, &dsStats); err != nil {
s.log.Error("Failed to get datasource stats", "error", err)

View File

@ -177,6 +177,7 @@ func TestCollectingUsageStats(t *testing.T) {
assert.EqualValues(t, 11, metrics["stats.data_keys.count"])
assert.EqualValues(t, 3, metrics["stats.active_data_keys.count"])
assert.EqualValues(t, 5, metrics["stats.public_dashboards.count"])
assert.InDelta(t, int64(65), metrics["stats.uptime"], 6)
}
@ -351,6 +352,7 @@ func mockSystemStats(sqlStore *mockstore.SQLStoreMock) {
APIKeys: 2,
DataKeys: 11,
ActiveDataKeys: 3,
PublicDashboards: 5,
}
}

View File

@ -41,6 +41,7 @@ type SystemStats struct {
DailyActiveSessions int64
DataKeys int64
ActiveDataKeys int64
PublicDashboards int64
}
type DataSourceStats struct {

View File

@ -105,6 +105,9 @@ func (ss *SQLStore) GetSystemStats(ctx context.Context, query *models.GetSystemS
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,`)
// TODO: table name will change and filter should check only for is_enabled = true
sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("dashboard_public") + `WHERE is_enabled = true) AS public_dashboards,`)
sb.Write(ss.roleCounterSQL(ctx))
var stats models.SystemStats