Instrument dashboard versions and annotation count (#26044)

This commit is contained in:
Carl Bergquist 2020-07-03 15:47:46 +02:00 committed by GitHub
parent 081f954a2b
commit 26852ca788
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 0 deletions

View File

@ -159,6 +159,12 @@ var (
// StatsTotalDataSources is a metric total number of defined datasources, labeled by pluginId
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 *prometheus.GaugeVec
@ -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",
Namespace: ExporterName,
}, []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
@ -550,6 +568,8 @@ func initMetricVars() {
StatsTotalDataSources,
grafanaBuildVersion,
grafanaPluginBuildInfoDesc,
StatsTotalDashboardVersions,
StatsTotalAnnotations,
)
}

View File

@ -61,6 +61,8 @@ func (uss *UsageStatsService) sendUsageStats(oauthProviders map[string]bool) {
metrics["stats.snapshots.count"] = statsQuery.Result.Snapshots
metrics["stats.teams.count"] = statsQuery.Result.Teams
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.edition.oss.count"] = getOssEditionCount()
metrics["stats.edition.enterprise.count"] = getEnterpriseEditionCount()
@ -212,6 +214,8 @@ func (uss *UsageStatsService) updateTotalStats() {
metrics.StatsTotalActiveEditors.Set(float64(statsQuery.Result.ActiveEditors))
metrics.StatsTotalAdmins.Set(float64(statsQuery.Result.Admins))
metrics.StatsTotalActiveAdmins.Set(float64(statsQuery.Result.ActiveAdmins))
metrics.StatsTotalDashboardVersions.Set(float64(statsQuery.Result.DashboardVersions))
metrics.StatsTotalAnnotations.Set(float64(statsQuery.Result.Annotations))
dsStats := models.GetDataSourceStatsQuery{}
if err := uss.Bus.Dispatch(&dsStats); err != nil {

View File

@ -50,6 +50,8 @@ func TestMetrics(t *testing.T) {
Snapshots: 13,
Teams: 14,
AuthTokens: 15,
DashboardVersions: 16,
Annotations: 17,
}
getSystemStatsQuery = query
return nil
@ -238,6 +240,8 @@ func TestMetrics(t *testing.T) {
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.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_PROMETHEUS+".count").MustInt(), ShouldEqual, 10)

View File

@ -16,6 +16,8 @@ type SystemStats struct {
Folders int64
ProvisionedDashboards int64
AuthTokens int64
DashboardVersions int64
Annotations int64
Admins int
Editors int

View File

@ -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_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("user_auth_token") + `) AS auth_tokens,`)