mirror of
https://github.com/slackhq/nebula.git
synced 2025-11-08 22:13:57 +01:00
stats: add ability to set static prometheus labels
This changes lets you define static Prometheus labels in the config.
This can be useful for tagging your stats with the custom labels you
need for your environment.
stats:
type: prometheus
labels:
myLabelOne: value1
myLabelTwo: value2
This commit is contained in:
parent
f8fb9759e9
commit
06372e12f1
@ -272,6 +272,10 @@ logging:
|
|||||||
#namespace: prometheusns
|
#namespace: prometheusns
|
||||||
#subsystem: nebula
|
#subsystem: nebula
|
||||||
#interval: 10s
|
#interval: 10s
|
||||||
|
# You can optionally set static labels to include with all metrics
|
||||||
|
#labels:
|
||||||
|
# myStaticLabel1: value1
|
||||||
|
# myStaticLabel2: value2
|
||||||
|
|
||||||
# enables counter metrics for meta packets
|
# enables counter metrics for meta packets
|
||||||
# e.g.: `messages.tx.handshake`
|
# e.g.: `messages.tx.handshake`
|
||||||
|
|||||||
19
stats.go
19
stats.go
@ -93,8 +93,19 @@ func startPrometheusStats(l *logrus.Logger, i time.Duration, c *config.C, buildV
|
|||||||
return nil, fmt.Errorf("stats.path should not be empty")
|
return nil, fmt.Errorf("stats.path should not be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
pr := prometheus.NewRegistry()
|
pry := prometheus.NewRegistry()
|
||||||
pClient := mp.NewPrometheusProvider(metrics.DefaultRegistry, namespace, subsystem, pr, i)
|
var prr prometheus.Registerer = pry
|
||||||
|
|
||||||
|
labelsRaw := c.GetMap("stats.labels", nil)
|
||||||
|
if labelsRaw != nil {
|
||||||
|
labels := prometheus.Labels{}
|
||||||
|
for k, v := range labelsRaw {
|
||||||
|
labels[fmt.Sprintf("%v", k)] = fmt.Sprintf("%v", v)
|
||||||
|
}
|
||||||
|
prr = prometheus.WrapRegistererWith(labels, prr)
|
||||||
|
}
|
||||||
|
|
||||||
|
pClient := mp.NewPrometheusProvider(metrics.DefaultRegistry, namespace, subsystem, prr, i)
|
||||||
if !configTest {
|
if !configTest {
|
||||||
go pClient.UpdatePrometheusMetrics()
|
go pClient.UpdatePrometheusMetrics()
|
||||||
}
|
}
|
||||||
@ -111,14 +122,14 @@ func startPrometheusStats(l *logrus.Logger, i time.Duration, c *config.C, buildV
|
|||||||
"boringcrypto": strconv.FormatBool(boringEnabled()),
|
"boringcrypto": strconv.FormatBool(boringEnabled()),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
pr.MustRegister(g)
|
prr.MustRegister(g)
|
||||||
g.Set(1)
|
g.Set(1)
|
||||||
|
|
||||||
var startFn func()
|
var startFn func()
|
||||||
if !configTest {
|
if !configTest {
|
||||||
startFn = func() {
|
startFn = func() {
|
||||||
l.Infof("Prometheus stats listening on %s at %s", listen, path)
|
l.Infof("Prometheus stats listening on %s at %s", listen, path)
|
||||||
http.Handle(path, promhttp.HandlerFor(pr, promhttp.HandlerOpts{ErrorLog: l}))
|
http.Handle(path, promhttp.HandlerFor(pry, promhttp.HandlerOpts{ErrorLog: l}))
|
||||||
log.Fatal(http.ListenAndServe(listen, nil))
|
log.Fatal(http.ListenAndServe(listen, nil))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user