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

This commit is contained in:
Dan Cech
2020-05-06 11:36:18 -04:00
committed by GitHub
parent 3451d09272
commit 66b7398fb6
2 changed files with 20 additions and 0 deletions

View File

@@ -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,
)

View File

@@ -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 {