Add http path configuration for OpenTSDB output (#4347)

This commit is contained in:
Jacob Lisi 2018-07-02 18:04:01 -04:00 committed by Daniel Nelson
parent 9bc63c2f7a
commit c7cfc2ec39
4 changed files with 15 additions and 1 deletions

View File

@ -723,6 +723,10 @@
# ## Not used with telnet API. # ## Not used with telnet API.
# httpBatchSize = 50 # 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 true - Prints OpenTSDB communication
# debug = false # debug = false
# #

View File

@ -22,6 +22,7 @@ var (
`%`, "-", `%`, "-",
"#", "-", "#", "-",
"$", "-") "$", "-")
defaultHttpPath = "/api/put"
defaultSeperator = "_" defaultSeperator = "_"
) )
@ -32,6 +33,7 @@ type OpenTSDB struct {
Port int Port int
HttpBatchSize int HttpBatchSize int
HttpPath string
Debug bool Debug bool
@ -54,6 +56,10 @@ var sampleConfig = `
## Not used with telnet API. ## Not used with telnet API.
httpBatchSize = 50 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 true - Prints OpenTSDB communication
debug = false debug = false
@ -121,6 +127,7 @@ func (o *OpenTSDB) WriteHttp(metrics []telegraf.Metric, u *url.URL) error {
Scheme: u.Scheme, Scheme: u.Scheme,
User: u.User, User: u.User,
BatchSize: o.HttpBatchSize, BatchSize: o.HttpBatchSize,
Path: o.HttpPath,
Debug: o.Debug, Debug: o.Debug,
} }
@ -260,6 +267,7 @@ func sanitize(value string) string {
func init() { func init() {
outputs.Add("opentsdb", func() telegraf.Output { outputs.Add("opentsdb", func() telegraf.Output {
return &OpenTSDB{ return &OpenTSDB{
HttpPath: defaultHttpPath,
Separator: defaultSeperator, Separator: defaultSeperator,
} }
}) })

View File

@ -26,6 +26,7 @@ type openTSDBHttp struct {
Scheme string Scheme string
User *url.Userinfo User *url.Userinfo
BatchSize int BatchSize int
Path string
Debug bool Debug bool
metricCounter int metricCounter int
@ -123,7 +124,7 @@ func (o *openTSDBHttp) flush() error {
Scheme: o.Scheme, Scheme: o.Scheme,
User: o.User, User: o.User,
Host: fmt.Sprintf("%s:%d", o.Host, o.Port), Host: fmt.Sprintf("%s:%d", o.Host, o.Port),
Path: "/api/put", Path: o.Path,
} }
if o.Debug { if o.Debug {

View File

@ -156,6 +156,7 @@ func BenchmarkHttpSend(b *testing.B) {
Port: port, Port: port,
Prefix: "", Prefix: "",
HttpBatchSize: BatchSize, HttpBatchSize: BatchSize,
HttpPath: "/api/put",
} }
b.ResetTimer() b.ResetTimer()