diff --git a/pkg/infra/metrics/metrics.go b/pkg/infra/metrics/metrics.go index b84dbe1bcfa..cb81d98c7d0 100644 --- a/pkg/infra/metrics/metrics.go +++ b/pkg/infra/metrics/metrics.go @@ -175,6 +175,9 @@ var ( // StatsTotalAnnotations is a metric of total number of annotations stored in Grafana. StatsTotalAnnotations prometheus.Gauge + // StatsTotalAlertRules is a metric of total number of alert rules stored in Grafana. + StatsTotalAlertRules prometheus.Gauge + // StatsTotalDashboardVersions is a metric of total number of dashboard versions stored in Grafana. StatsTotalDashboardVersions prometheus.Gauge @@ -521,6 +524,12 @@ func init() { Namespace: ExporterName, }) + StatsTotalAlertRules = prometheus.NewGauge(prometheus.GaugeOpts{ + Name: "stat_totals_alert_rules", + Help: "total amount of alert rules in the database", + Namespace: ExporterName, + }) + MAccessPermissionsSummary = prometheus.NewHistogram(prometheus.HistogramOpts{ Name: "access_permissions_duration", Help: "Histogram for the runtime of permissions check function.", diff --git a/pkg/infra/usagestats/usage_stats.go b/pkg/infra/usagestats/usage_stats.go index a0ed8951110..d2e5c78879f 100644 --- a/pkg/infra/usagestats/usage_stats.go +++ b/pkg/infra/usagestats/usage_stats.go @@ -71,6 +71,7 @@ func (uss *UsageStatsService) GetUsageReport(ctx context.Context) (UsageReport, metrics["stats.total_auth_token.count"] = statsQuery.Result.AuthTokens metrics["stats.dashboard_versions.count"] = statsQuery.Result.DashboardVersions metrics["stats.annotations.count"] = statsQuery.Result.Annotations + metrics["stats.alert_rules.count"] = statsQuery.Result.AlertRules validLicCount := 0 if uss.License.HasValidLicense() { validLicCount = 1 @@ -315,6 +316,7 @@ func (uss *UsageStatsService) updateTotalStats() { metrics.StatsTotalActiveAdmins.Set(float64(statsQuery.Result.ActiveAdmins)) metrics.StatsTotalDashboardVersions.Set(float64(statsQuery.Result.DashboardVersions)) metrics.StatsTotalAnnotations.Set(float64(statsQuery.Result.Annotations)) + metrics.StatsTotalAlertRules.Set(float64(statsQuery.Result.AlertRules)) dsStats := models.GetDataSourceStatsQuery{} if err := uss.Bus.Dispatch(&dsStats); err != nil { diff --git a/pkg/infra/usagestats/usage_stats_test.go b/pkg/infra/usagestats/usage_stats_test.go index ca8e3f73ab4..4e068704256 100644 --- a/pkg/infra/usagestats/usage_stats_test.go +++ b/pkg/infra/usagestats/usage_stats_test.go @@ -62,6 +62,7 @@ func TestMetrics(t *testing.T) { AuthTokens: 15, DashboardVersions: 16, Annotations: 17, + AlertRules: 18, } getSystemStatsQuery = query return nil @@ -311,6 +312,7 @@ func TestMetrics(t *testing.T) { assert.Equal(t, 5, metrics.Get("stats.avg_auth_token_per_user.count").MustInt()) 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, 9, metrics.Get("stats.ds."+models.DS_ES+".count").MustInt()) assert.Equal(t, 10, metrics.Get("stats.ds."+models.DS_PROMETHEUS+".count").MustInt()) diff --git a/pkg/models/stats.go b/pkg/models/stats.go index c7877f069ec..640eb535d48 100644 --- a/pkg/models/stats.go +++ b/pkg/models/stats.go @@ -18,6 +18,7 @@ type SystemStats struct { AuthTokens int64 DashboardVersions int64 Annotations int64 + AlertRules int64 Admins int Editors int diff --git a/pkg/services/sqlstore/stats.go b/pkg/services/sqlstore/stats.go index 47ccb010086..b7341ab7d7f 100644 --- a/pkg/services/sqlstore/stats.go +++ b/pkg/services/sqlstore/stats.go @@ -79,6 +79,7 @@ func GetSystemStats(query *models.GetSystemStatsQuery) error { sb.Write(`(SELECT COUNT(id) FROM ` + dialect.Quote("annotation") + `) AS annotations,`) sb.Write(`(SELECT COUNT(id) FROM ` + dialect.Quote("team") + `) AS teams,`) sb.Write(`(SELECT COUNT(id) FROM ` + dialect.Quote("user_auth_token") + `) AS auth_tokens,`) + sb.Write(`(SELECT COUNT(id) FROM ` + dialect.Quote("alert_rule") + `) AS alert_rules,`) sb.Write(roleCounterSQL())