Sanitize password from couchbase metric (#3033)

This commit is contained in:
DanKans 2017-07-31 19:29:14 +01:00 committed by Daniel Nelson
parent c31e7d0b91
commit 5e95367f6c
3 changed files with 34 additions and 4 deletions

View File

@ -22,7 +22,7 @@
### couchbase_node
Tags:
- cluster: whatever you called it in `servers` in the configuration, e.g.: `http://couchbase-0.example.com/`
- cluster: sanitized string from `servers` configuration field e.g.: `http://user:password@couchbase-0.example.com:8091/endpoint` -> `http://couchbase-0.example.com:8091/endpoint`
- hostname: Couchbase's name for the node and port, e.g., `172.16.10.187:8091`
Fields:

View File

@ -1,10 +1,12 @@
package couchbase
import (
"regexp"
"sync"
couchbase "github.com/couchbase/go-couchbase"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
"sync"
)
type Couchbase struct {
@ -24,6 +26,8 @@ var sampleConfig = `
servers = ["http://localhost:8091"]
`
var regexpURI = regexp.MustCompile(`(\S+://)?(\S+\:\S+@)`)
func (r *Couchbase) SampleConfig() string {
return sampleConfig
}
@ -71,15 +75,17 @@ func (r *Couchbase) gatherServer(addr string, acc telegraf.Accumulator, pool *co
}
pool = &p
}
for i := 0; i < len(pool.Nodes); i++ {
node := pool.Nodes[i]
tags := map[string]string{"cluster": addr, "hostname": node.Hostname}
tags := map[string]string{"cluster": regexpURI.ReplaceAllString(addr, "${1}"), "hostname": node.Hostname}
fields := make(map[string]interface{})
fields["memory_free"] = node.MemoryFree
fields["memory_total"] = node.MemoryTotal
acc.AddFields("couchbase_node", fields, tags)
}
for bucketName, _ := range pool.BucketMap {
for bucketName := range pool.BucketMap {
tags := map[string]string{"cluster": addr, "bucket": bucketName}
bs := pool.BucketMap[bucketName].BasicStats
fields := make(map[string]interface{})

File diff suppressed because one or more lines are too long