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 cb56269c8b
commit 4c84e5996c
3 changed files with 34 additions and 4 deletions

View File

@ -22,7 +22,7 @@
### couchbase_node ### couchbase_node
Tags: 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` - hostname: Couchbase's name for the node and port, e.g., `172.16.10.187:8091`
Fields: Fields:

View File

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

File diff suppressed because one or more lines are too long