export build version as a prometheus label (#405)
This is how Prometheus recommends you do it, and how they do it themselves in their client. This makes it easy to see which versions you have deployed in your fleet, and query over it too.
This commit is contained in:
parent
3ea7e1b75f
commit
a71541fb0b
2
main.go
2
main.go
|
@ -396,7 +396,7 @@ func Main(config *Config, configTest bool, buildVersion string, logger *logrus.L
|
||||||
go lightHouse.LhUpdateWorker(ifce)
|
go lightHouse.LhUpdateWorker(ifce)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = startStats(l, config, configTest)
|
err = startStats(l, config, buildVersion, configTest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, NewContextualError("Failed to start stats emitter", nil, err)
|
return nil, NewContextualError("Failed to start stats emitter", nil, err)
|
||||||
}
|
}
|
||||||
|
|
21
stats.go
21
stats.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
graphite "github.com/cyberdelia/go-metrics-graphite"
|
graphite "github.com/cyberdelia/go-metrics-graphite"
|
||||||
|
@ -16,7 +17,7 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func startStats(l *logrus.Logger, c *Config, configTest bool) error {
|
func startStats(l *logrus.Logger, c *Config, buildVersion string, configTest bool) error {
|
||||||
mType := c.GetString("stats.type", "")
|
mType := c.GetString("stats.type", "")
|
||||||
if mType == "" || mType == "none" {
|
if mType == "" || mType == "none" {
|
||||||
return nil
|
return nil
|
||||||
|
@ -31,7 +32,7 @@ func startStats(l *logrus.Logger, c *Config, configTest bool) error {
|
||||||
case "graphite":
|
case "graphite":
|
||||||
startGraphiteStats(l, interval, c, configTest)
|
startGraphiteStats(l, interval, c, configTest)
|
||||||
case "prometheus":
|
case "prometheus":
|
||||||
startPrometheusStats(l, interval, c, configTest)
|
startPrometheusStats(l, interval, c, buildVersion, configTest)
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("stats.type was not understood: %s", mType)
|
return fmt.Errorf("stats.type was not understood: %s", mType)
|
||||||
}
|
}
|
||||||
|
@ -65,7 +66,7 @@ func startGraphiteStats(l *logrus.Logger, i time.Duration, c *Config, configTest
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func startPrometheusStats(l *logrus.Logger, i time.Duration, c *Config, configTest bool) error {
|
func startPrometheusStats(l *logrus.Logger, i time.Duration, c *Config, buildVersion string, configTest bool) error {
|
||||||
namespace := c.GetString("stats.namespace", "")
|
namespace := c.GetString("stats.namespace", "")
|
||||||
subsystem := c.GetString("stats.subsystem", "")
|
subsystem := c.GetString("stats.subsystem", "")
|
||||||
|
|
||||||
|
@ -83,6 +84,20 @@ func startPrometheusStats(l *logrus.Logger, i time.Duration, c *Config, configTe
|
||||||
pClient := mp.NewPrometheusProvider(metrics.DefaultRegistry, namespace, subsystem, pr, i)
|
pClient := mp.NewPrometheusProvider(metrics.DefaultRegistry, namespace, subsystem, pr, i)
|
||||||
go pClient.UpdatePrometheusMetrics()
|
go pClient.UpdatePrometheusMetrics()
|
||||||
|
|
||||||
|
// Export our version information as labels on a static gauge
|
||||||
|
g := prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: subsystem,
|
||||||
|
Name: "info",
|
||||||
|
Help: "Version information for the Nebula binary",
|
||||||
|
ConstLabels: prometheus.Labels{
|
||||||
|
"version": buildVersion,
|
||||||
|
"goversion": runtime.Version(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
pr.MustRegister(g)
|
||||||
|
g.Set(1)
|
||||||
|
|
||||||
if !configTest {
|
if !configTest {
|
||||||
go func() {
|
go func() {
|
||||||
l.Infof("Prometheus stats listening on %s at %s", listen, path)
|
l.Infof("Prometheus stats listening on %s at %s", listen, path)
|
||||||
|
|
Loading…
Reference in New Issue