metrics: expose when the binary was built as an gauge (#57951)

Signed-off-by: bergquist <carl.bergquist@gmail.com>
This commit is contained in:
Carl Bergquist 2022-11-01 13:00:47 +01:00 committed by GitHub
parent cff6d1cf8b
commit 3188af9be3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 12 deletions

View File

@ -175,7 +175,7 @@ func executeServer(configFile, homePath, pidFile, packaging string, traceDiagnos
setting.IsEnterprise = extensions.IsEnterprise setting.IsEnterprise = extensions.IsEnterprise
setting.Packaging = validPackaging(packaging) setting.Packaging = validPackaging(packaging)
metrics.SetBuildInformation(opt.Version, opt.Commit, opt.BuildBranch) metrics.SetBuildInformation(opt.Version, opt.Commit, opt.BuildBranch, buildstampInt64)
elevated, err := process.IsRunningWithElevatedPrivileges() elevated, err := process.IsRunningWithElevatedPrivileges()
if err != nil { if err != nil {

View File

@ -181,9 +181,6 @@ var (
// StatsTotalDashboardVersions is a metric of total number of dashboard versions stored in Grafana. // StatsTotalDashboardVersions is a metric of total number of dashboard versions stored in Grafana.
StatsTotalDashboardVersions prometheus.Gauge 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
grafanaPluginBuildInfoDesc *prometheus.GaugeVec grafanaPluginBuildInfoDesc *prometheus.GaugeVec
// StatsTotalLibraryPanels is a metric of total number of library panels stored in Grafana. // StatsTotalLibraryPanels is a metric of total number of library panels stored in Grafana.
@ -507,12 +504,6 @@ func init() {
Namespace: ExporterName, Namespace: ExporterName,
}, []string{"plugin_id"}) }, []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",
Namespace: ExporterName,
}, []string{"version", "revision", "branch", "goversion", "edition"})
grafanaPluginBuildInfoDesc = prometheus.NewGaugeVec(prometheus.GaugeOpts{ grafanaPluginBuildInfoDesc = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "plugin_build_info", Name: "plugin_build_info",
Help: "A metric with a constant '1' value labeled by pluginId, pluginType and version from which Grafana plugin was built", Help: "A metric with a constant '1' value labeled by pluginId, pluginType and version from which Grafana plugin was built",
@ -581,13 +572,28 @@ func init() {
} }
// SetBuildInformation sets the build information for this binary // SetBuildInformation sets the build information for this binary
func SetBuildInformation(version, revision, branch string) { func SetBuildInformation(version, revision, branch string, buildTimestamp int64) {
edition := "oss" edition := "oss"
if setting.IsEnterprise { if setting.IsEnterprise {
edition = "enterprise" edition = "enterprise"
} }
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",
Namespace: ExporterName,
}, []string{"version", "revision", "branch", "goversion", "edition"})
grafanaBuildTimestamp := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "build_timestamp",
Help: "A metric exposing when the binary was built in epoch",
Namespace: ExporterName,
}, []string{"version", "revision", "branch", "goversion", "edition"})
prometheus.MustRegister(grafanaBuildVersion, grafanaBuildTimestamp)
grafanaBuildVersion.WithLabelValues(version, revision, branch, runtime.Version(), edition).Set(1) grafanaBuildVersion.WithLabelValues(version, revision, branch, runtime.Version(), edition).Set(1)
grafanaBuildTimestamp.WithLabelValues(version, revision, branch, runtime.Version(), edition).Set(float64(buildTimestamp))
} }
// SetEnvironmentInformation exposes environment values provided by the operators as an `_info` metric. // SetEnvironmentInformation exposes environment values provided by the operators as an `_info` metric.
@ -664,7 +670,6 @@ func initMetricVars() {
StatsTotalActiveEditors, StatsTotalActiveEditors,
StatsTotalActiveAdmins, StatsTotalActiveAdmins,
StatsTotalDataSources, StatsTotalDataSources,
grafanaBuildVersion,
grafanaPluginBuildInfoDesc, grafanaPluginBuildInfoDesc,
StatsTotalDashboardVersions, StatsTotalDashboardVersions,
StatsTotalAnnotations, StatsTotalAnnotations,