Commit 26852ca7 by Carl Bergquist Committed by GitHub

Instrument dashboard versions and annotation count (#26044)

parent 081f954a
...@@ -159,6 +159,12 @@ var ( ...@@ -159,6 +159,12 @@ var (
// StatsTotalDataSources is a metric total number of defined datasources, labeled by pluginId // StatsTotalDataSources is a metric total number of defined datasources, labeled by pluginId
StatsTotalDataSources *prometheus.GaugeVec StatsTotalDataSources *prometheus.GaugeVec
// StatsTotalAnnotations is a metric of total number of annotations stored in Grafana.
StatsTotalAnnotations prometheus.Gauge
// StatsTotalDashboardVersions is a metric of total number of dashboard versions stored in Grafana.
StatsTotalDashboardVersions prometheus.Gauge
// grafanaBuildVersion is a metric with a constant '1' value labeled by version, revision, branch, and goversion from which Grafana was built // grafanaBuildVersion is a metric with a constant '1' value labeled by version, revision, branch, and goversion from which Grafana was built
grafanaBuildVersion *prometheus.GaugeVec grafanaBuildVersion *prometheus.GaugeVec
...@@ -483,6 +489,18 @@ func init() { ...@@ -483,6 +489,18 @@ func init() {
Help: "A metric with a constant '1' value labeled by pluginId, pluginType and version from which Grafana plugin was built", Help: "A metric with a constant '1' value labeled by pluginId, pluginType and version from which Grafana plugin was built",
Namespace: ExporterName, Namespace: ExporterName,
}, []string{"plugin_id", "plugin_type", "version"}) }, []string{"plugin_id", "plugin_type", "version"})
StatsTotalDashboardVersions = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_dashboard_versions",
Help: "total amount of dashboard versions in the database",
Namespace: ExporterName,
})
StatsTotalAnnotations = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "stat_totals_annotations",
Help: "total amount of annotations in the database",
Namespace: ExporterName,
})
} }
// SetBuildInformation sets the build information for this binary // SetBuildInformation sets the build information for this binary
...@@ -550,6 +568,8 @@ func initMetricVars() { ...@@ -550,6 +568,8 @@ func initMetricVars() {
StatsTotalDataSources, StatsTotalDataSources,
grafanaBuildVersion, grafanaBuildVersion,
grafanaPluginBuildInfoDesc, grafanaPluginBuildInfoDesc,
StatsTotalDashboardVersions,
StatsTotalAnnotations,
) )
} }
......
...@@ -61,6 +61,8 @@ func (uss *UsageStatsService) sendUsageStats(oauthProviders map[string]bool) { ...@@ -61,6 +61,8 @@ func (uss *UsageStatsService) sendUsageStats(oauthProviders map[string]bool) {
metrics["stats.snapshots.count"] = statsQuery.Result.Snapshots metrics["stats.snapshots.count"] = statsQuery.Result.Snapshots
metrics["stats.teams.count"] = statsQuery.Result.Teams metrics["stats.teams.count"] = statsQuery.Result.Teams
metrics["stats.total_auth_token.count"] = statsQuery.Result.AuthTokens 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.valid_license.count"] = getValidLicenseCount(uss.License.HasValidLicense()) metrics["stats.valid_license.count"] = getValidLicenseCount(uss.License.HasValidLicense())
metrics["stats.edition.oss.count"] = getOssEditionCount() metrics["stats.edition.oss.count"] = getOssEditionCount()
metrics["stats.edition.enterprise.count"] = getEnterpriseEditionCount() metrics["stats.edition.enterprise.count"] = getEnterpriseEditionCount()
...@@ -212,6 +214,8 @@ func (uss *UsageStatsService) updateTotalStats() { ...@@ -212,6 +214,8 @@ func (uss *UsageStatsService) updateTotalStats() {
metrics.StatsTotalActiveEditors.Set(float64(statsQuery.Result.ActiveEditors)) metrics.StatsTotalActiveEditors.Set(float64(statsQuery.Result.ActiveEditors))
metrics.StatsTotalAdmins.Set(float64(statsQuery.Result.Admins)) metrics.StatsTotalAdmins.Set(float64(statsQuery.Result.Admins))
metrics.StatsTotalActiveAdmins.Set(float64(statsQuery.Result.ActiveAdmins)) metrics.StatsTotalActiveAdmins.Set(float64(statsQuery.Result.ActiveAdmins))
metrics.StatsTotalDashboardVersions.Set(float64(statsQuery.Result.DashboardVersions))
metrics.StatsTotalAnnotations.Set(float64(statsQuery.Result.Annotations))
dsStats := models.GetDataSourceStatsQuery{} dsStats := models.GetDataSourceStatsQuery{}
if err := uss.Bus.Dispatch(&dsStats); err != nil { if err := uss.Bus.Dispatch(&dsStats); err != nil {
......
...@@ -50,6 +50,8 @@ func TestMetrics(t *testing.T) { ...@@ -50,6 +50,8 @@ func TestMetrics(t *testing.T) {
Snapshots: 13, Snapshots: 13,
Teams: 14, Teams: 14,
AuthTokens: 15, AuthTokens: 15,
DashboardVersions: 16,
Annotations: 17,
} }
getSystemStatsQuery = query getSystemStatsQuery = query
return nil return nil
...@@ -238,6 +240,8 @@ func TestMetrics(t *testing.T) { ...@@ -238,6 +240,8 @@ func TestMetrics(t *testing.T) {
So(metrics.Get("stats.teams.count").MustInt(), ShouldEqual, getSystemStatsQuery.Result.Teams) So(metrics.Get("stats.teams.count").MustInt(), ShouldEqual, getSystemStatsQuery.Result.Teams)
So(metrics.Get("stats.total_auth_token.count").MustInt64(), ShouldEqual, 15) So(metrics.Get("stats.total_auth_token.count").MustInt64(), ShouldEqual, 15)
So(metrics.Get("stats.avg_auth_token_per_user.count").MustInt64(), ShouldEqual, 5) So(metrics.Get("stats.avg_auth_token_per_user.count").MustInt64(), ShouldEqual, 5)
So(metrics.Get("stats.dashboard_versions.count").MustInt64(), ShouldEqual, 16)
So(metrics.Get("stats.annotations.count").MustInt64(), ShouldEqual, 17)
So(metrics.Get("stats.ds."+models.DS_ES+".count").MustInt(), ShouldEqual, 9) So(metrics.Get("stats.ds."+models.DS_ES+".count").MustInt(), ShouldEqual, 9)
So(metrics.Get("stats.ds."+models.DS_PROMETHEUS+".count").MustInt(), ShouldEqual, 10) So(metrics.Get("stats.ds."+models.DS_PROMETHEUS+".count").MustInt(), ShouldEqual, 10)
......
...@@ -16,6 +16,8 @@ type SystemStats struct { ...@@ -16,6 +16,8 @@ type SystemStats struct {
Folders int64 Folders int64
ProvisionedDashboards int64 ProvisionedDashboards int64
AuthTokens int64 AuthTokens int64
DashboardVersions int64
Annotations int64
Admins int Admins int
Editors int Editors int
......
...@@ -75,6 +75,8 @@ func GetSystemStats(query *models.GetSystemStatsQuery) error { ...@@ -75,6 +75,8 @@ func GetSystemStats(query *models.GetSystemStatsQuery) error {
sb.Write(`(SELECT COUNT(id) FROM ` + dialect.Quote("dashboard_provisioning") + `) AS provisioned_dashboards,`) sb.Write(`(SELECT COUNT(id) FROM ` + dialect.Quote("dashboard_provisioning") + `) AS provisioned_dashboards,`)
sb.Write(`(SELECT COUNT(id) FROM ` + dialect.Quote("dashboard_snapshot") + `) AS snapshots,`) sb.Write(`(SELECT COUNT(id) FROM ` + dialect.Quote("dashboard_snapshot") + `) AS snapshots,`)
sb.Write(`(SELECT COUNT(id) FROM ` + dialect.Quote("dashboard_version") + `) AS dashboard_versions,`)
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("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("user_auth_token") + `) AS auth_tokens,`)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment