From 509185dfbe9d79921a79863378533f7dcefd007b Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Thu, 11 Jun 2020 16:32:54 +0200 Subject: [PATCH] prometheus: expose zrepl version as const metric --- daemon/daemon.go | 1 + version/version.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/daemon/daemon.go b/daemon/daemon.go index 4c354af..f6a90bc 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -95,6 +95,7 @@ func Run(ctx context.Context, conf *config.Config) error { } // register global (=non job-local) metrics + version.PrometheusRegister(prometheus.DefaultRegisterer) zfscmd.RegisterMetrics(prometheus.DefaultRegisterer) trace.RegisterMetrics(prometheus.DefaultRegisterer) endpoint.RegisterMetrics(prometheus.DefaultRegisterer) diff --git a/version/version.go b/version/version.go index 19e7aa9..1723179 100644 --- a/version/version.go +++ b/version/version.go @@ -3,6 +3,8 @@ package version import ( "fmt" "runtime" + + "github.com/prometheus/client_golang/prometheus" ) var ( @@ -29,3 +31,21 @@ func (i *ZreplVersionInformation) String() string { return fmt.Sprintf("zrepl version=%s GOOS=%s GOARCH=%s Compiler=%s", i.Version, i.RuntimeGOOS, i.RuntimeGOARCH, i.RUNTIMECompiler) } + +var prometheusMetric = prometheus.NewUntypedFunc( + prometheus.UntypedOpts{ + Namespace: "zrepl", + Subsystem: "version", + Name: "daemon", + Help: "zrepl daemon version", + ConstLabels: map[string]string{ + "raw": zreplVersion, + "version_info": NewZreplVersionInformation().String(), + }, + }, + func() float64 { return 1 }, +) + +func PrometheusRegister(r prometheus.Registerer) { + r.MustRegister(prometheusMetric) +}