Commit 66b7398f by Dan Cech Committed by GitHub

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

parent 3451d092
......@@ -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 {
......
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