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

Signed-off-by: bergquist <carl.bergquist@gmail.com>
(cherry picked from commit 3188af9be3)
This commit is contained in:
Grot (@grafanabot)
2022-11-01 08:14:17 -04:00
committed by GitHub
parent 6c027ccf6a
commit ca73c43b56
2 changed files with 17 additions and 12 deletions
+1 -1
View File
@@ -175,7 +175,7 @@ func executeServer(configFile, homePath, pidFile, packaging string, traceDiagnos
setting.IsEnterprise = extensions.IsEnterprise
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()
if err != nil {
+16 -11
View File
@@ -177,9 +177,6 @@ var (
// StatsTotalDashboardVersions is a metric of total number of dashboard versions stored in Grafana.
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
// StatsTotalLibraryPanels is a metric of total number of library panels stored in Grafana.
@@ -497,12 +494,6 @@ func init() {
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",
Namespace: ExporterName,
}, []string{"version", "revision", "branch", "goversion", "edition"})
grafanaPluginBuildInfoDesc = 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",
@@ -571,13 +562,28 @@ func init() {
}
// SetBuildInformation sets the build information for this binary
func SetBuildInformation(version, revision, branch string) {
func SetBuildInformation(version, revision, branch string, buildTimestamp int64) {
edition := "oss"
if setting.IsEnterprise {
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)
grafanaBuildTimestamp.WithLabelValues(version, revision, branch, runtime.Version(), edition).Set(float64(buildTimestamp))
}
// SetEnvironmentInformation exposes environment values provided by the operators as an `_info` metric.
@@ -654,7 +660,6 @@ func initMetricVars() {
StatsTotalActiveEditors,
StatsTotalActiveAdmins,
StatsTotalDataSources,
grafanaBuildVersion,
grafanaPluginBuildInfoDesc,
StatsTotalDashboardVersions,
StatsTotalAnnotations,