-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Couchbase input plugin #866
Changes from 6 commits
c512c25
747edb0
8ed7a7e
de10b8e
233cd77
7d16fbf
92cea4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Telegraf Plugin: Couchbase | ||
|
||
### Configuration: | ||
|
||
``` | ||
# Read per-node and per-bucket metrics from Couchbase | ||
[[inputs.couchbase]] | ||
## specify servers via a url matching: | ||
## [protocol://][:password]@address[:port] | ||
## e.g. | ||
## http://couchbase-0.example.com/ | ||
## http://admin:[email protected]:8091/ | ||
## | ||
## If no servers are specified, then localhost is used as the host. | ||
## If no protocol is specifed, HTTP is used. | ||
## If no port is specified, 8091 is used. | ||
servers = ["http://localhost:8091"] | ||
``` | ||
|
||
## Measurements: | ||
|
||
### Per-node measurements | ||
|
||
Meta: | ||
- units: bytes | ||
- tags: `cluster`, `hostname` | ||
|
||
Measurement names: | ||
- memory_free (example: 23181365248.0) | ||
- memory_total (example: 64424656896.0) | ||
|
||
### Per-bucket measurements | ||
|
||
Meta: | ||
- units: varies | ||
- tags: `cluster`, `bucket` | ||
|
||
Measurement names: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also field names, and update the casing |
||
- quotaPercentUsed (unit: percent, example: 68.85424936294555) | ||
- opsPerSec (unit: count, example: 5686.789686789687) | ||
- diskFetches (unit: count, example: 0.0) | ||
- itemCount (unit: count, example: 943239752.0) | ||
- diskUsed (unit: bytes, example: 409178772321.0) | ||
- dataUsed (unit: bytes, example: 212179309111.0) | ||
- memUsed (unit: bytes, example: 202156957464.0) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here you should have example output There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please provide example test output also, for example: https://github.com/influxdata/telegraf/tree/master/plugins/inputs/dns_query#example-output |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package couchbase | ||
|
||
import ( | ||
couchbase "github.com/couchbase/go-couchbase" | ||
"github.com/influxdata/telegraf" | ||
"github.com/influxdata/telegraf/plugins/inputs" | ||
"sync" | ||
) | ||
|
||
type Couchbase struct { | ||
Servers []string | ||
} | ||
|
||
var sampleConfig = ` | ||
## specify servers via a url matching: | ||
## [protocol://][:password]@address[:port] | ||
## e.g. | ||
## http://couchbase-0.example.com/ | ||
## http://admin:[email protected]:8091/ | ||
## | ||
## If no servers are specified, then localhost is used as the host. | ||
## If no protocol is specifed, HTTP is used. | ||
## If no port is specified, 8091 is used. | ||
servers = ["http://localhost:8091"] | ||
` | ||
|
||
func (r *Couchbase) SampleConfig() string { | ||
return sampleConfig | ||
} | ||
|
||
func (r *Couchbase) Description() string { | ||
return "Read metrics from one or many couchbase clusters" | ||
} | ||
|
||
// Reads stats from all configured clusters. Accumulates stats. | ||
// Returns one of the errors encountered while gathering stats (if any). | ||
func (r *Couchbase) Gather(acc telegraf.Accumulator) error { | ||
if len(r.Servers) == 0 { | ||
r.gatherServer("http://localhost:8091/", acc, nil) | ||
return nil | ||
} | ||
|
||
var wg sync.WaitGroup | ||
|
||
var outerr error | ||
|
||
for _, serv := range r.Servers { | ||
wg.Add(1) | ||
go func(serv string) { | ||
defer wg.Done() | ||
outerr = r.gatherServer(serv, acc, nil) | ||
}(serv) | ||
} | ||
|
||
wg.Wait() | ||
|
||
return outerr | ||
} | ||
|
||
func (r *Couchbase) gatherServer(addr string, acc telegraf.Accumulator, pool *couchbase.Pool) error { | ||
if pool == nil { | ||
client, err := couchbase.Connect(addr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// `default` is the only possible pool name. It's a | ||
// placeholder for a possible future Couchbase feature. See | ||
// http://stackoverflow.com/a/16990911/17498. | ||
p, err := client.GetPool("default") | ||
if err != nil { | ||
return err | ||
} | ||
pool = &p | ||
} | ||
for i := 0; i < len(pool.Nodes); i++ { | ||
node := pool.Nodes[i] | ||
tags := map[string]string{"cluster": addr, "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 { | ||
tags := map[string]string{"cluster": addr, "bucket": bucketName} | ||
bs := pool.BucketMap[bucketName].BasicStats | ||
fields := make(map[string]interface{}) | ||
fields["quota_percent_used"] = bs["quotaPercentUsed"] | ||
fields["ops_per_sec"] = bs["opsPerSec"] | ||
fields["disk_fetches"] = bs["diskFetches"] | ||
fields["item_count"] = bs["itemCount"] | ||
fields["disk_used"] = bs["diskUsed"] | ||
fields["data_used"] = bs["dataUsed"] | ||
fields["mem_used"] = bs["memUsed"] | ||
acc.AddFields("couchbase_bucket", fields, tags) | ||
} | ||
return nil | ||
} | ||
|
||
func init() { | ||
inputs.Add("couchbase", func() telegraf.Input { | ||
return &Couchbase{} | ||
}) | ||
} |
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are actually "field names"