Backend Plugins: Collect and expose metrics and plugin process health check (#21481)

Adds support for collecting metrics from backend plugins and 
exposing them thru Grafana's Prometheus metrics endpoint. 
Enables to check health of backend plugin by using the route
`/api/plugins/<plugin id>/health`.
Uses sdk v0.6.0.

Closes #20984
This commit is contained in:
Marcus Efraimsson
2020-01-15 13:10:48 +01:00
committed by GitHub
parent f56f54b1a3
commit 5c711bfb79
34 changed files with 2406 additions and 623 deletions

View File

@ -148,6 +148,8 @@ var (
// grafanaBuildVersion is a metric with a constant '1' value labeled by version, revision, branch, and goversion from which Grafana was built
grafanaBuildVersion *prometheus.GaugeVec
grafanPluginBuildInfoDesc *prometheus.GaugeVec
)
func init() {
@ -422,6 +424,12 @@ func init() {
Help: "A metric with a constant '1' value labeled by version, revision, branch, and goversion from which Grafana was built",
Namespace: exporterName,
}, []string{"version", "revision", "branch", "goversion", "edition"})
grafanPluginBuildInfoDesc = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "plugin_build_info",
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"})
}
// SetBuildInformation sets the build information for this binary
@ -434,6 +442,10 @@ func SetBuildInformation(version, revision, branch string) {
grafanaBuildVersion.WithLabelValues(version, revision, branch, runtime.Version(), edition).Set(1)
}
func SetPluginBuildInformation(pluginID, pluginType, version string) {
grafanPluginBuildInfoDesc.WithLabelValues(pluginID, pluginType, version).Set(1)
}
func initMetricVars() {
prometheus.MustRegister(
MInstanceStart,
@ -480,6 +492,7 @@ func initMetricVars() {
StatsTotalActiveEditors,
StatsTotalActiveAdmins,
grafanaBuildVersion,
grafanPluginBuildInfoDesc,
)
}