Add configurable metrics endpoint to prometheus output (#3245)

This commit is contained in:
Paulo Cabido 2017-09-19 11:27:11 -07:00 committed by Daniel Nelson
parent cf69a97ae0
commit 43e2400612
3 changed files with 11 additions and 2 deletions

View File

@ -1,6 +1,6 @@
# Prometheus Client Service Output Plugin # 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 ## Configuration
@ -10,6 +10,9 @@ This plugin starts a [Prometheus](https://prometheus.io/) Client, it exposes all
# Address to listen on # Address to listen on
listen = ":9273" listen = ":9273"
# Path to publish the metrics on, defaults to /metrics
path = "/metrics"
# Expiration interval for each metric. 0 == no expiration # Expiration interval for each metric. 0 == no expiration
expiration_interval = "60s" expiration_interval = "60s"
``` ```

View File

@ -45,6 +45,7 @@ type MetricFamily struct {
type PrometheusClient struct { type PrometheusClient struct {
Listen string Listen string
ExpirationInterval internal.Duration `toml:"expiration_interval"` ExpirationInterval internal.Duration `toml:"expiration_interval"`
Path string `toml:"path"`
server *http.Server server *http.Server
@ -70,8 +71,12 @@ func (p *PrometheusClient) Start() error {
p.Listen = "localhost:9273" p.Listen = "localhost:9273"
} }
if p.Path == "" {
p.Path = "/metrics"
}
mux := http.NewServeMux() mux := http.NewServeMux()
mux.Handle("/metrics", prometheus.Handler()) mux.Handle(p.Path, prometheus.Handler())
p.server = &http.Server{ p.server = &http.Server{
Addr: p.Listen, Addr: p.Listen,

View File

@ -445,6 +445,7 @@ func setupPrometheus() (*PrometheusClient, *prometheus_input.Prometheus, error)
if pTesting == nil { if pTesting == nil {
pTesting = NewClient() pTesting = NewClient()
pTesting.Listen = "localhost:9127" pTesting.Listen = "localhost:9127"
pTesting.Path = "/metrics"
err := pTesting.Start() err := pTesting.Start()
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err