Add configurable metrics endpoint to prometheus output (#3245)
This commit is contained in:
committed by
Daniel Nelson
parent
a63f80e017
commit
decb09e760
@@ -1,6 +1,6 @@
|
||||
# Prometheus Client Service Output Plugin
|
||||
|
||||
This plugin starts a [Prometheus](https://prometheus.io/) Client, it exposes all metrics on `/metrics` to be polled by a Prometheus server.
|
||||
This plugin starts a [Prometheus](https://prometheus.io/) Client, it exposes all metrics on `/metrics` (default) to be polled by a Prometheus server.
|
||||
|
||||
## Configuration
|
||||
|
||||
@@ -10,6 +10,9 @@ This plugin starts a [Prometheus](https://prometheus.io/) Client, it exposes all
|
||||
# Address to listen on
|
||||
listen = ":9273"
|
||||
|
||||
# Path to publish the metrics on, defaults to /metrics
|
||||
path = "/metrics"
|
||||
|
||||
# Expiration interval for each metric. 0 == no expiration
|
||||
expiration_interval = "60s"
|
||||
```
|
||||
|
||||
@@ -45,6 +45,7 @@ type MetricFamily struct {
|
||||
type PrometheusClient struct {
|
||||
Listen string
|
||||
ExpirationInterval internal.Duration `toml:"expiration_interval"`
|
||||
Path string `toml:"path"`
|
||||
|
||||
server *http.Server
|
||||
|
||||
@@ -70,8 +71,12 @@ func (p *PrometheusClient) Start() error {
|
||||
p.Listen = "localhost:9273"
|
||||
}
|
||||
|
||||
if p.Path == "" {
|
||||
p.Path = "/metrics"
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/metrics", prometheus.Handler())
|
||||
mux.Handle(p.Path, prometheus.Handler())
|
||||
|
||||
p.server = &http.Server{
|
||||
Addr: p.Listen,
|
||||
|
||||
@@ -445,6 +445,7 @@ func setupPrometheus() (*PrometheusClient, *prometheus_input.Prometheus, error)
|
||||
if pTesting == nil {
|
||||
pTesting = NewClient()
|
||||
pTesting.Listen = "localhost:9127"
|
||||
pTesting.Path = "/metrics"
|
||||
err := pTesting.Start()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
Reference in New Issue
Block a user