From bab0ebd8dbca06b46b54365b4163be435cc876ea Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Tue, 18 Dec 2018 14:32:13 -0800 Subject: [PATCH 1/2] Add support for basic auth in couchdb input --- plugins/inputs/couchdb/couchdb.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/couchdb/couchdb.go b/plugins/inputs/couchdb/couchdb.go index bc9f316884e4e..1b542d042dd30 100644 --- a/plugins/inputs/couchdb/couchdb.go +++ b/plugins/inputs/couchdb/couchdb.go @@ -80,7 +80,9 @@ type ( } CouchDB struct { - Hosts []string `toml:"hosts"` + Hosts []string `toml:"hosts"` + BasicUsername string `toml:"basic_username"` + BasicPassword string `toml:"basic_password"` client *http.Client } @@ -95,6 +97,10 @@ func (*CouchDB) SampleConfig() string { ## Works with CouchDB stats endpoints out of the box ## Multiple Hosts from which to read CouchDB stats: hosts = ["http://localhost:8086/_stats"] + + ## Use HTTP Basic Authentication. + # basic_username = "telegraf" + # basic_password = "p@ssw0rd" ` } @@ -124,7 +130,17 @@ func (c *CouchDB) fetchAndInsertData(accumulator telegraf.Accumulator, host stri Timeout: time.Duration(4 * time.Second), } } - response, error := c.client.Get(host) + + req, err := http.NewRequest("GET", host, nil) + if err != nil { + return err + } + + if c.BasicUsername != "" || c.BasicPassword != "" { + req.SetBasicAuth(c.BasicUsername, c.BasicPassword) + } + + response, error := c.client.Do(req) if error != nil { return error } From 613ed17e6283085e9a616be7d3d26179fb08fbdb Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Tue, 18 Dec 2018 14:37:51 -0800 Subject: [PATCH 2/2] Add basic auth to couchdb readme --- plugins/inputs/couchdb/README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/inputs/couchdb/README.md b/plugins/inputs/couchdb/README.md index 0af06cc542a39..3a7f127dbc3db 100644 --- a/plugins/inputs/couchdb/README.md +++ b/plugins/inputs/couchdb/README.md @@ -1,14 +1,18 @@ # CouchDB Input Plugin ---- -The CouchDB plugin gathers metrics of CouchDB using [_stats](http://docs.couchdb.org/en/1.6.1/api/server/common.html?highlight=stats#get--_stats) endpoint. +The CouchDB plugin gathers metrics of CouchDB using [_stats] endpoint. -### Configuration: +### Configuration -``` -# Sample Config: +```toml [[inputs.couchdb]] - hosts = ["http://localhost:5984/_stats"] + ## Works with CouchDB stats endpoints out of the box + ## Multiple Hosts from which to read CouchDB stats: + hosts = ["http://localhost:8086/_stats"] + + ## Use HTTP Basic Authentication. + # basic_username = "telegraf" + # basic_password = "p@ssw0rd" ``` ### Measurements & Fields: @@ -71,3 +75,5 @@ couchdb,server=http://couchdb22:5984/_node/_local/_stats couchdb_auth_cache_hits ``` couchdb,server=http://couchdb16:5984/_stats couchdb_request_time_sum=96,httpd_status_codes_200_sum=37,httpd_status_codes_200_min=0,httpd_requests_mean=0.005,httpd_requests_min=0,couchdb_request_time_stddev=3.833,couchdb_request_time_min=1,httpd_request_methods_get_stddev=0.073,httpd_request_methods_get_min=0,httpd_status_codes_200_mean=0.005,httpd_status_codes_200_max=1,httpd_requests_sum=37,couchdb_request_time_current=96,httpd_request_methods_get_sum=37,httpd_request_methods_get_mean=0.005,httpd_request_methods_get_max=1,httpd_status_codes_200_stddev=0.073,couchdb_request_time_mean=2.595,couchdb_request_time_max=25,httpd_request_methods_get_current=37,httpd_status_codes_200_current=37,httpd_requests_current=37,httpd_requests_stddev=0.073,httpd_requests_max=1 1536707179000000000 ``` + +[_stats]: http://docs.couchdb.org/en/1.6.1/api/server/common.html?highlight=stats#get--_stats