mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 09:26:43 -06:00
PublicDashboards: collect stats for public dashboards (#50553)
* PublicDashboards: collect stats for public dashboards
This commit is contained in:
parent
eceb21e72d
commit
4c4d6fd425
@ -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,
|
||||
)
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ type SystemStats struct {
|
||||
DailyActiveSessions int64
|
||||
DataKeys int64
|
||||
ActiveDataKeys int64
|
||||
PublicDashboards int64
|
||||
}
|
||||
|
||||
type DataSourceStats struct {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user