Usagestats: Add stat group for alert rule groups (#78825)

* Add rule group support to usagestats service

* Quote column name
This commit is contained in:
Alexander Weaver 2023-11-29 14:37:36 -06:00 committed by GitHub
parent a50be7ea0a
commit 8a56a94781
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 0 deletions

View File

@ -185,6 +185,9 @@ var (
// StatsTotalAlertRules is a metric of total number of alert rules stored in Grafana. // StatsTotalAlertRules is a metric of total number of alert rules stored in Grafana.
StatsTotalAlertRules prometheus.Gauge StatsTotalAlertRules prometheus.Gauge
// StatsTotalRuleGroups is a metric of total number of alert rule groups stored in Grafana.
StatsTotalRuleGroups prometheus.Gauge
// StatsTotalDashboardVersions is a metric of total number of dashboard versions stored in Grafana. // StatsTotalDashboardVersions is a metric of total number of dashboard versions stored in Grafana.
StatsTotalDashboardVersions prometheus.Gauge StatsTotalDashboardVersions prometheus.Gauge
@ -554,6 +557,12 @@ func init() {
Namespace: ExporterName, Namespace: ExporterName,
}) })
StatsTotalRuleGroups = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_rule_groups",
Help: "total amount of alert rule groups in the database",
Namespace: ExporterName,
})
MAccessPermissionsSummary = prometheus.NewHistogram(prometheus.HistogramOpts{ MAccessPermissionsSummary = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "access_permissions_duration", Name: "access_permissions_duration",
Help: "Histogram for the runtime of permissions check function.", Help: "Histogram for the runtime of permissions check function.",
@ -708,6 +717,7 @@ func initMetricVars() {
StatsTotalDashboardVersions, StatsTotalDashboardVersions,
StatsTotalAnnotations, StatsTotalAnnotations,
StatsTotalAlertRules, StatsTotalAlertRules,
StatsTotalRuleGroups,
MAccessEvaluationCount, MAccessEvaluationCount,
StatsTotalLibraryPanels, StatsTotalLibraryPanels,
StatsTotalLibraryVariables, StatsTotalLibraryVariables,

View File

@ -164,6 +164,7 @@ func (s *Service) collectSystemStats(ctx context.Context) (map[string]any, error
m["stats.dashboard_versions.count"] = statsResult.DashboardVersions m["stats.dashboard_versions.count"] = statsResult.DashboardVersions
m["stats.annotations.count"] = statsResult.Annotations m["stats.annotations.count"] = statsResult.Annotations
m["stats.alert_rules.count"] = statsResult.AlertRules m["stats.alert_rules.count"] = statsResult.AlertRules
m["stats.rule_groups.count"] = statsResult.RuleGroups
m["stats.library_panels.count"] = statsResult.LibraryPanels m["stats.library_panels.count"] = statsResult.LibraryPanels
m["stats.library_variables.count"] = statsResult.LibraryVariables m["stats.library_variables.count"] = statsResult.LibraryVariables
m["stats.dashboards_viewers_can_edit.count"] = statsResult.DashboardsViewersCanEdit m["stats.dashboards_viewers_can_edit.count"] = statsResult.DashboardsViewersCanEdit
@ -328,6 +329,7 @@ func (s *Service) updateTotalStats(ctx context.Context) bool {
metrics.StatsTotalDashboardVersions.Set(float64(statsResult.DashboardVersions)) metrics.StatsTotalDashboardVersions.Set(float64(statsResult.DashboardVersions))
metrics.StatsTotalAnnotations.Set(float64(statsResult.Annotations)) metrics.StatsTotalAnnotations.Set(float64(statsResult.Annotations))
metrics.StatsTotalAlertRules.Set(float64(statsResult.AlertRules)) metrics.StatsTotalAlertRules.Set(float64(statsResult.AlertRules))
metrics.StatsTotalRuleGroups.Set(float64(statsResult.RuleGroups))
metrics.StatsTotalLibraryPanels.Set(float64(statsResult.LibraryPanels)) metrics.StatsTotalLibraryPanels.Set(float64(statsResult.LibraryPanels))
metrics.StatsTotalLibraryVariables.Set(float64(statsResult.LibraryVariables)) metrics.StatsTotalLibraryVariables.Set(float64(statsResult.LibraryVariables))

View File

@ -26,6 +26,7 @@ type SystemStats struct {
DashboardVersions int64 DashboardVersions int64
Annotations int64 Annotations int64
AlertRules int64 AlertRules int64
RuleGroups int64
LibraryPanels int64 LibraryPanels int64
LibraryVariables int64 LibraryVariables int64
DashboardsViewersCanEdit int64 DashboardsViewersCanEdit int64

View File

@ -128,6 +128,9 @@ func (ss *sqlStatsService) GetSystemStats(ctx context.Context, query *stats.GetS
sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("data_keys") + `WHERE active = true) AS active_data_keys,`) sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("data_keys") + `WHERE active = true) AS active_data_keys,`)
sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("dashboard_public") + `) AS public_dashboards,`) sb.Write(`(SELECT COUNT(*) FROM ` + dialect.Quote("dashboard_public") + `) AS public_dashboards,`)
sb.Write(`(SELECT MIN(timestamp) FROM ` + dialect.Quote("migration_log") + `) AS database_created_time,`) sb.Write(`(SELECT MIN(timestamp) FROM ` + dialect.Quote("migration_log") + `) AS database_created_time,`)
if ss.IsUnifiedAlertingEnabled() {
sb.Write(`(SELECT COUNT(DISTINCT (` + dialect.Quote("rule_group") + `)) FROM ` + dialect.Quote("alert_rule") + `) AS rule_groups,`)
}
sb.Write(ss.roleCounterSQL(ctx)) sb.Write(ss.roleCounterSQL(ctx))