From 5a1f20142c28153fa9849238d06d99605ff13af9 Mon Sep 17 00:00:00 2001 From: postmannen Date: Fri, 10 Sep 2021 10:21:33 +0200 Subject: [PATCH] added prometheus exporter for build version --- metrics.go | 13 +++++++++++-- server.go | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/metrics.go b/metrics.go index b15a095..d0f02ec 100644 --- a/metrics.go +++ b/metrics.go @@ -18,6 +18,9 @@ type metrics struct { // host and port where prometheus metrics will be exported. hostAndPort string + // The build version + promVersion *prometheus.GaugeVec + // --- Processes // Prometheus metrics for total processes. promProcessesTotal prometheus.Gauge @@ -65,6 +68,13 @@ func newMetrics(hostAndPort string) *metrics { hostAndPort: hostAndPort, } + m.promVersion = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "steward_build_version", + Help: "Build version of steward", + }, []string{"version"}, + ) + m.promRegistry.MustRegister(m.promVersion) + m.promProcessesTotal = prometheus.NewGauge(prometheus.GaugeOpts{ Name: "steward_processes_total", Help: "The current number of total running processes", @@ -87,8 +97,7 @@ func newMetrics(hostAndPort string) *metrics { m.promHelloNodesContactLast = prometheus.NewGaugeVec(prometheus.GaugeOpts{ Name: "steward_hello_node_contact_last", Help: "Name of the nodes who have said hello", - }, []string{"nodeName"}, - ) + }, []string{"nodeName"}) m.promRegistry.MustRegister(m.promHelloNodesContactLast) m.promMessagesProcessedIDLast = prometheus.NewGauge(prometheus.GaugeOpts{ diff --git a/server.go b/server.go index 47a1518..cc5b8c1 100644 --- a/server.go +++ b/server.go @@ -12,6 +12,7 @@ import ( "time" "github.com/nats-io/nats.go" + "github.com/prometheus/client_golang/prometheus" ) type processName string @@ -195,6 +196,7 @@ func NewServer(c *Configuration, version string) (*server, error) { // if it does not exist it will spawn one. func (s *server) Start() { fmt.Printf(" * VERSION = %+v\n", s.version) + s.metrics.promVersion.With(prometheus.Labels{"version": string(s.version)}) // Start the error kernel that will do all the error handling // that is not done within a process.