From 43e2400612961f1edd006acfe4f763ee8c527ac8 Mon Sep 17 00:00:00 2001 From: Paulo Cabido Date: Tue, 19 Sep 2017 11:27:11 -0700 Subject: [PATCH] Add configurable metrics endpoint to prometheus output (#3245) --- plugins/outputs/prometheus_client/README.md | 5 ++++- plugins/outputs/prometheus_client/prometheus_client.go | 7 ++++++- .../outputs/prometheus_client/prometheus_client_test.go | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/outputs/prometheus_client/README.md b/plugins/outputs/prometheus_client/README.md index 4ec7eee3f..13cd80412 100644 --- a/plugins/outputs/prometheus_client/README.md +++ b/plugins/outputs/prometheus_client/README.md @@ -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" ``` diff --git a/plugins/outputs/prometheus_client/prometheus_client.go b/plugins/outputs/prometheus_client/prometheus_client.go index c068a5fe7..92addf9c0 100644 --- a/plugins/outputs/prometheus_client/prometheus_client.go +++ b/plugins/outputs/prometheus_client/prometheus_client.go @@ -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, diff --git a/plugins/outputs/prometheus_client/prometheus_client_test.go b/plugins/outputs/prometheus_client/prometheus_client_test.go index 5be29a241..767f9a878 100644 --- a/plugins/outputs/prometheus_client/prometheus_client_test.go +++ b/plugins/outputs/prometheus_client/prometheus_client_test.go @@ -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