mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: a usage stat for ualerting (#34390)
collects `stats.alert_rules.count` , where alert_rules is the nextgen system
This commit is contained in:
parent
559ce4db89
commit
e291203528
@ -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.",
|
||||
|
@ -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 {
|
||||
|
@ -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())
|
||||
|
@ -18,6 +18,7 @@ type SystemStats struct {
|
||||
AuthTokens int64
|
||||
DashboardVersions int64
|
||||
Annotations int64
|
||||
AlertRules int64
|
||||
|
||||
Admins int
|
||||
Editors int
|
||||
|
@ -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())
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user