* LibraryPanels: Adds usage collection
* Refactor: renames Panel and Variable consts
* Chore: initialize stats
* Refactor: moves library element migrations to migration namespace
(cherry picked from commit 7204a64717)
Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com>
This commit is contained in:
co-authored by
Hugo Häggmark
parent
34a1621a5c
commit
7f919c0e55
@@ -185,6 +185,12 @@ var (
|
||||
grafanaBuildVersion *prometheus.GaugeVec
|
||||
|
||||
grafanaPluginBuildInfoDesc *prometheus.GaugeVec
|
||||
|
||||
// StatsTotalLibraryPanels is a metric of total number of library panels stored in Grafana.
|
||||
StatsTotalLibraryPanels prometheus.Gauge
|
||||
|
||||
// StatsTotalLibraryVariables is a metric of total number of library variables stored in Grafana.
|
||||
StatsTotalLibraryVariables prometheus.Gauge
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -547,6 +553,18 @@ func init() {
|
||||
Help: "number of evaluation calls",
|
||||
Namespace: ExporterName,
|
||||
})
|
||||
|
||||
StatsTotalLibraryPanels = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "stat_totals_library_panels",
|
||||
Help: "total amount of library panels in the database",
|
||||
Namespace: ExporterName,
|
||||
})
|
||||
|
||||
StatsTotalLibraryVariables = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "stat_totals_library_variables",
|
||||
Help: "total amount of library variables in the database",
|
||||
Namespace: ExporterName,
|
||||
})
|
||||
}
|
||||
|
||||
// SetBuildInformation sets the build information for this binary
|
||||
@@ -640,6 +658,8 @@ func initMetricVars() {
|
||||
StatsTotalDashboardVersions,
|
||||
StatsTotalAnnotations,
|
||||
MAccessEvaluationCount,
|
||||
StatsTotalLibraryPanels,
|
||||
StatsTotalLibraryVariables,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,8 @@ func (uss *UsageStatsService) GetUsageReport(ctx context.Context) (UsageReport,
|
||||
metrics["stats.dashboard_versions.count"] = statsQuery.Result.DashboardVersions
|
||||
metrics["stats.annotations.count"] = statsQuery.Result.Annotations
|
||||
metrics["stats.alert_rules.count"] = statsQuery.Result.AlertRules
|
||||
metrics["stats.library_panels.count"] = statsQuery.Result.LibraryPanels
|
||||
metrics["stats.library_variables.count"] = statsQuery.Result.LibraryVariables
|
||||
validLicCount := 0
|
||||
if uss.License.HasValidLicense() {
|
||||
validLicCount = 1
|
||||
@@ -317,6 +319,8 @@ func (uss *UsageStatsService) updateTotalStats() {
|
||||
metrics.StatsTotalDashboardVersions.Set(float64(statsQuery.Result.DashboardVersions))
|
||||
metrics.StatsTotalAnnotations.Set(float64(statsQuery.Result.Annotations))
|
||||
metrics.StatsTotalAlertRules.Set(float64(statsQuery.Result.AlertRules))
|
||||
metrics.StatsTotalLibraryPanels.Set(float64(statsQuery.Result.LibraryPanels))
|
||||
metrics.StatsTotalLibraryVariables.Set(float64(statsQuery.Result.LibraryVariables))
|
||||
|
||||
dsStats := models.GetDataSourceStatsQuery{}
|
||||
if err := uss.Bus.Dispatch(&dsStats); err != nil {
|
||||
|
||||
@@ -63,6 +63,8 @@ func TestMetrics(t *testing.T) {
|
||||
DashboardVersions: 16,
|
||||
Annotations: 17,
|
||||
AlertRules: 18,
|
||||
LibraryPanels: 19,
|
||||
LibraryVariables: 20,
|
||||
}
|
||||
getSystemStatsQuery = query
|
||||
return nil
|
||||
@@ -313,6 +315,8 @@ func TestMetrics(t *testing.T) {
|
||||
assert.Equal(t, 16, metrics.Get("stats.dashboard_versions.count").MustInt())
|
||||
assert.Equal(t, 17, metrics.Get("stats.annotations.count").MustInt())
|
||||
assert.Equal(t, 18, metrics.Get("stats.alert_rules.count").MustInt())
|
||||
assert.Equal(t, 19, metrics.Get("stats.library_panels.count").MustInt())
|
||||
assert.Equal(t, 20, metrics.Get("stats.library_variables.count").MustInt())
|
||||
|
||||
assert.Equal(t, 9, metrics.Get("stats.ds."+models.DS_ES+".count").MustInt())
|
||||
assert.Equal(t, 10, metrics.Get("stats.ds."+models.DS_PROMETHEUS+".count").MustInt())
|
||||
|
||||
Reference in New Issue
Block a user