From decb09e7607d0eff825c6f67e0a9e09bd0ff3b9f Mon Sep 17 00:00:00 2001
From: Paulo Cabido <paulo.cabido@gmail.com>
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 4ec7eee3..13cd8041 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 c068a5fe..92addf9c 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 5be29a24..767f9a87 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
-- 
GitLab