Skip to content
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

Make rabbitmq_queue gathering be configurable #3702

Merged
merged 6 commits into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plugins/inputs/rabbitmq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ For additional details reference the [RabbitMQ Management HTTP Stats](https://cd
## A list of exchanges to gather as the rabbitmq_exchange measurement. If not
## specified, metrics for all exchanges are gathered.
# exchanges = ["telegraf"]

## Queues to include and exclude. Globs accepted.
## Note that an empty array for both will include all queues
# queue_name_include = []
# queue_name_exclude = []
```

### Measurements & Fields:
Expand Down
50 changes: 41 additions & 9 deletions plugins/inputs/rabbitmq/rabbitmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/filter"
"github.com/influxdata/telegraf/internal"
"github.com/influxdata/telegraf/plugins/inputs"
)
Expand Down Expand Up @@ -52,7 +53,14 @@ type RabbitMQ struct {
Queues []string
Exchanges []string

QueueInclude []string `toml:"queue_name_include"`
QueueExclude []string `toml:"queue_name_exclude"`

Client *http.Client

filterCreated bool
excludeEveryQueue bool
queueFilter filter.Filter
}

// OverviewResponse ...
Expand Down Expand Up @@ -186,8 +194,13 @@ var sampleConfig = `
# queues = ["telegraf"]

## A list of exchanges to gather as the rabbitmq_exchange measurement. If not
## specified, metrics for all exchanges are gathered.
## specified, metrics for all exchanges are gathered.
# exchanges = ["telegraf"]

## Queues to include and exclude. Globs accepted.
## Note that an empty array for both will include all queues
queue_name_include = []
queue_name_exclude = []
`

// SampleConfig ...
Expand Down Expand Up @@ -218,6 +231,15 @@ func (r *RabbitMQ) Gather(acc telegraf.Accumulator) error {
}
}

// Create queue filter if not already created
if !r.filterCreated {
err := r.createQueueFilter()
if err != nil {
return err
}
r.filterCreated = true
}

var wg sync.WaitGroup
wg.Add(len(gatherFunctions))
for _, f := range gatherFunctions {
Expand Down Expand Up @@ -337,6 +359,9 @@ func gatherNodes(r *RabbitMQ, acc telegraf.Accumulator) {
}

func gatherQueues(r *RabbitMQ, acc telegraf.Accumulator) {
if r.excludeEveryQueue {
return
}
// Gather information about queues
queues := make([]Queue, 0)
err := r.requestJSON("/api/queues", &queues)
Expand All @@ -346,7 +371,7 @@ func gatherQueues(r *RabbitMQ, acc telegraf.Accumulator) {
}

for _, queue := range queues {
if !r.shouldGatherQueue(queue) {
if !r.queueFilter.Match(queue.Name) {
continue
}
tags := map[string]string{
Expand Down Expand Up @@ -439,18 +464,25 @@ func (r *RabbitMQ) shouldGatherNode(node Node) bool {
return false
}

func (r *RabbitMQ) shouldGatherQueue(queue Queue) bool {
if len(r.Queues) == 0 {
return true
func (r *RabbitMQ) createQueueFilter() error {
// Backwards compatibility for deprecated `queues` parameter.
if len(r.Queues) > 0 {
r.QueueInclude = append(r.QueueInclude, r.Queues...)
}

for _, name := range r.Queues {
if name == queue.Name {
return true
filter, err := filter.NewIncludeExcludeFilter(r.QueueInclude, r.QueueExclude)
if err != nil {
return err
}
r.queueFilter = filter

for _, q := range r.QueueExclude {
if q == "*" {
r.excludeEveryQueue = true
}
}

return false
return nil
}

func (r *RabbitMQ) shouldGatherExchange(exchange Exchange) bool {
Expand Down