Skip to content

Commit

Permalink
Add support for basic auth to couchdb input (influxdata#5160)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielnelson authored and Max Eshleman committed Feb 13, 2019
1 parent 690519c commit ceb4dc7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
18 changes: 12 additions & 6 deletions plugins/inputs/couchdb/README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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
20 changes: 18 additions & 2 deletions plugins/inputs/couchdb/couchdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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"
`
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit ceb4dc7

Please sign in to comment.