Skip to content

Commit

Permalink
Make rabbitmq_queue gathering be configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
ildarsv committed Jan 19, 2018
1 parent 0f55d9e commit 0a804da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions plugins/inputs/rabbitmq/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ For additional details reference the [RabbitMQ Management HTTP Stats](https://cd
## Includes connection time, any redirects, and reading the response body.
# client_timeout = "4s"

## Whether to gather queues metrics.
# gather_queues = true

## A list of nodes to gather as the rabbitmq_node measurement. If not
## specified, metrics for all nodes are gathered.
# nodes = ["rabbit@node1", "rabbit@node2"]
Expand Down
17 changes: 15 additions & 2 deletions plugins/inputs/rabbitmq/rabbitmq.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type RabbitMQ struct {
ResponseHeaderTimeout internal.Duration `toml:"header_timeout"`
ClientTimeout internal.Duration `toml:"client_timeout"`

GatherQueues bool

Nodes []string
Queues []string
Exchanges []string
Expand Down Expand Up @@ -149,7 +151,7 @@ type Exchange struct {
// gatherFunc ...
type gatherFunc func(r *RabbitMQ, acc telegraf.Accumulator)

var gatherFunctions = []gatherFunc{gatherOverview, gatherNodes, gatherQueues, gatherExchanges}
var gatherFunctions = []gatherFunc{gatherOverview, gatherNodes, gatherExchanges}

var sampleConfig = `
## Management Plugin url. (default: http://localhost:15672)
Expand Down Expand Up @@ -177,6 +179,9 @@ var sampleConfig = `
## Includes connection time, any redirects, and reading the response body.
# client_timeout = "4s"
## Whether to gather queues metrics.
# gather_queues = true
## A list of nodes to gather as the rabbitmq_node measurement. If not
## specified, metrics for all nodes are gathered.
# nodes = ["rabbit@node1", "rabbit@node2"]
Expand All @@ -186,7 +191,7 @@ 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"]
`

Expand Down Expand Up @@ -226,6 +231,13 @@ func (r *RabbitMQ) Gather(acc telegraf.Accumulator) error {
gf(r, acc)
}(f)
}
if r.GatherQueues {
wg.Add(1)
go func() {
defer wg.Done()
gatherQueues(r, acc)
}()
}
wg.Wait()

return nil
Expand Down Expand Up @@ -472,6 +484,7 @@ func init() {
return &RabbitMQ{
ResponseHeaderTimeout: internal.Duration{Duration: DefaultResponseHeaderTimeout * time.Second},
ClientTimeout: internal.Duration{Duration: DefaultClientTimeout * time.Second},
GatherQueues: true,
}
})
}

0 comments on commit 0a804da

Please sign in to comment.