expose metrics for the number of configured datasources (#24267)

pull/24353/head
Dan Cech 6 years ago committed by GitHub
parent 3451d09272
commit 66b7398fb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      pkg/infra/metrics/metrics.go
  2. 10
      pkg/infra/usagestats/usage_stats.go

@ -156,6 +156,9 @@ var (
// StatsTotalActiveAdmins is a metric total amount of active admins
StatsTotalActiveAdmins prometheus.Gauge
// StatsTotalDataSources is a metric total number of defined datasources, labeled by pluginId
StatsTotalDataSources *prometheus.GaugeVec
// grafanaBuildVersion is a metric with a constant '1' value labeled by version, revision, branch, and goversion from which Grafana was built
grafanaBuildVersion *prometheus.GaugeVec
@ -463,6 +466,12 @@ func init() {
Namespace: ExporterName,
})
StatsTotalDataSources = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "stat_totals_datasource",
Help: "total number of defined datasources, labeled by pluginId",
Namespace: ExporterName,
}, []string{"plugin_id"})
grafanaBuildVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "build_info",
Help: "A metric with a constant '1' value labeled by version, revision, branch, and goversion from which Grafana was built",
@ -538,6 +547,7 @@ func initMetricVars() {
StatsTotalActiveViewers,
StatsTotalActiveEditors,
StatsTotalActiveAdmins,
StatsTotalDataSources,
grafanaBuildVersion,
grafanPluginBuildInfoDesc,
)

@ -209,6 +209,16 @@ 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))
dsStats := models.GetDataSourceStatsQuery{}
if err := uss.Bus.Dispatch(&dsStats); err != nil {
metricsLogger.Error("Failed to get datasource stats", "error", err)
return
}
for _, dsStat := range dsStats.Result {
metrics.StatsTotalDataSources.WithLabelValues(dsStat.Type).Set(float64(dsStat.Count))
}
}
func getEdition() string {

Loading…
Cancel
Save