v1.1.3: surface daemon version + commit on maglev_info
Extend the existing maglev_info gauge with two more labels: - version (build version, from -ldflags) - commit (git short hash) Mirrors nginx_ipng_stats-plugin's nginx_ipng_info pattern: a label-only gauge value=1 carrying build metadata for Prometheus to query and Grafana dashboards to render. Useful for spotting version drift across the fleet with a single query, and for populating the "Version" column of the Maglev Nodes table on the global overview. Existing label source_tag is preserved. Plumbing: NewCollector / Register signatures gain version and commit string parameters; main.go reads them from cmd.Version() and cmd.Commit() (already imported as 'buildinfo').
This commit is contained in:
@@ -134,6 +134,8 @@ type Collector struct {
|
||||
src StateSource
|
||||
vpp VPPSource // optional; nil when VPP integration is disabled
|
||||
sourceTag string
|
||||
version string
|
||||
commit string
|
||||
|
||||
maglevInfo *prometheus.Desc
|
||||
backendState *prometheus.Desc
|
||||
@@ -153,16 +155,18 @@ type Collector struct {
|
||||
|
||||
// NewCollector creates a Collector backed by the given StateSource. vpp may
|
||||
// be nil when VPP integration is disabled; in that case vpp_* metrics are
|
||||
// simply not emitted.
|
||||
func NewCollector(src StateSource, vpp VPPSource, sourceTag string) *Collector {
|
||||
// simply not emitted. version and commit are surfaced via maglev_info labels.
|
||||
func NewCollector(src StateSource, vpp VPPSource, sourceTag, version, commit string) *Collector {
|
||||
return &Collector{
|
||||
src: src,
|
||||
vpp: vpp,
|
||||
sourceTag: sourceTag,
|
||||
version: version,
|
||||
commit: commit,
|
||||
maglevInfo: prometheus.NewDesc(
|
||||
"maglev_info",
|
||||
"Static maglevd instance metadata. Always 1; metadata is conveyed via labels.",
|
||||
[]string{"source_tag"}, nil,
|
||||
[]string{"source_tag", "version", "commit"}, nil,
|
||||
),
|
||||
backendState: prometheus.NewDesc(
|
||||
"maglev_backend_state",
|
||||
@@ -240,7 +244,8 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
|
||||
|
||||
// Collect implements prometheus.Collector.
|
||||
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
||||
ch <- prometheus.MustNewConstMetric(c.maglevInfo, prometheus.GaugeValue, 1.0, c.sourceTag)
|
||||
ch <- prometheus.MustNewConstMetric(c.maglevInfo, prometheus.GaugeValue, 1.0,
|
||||
c.sourceTag, c.version, c.commit)
|
||||
|
||||
states := []health.State{
|
||||
health.StateUnknown,
|
||||
@@ -353,9 +358,10 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
||||
}
|
||||
|
||||
// Register registers all metrics with the given registry. vpp may be nil
|
||||
// to disable VPP-related metrics.
|
||||
func Register(reg prometheus.Registerer, src StateSource, vpp VPPSource, sourceTag string) *Collector {
|
||||
coll := NewCollector(src, vpp, sourceTag)
|
||||
// to disable VPP-related metrics. version / commit are surfaced via
|
||||
// maglev_info labels.
|
||||
func Register(reg prometheus.Registerer, src StateSource, vpp VPPSource, sourceTag, version, commit string) *Collector {
|
||||
coll := NewCollector(src, vpp, sourceTag, version, commit)
|
||||
reg.MustRegister(coll)
|
||||
reg.MustRegister(ProbeTotal)
|
||||
reg.MustRegister(ProbeDuration)
|
||||
|
||||
Reference in New Issue
Block a user