From 6dff2ab92b1e849035155e52efb1d6a659aa4e5b Mon Sep 17 00:00:00 2001 From: Jacob Lisi Date: Tue, 26 Jun 2018 16:59:55 -0400 Subject: [PATCH 1/2] Add http path configuration for OpenTSDB plugin --- etc/telegraf.conf | 4 ++++ plugins/outputs/opentsdb/opentsdb.go | 6 ++++++ plugins/outputs/opentsdb/opentsdb_http.go | 3 ++- plugins/outputs/opentsdb/opentsdb_test.go | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/etc/telegraf.conf b/etc/telegraf.conf index f51e973df3fdb..38942adee0a6a 100644 --- a/etc/telegraf.conf +++ b/etc/telegraf.conf @@ -723,6 +723,10 @@ # ## Not used with telnet API. # httpBatchSize = 50 # +# ## URI Path for Http requests to OpenTSDB. +# ## Used in cases where OpenTSDB is located behind a reverse proxy. +# httpPath = "/api/put" +# # ## Debug true - Prints OpenTSDB communication # debug = false # diff --git a/plugins/outputs/opentsdb/opentsdb.go b/plugins/outputs/opentsdb/opentsdb.go index c38ad353b36be..a7ab4b0315acb 100644 --- a/plugins/outputs/opentsdb/opentsdb.go +++ b/plugins/outputs/opentsdb/opentsdb.go @@ -32,6 +32,7 @@ type OpenTSDB struct { Port int HttpBatchSize int + HttpPath string Debug bool @@ -54,6 +55,10 @@ var sampleConfig = ` ## Not used with telnet API. httpBatchSize = 50 + ## URI Path for Http requests to OpenTSDB. + ## Used in cases where OpenTSDB is located behind a reverse proxy. + httpPath = "/api/put" + ## Debug true - Prints OpenTSDB communication debug = false @@ -121,6 +126,7 @@ func (o *OpenTSDB) WriteHttp(metrics []telegraf.Metric, u *url.URL) error { Scheme: u.Scheme, User: u.User, BatchSize: o.HttpBatchSize, + Path: o.HttpPath, Debug: o.Debug, } diff --git a/plugins/outputs/opentsdb/opentsdb_http.go b/plugins/outputs/opentsdb/opentsdb_http.go index e74e74f039448..4f971abb639aa 100644 --- a/plugins/outputs/opentsdb/opentsdb_http.go +++ b/plugins/outputs/opentsdb/opentsdb_http.go @@ -26,6 +26,7 @@ type openTSDBHttp struct { Scheme string User *url.Userinfo BatchSize int + Path string Debug bool metricCounter int @@ -123,7 +124,7 @@ func (o *openTSDBHttp) flush() error { Scheme: o.Scheme, User: o.User, Host: fmt.Sprintf("%s:%d", o.Host, o.Port), - Path: "/api/put", + Path: o.Path, } if o.Debug { diff --git a/plugins/outputs/opentsdb/opentsdb_test.go b/plugins/outputs/opentsdb/opentsdb_test.go index d5d7aa7e90fcf..096337c5c6648 100644 --- a/plugins/outputs/opentsdb/opentsdb_test.go +++ b/plugins/outputs/opentsdb/opentsdb_test.go @@ -156,6 +156,7 @@ func BenchmarkHttpSend(b *testing.B) { Port: port, Prefix: "", HttpBatchSize: BatchSize, + HttpPath: "/api/put", } b.ResetTimer() From f7fd035e57255145a2d8cbdb2091604b8be099ed Mon Sep 17 00:00:00 2001 From: Jacob Lisi Date: Fri, 29 Jun 2018 13:17:35 -0400 Subject: [PATCH 2/2] set default path to /api/put --- plugins/outputs/opentsdb/opentsdb.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/outputs/opentsdb/opentsdb.go b/plugins/outputs/opentsdb/opentsdb.go index a7ab4b0315acb..96d022c199042 100644 --- a/plugins/outputs/opentsdb/opentsdb.go +++ b/plugins/outputs/opentsdb/opentsdb.go @@ -22,6 +22,7 @@ var ( `%`, "-", "#", "-", "$", "-") + defaultHttpPath = "/api/put" defaultSeperator = "_" ) @@ -266,6 +267,7 @@ func sanitize(value string) string { func init() { outputs.Add("opentsdb", func() telegraf.Output { return &OpenTSDB{ + HttpPath: defaultHttpPath, Separator: defaultSeperator, } })