Add gathering of RabbitMQ federation link metrics (#6283)
This commit is contained in:
committed by
Daniel Nelson
parent
1761e25c96
commit
8b3a8d1113
@@ -47,14 +47,17 @@ type RabbitMQ struct {
|
||||
Queues []string
|
||||
Exchanges []string
|
||||
|
||||
QueueInclude []string `toml:"queue_name_include"`
|
||||
QueueExclude []string `toml:"queue_name_exclude"`
|
||||
QueueInclude []string `toml:"queue_name_include"`
|
||||
QueueExclude []string `toml:"queue_name_exclude"`
|
||||
FederationUpstreamInclude []string `toml:"federation_upstream_include"`
|
||||
FederationUpstreamExclude []string `toml:"federation_upstream_exclude"`
|
||||
|
||||
Client *http.Client
|
||||
|
||||
filterCreated bool
|
||||
excludeEveryQueue bool
|
||||
queueFilter filter.Filter
|
||||
upstreamFilter filter.Filter
|
||||
}
|
||||
|
||||
// OverviewResponse ...
|
||||
@@ -178,6 +181,38 @@ type Exchange struct {
|
||||
AutoDelete bool `json:"auto_delete"`
|
||||
}
|
||||
|
||||
// FederationLinkChannelMessageStats ...
|
||||
type FederationLinkChannelMessageStats struct {
|
||||
Confirm int64 `json:"confirm"`
|
||||
ConfirmDetails Details `json:"confirm_details"`
|
||||
Publish int64 `json:"publish"`
|
||||
PublishDetails Details `json:"publish_details"`
|
||||
ReturnUnroutable int64 `json:"return_unroutable"`
|
||||
ReturnUnroutableDetails Details `json:"return_unroutable_details"`
|
||||
}
|
||||
|
||||
// FederationLinkChannel ...
|
||||
type FederationLinkChannel struct {
|
||||
AcksUncommitted int64 `json:"acks_uncommitted"`
|
||||
ConsumerCount int64 `json:"consumer_count"`
|
||||
MessagesUnacknowledged int64 `json:"messages_unacknowledged"`
|
||||
MessagesUncommitted int64 `json:"messages_uncommitted"`
|
||||
MessagesUnconfirmed int64 `json:"messages_unconfirmed"`
|
||||
MessageStats FederationLinkChannelMessageStats `json:"message_stats"`
|
||||
}
|
||||
|
||||
// FederationLink ...
|
||||
type FederationLink struct {
|
||||
Type string `json:"type"`
|
||||
Queue string `json:"queue"`
|
||||
UpstreamQueue string `json:"upstream_queue"`
|
||||
Exchange string `json:"exchange"`
|
||||
UpstreamExchange string `json:"upstream_exchange"`
|
||||
Vhost string `json:"vhost"`
|
||||
Upstream string `json:"upstream"`
|
||||
LocalChannel FederationLinkChannel `json:"local_channel"`
|
||||
}
|
||||
|
||||
type HealthCheck struct {
|
||||
Status string `json:"status"`
|
||||
}
|
||||
@@ -214,7 +249,7 @@ type Memory struct {
|
||||
// gatherFunc ...
|
||||
type gatherFunc func(r *RabbitMQ, acc telegraf.Accumulator)
|
||||
|
||||
var gatherFunctions = []gatherFunc{gatherOverview, gatherNodes, gatherQueues, gatherExchanges}
|
||||
var gatherFunctions = []gatherFunc{gatherOverview, gatherNodes, gatherQueues, gatherExchanges, gatherFederationLinks}
|
||||
|
||||
var sampleConfig = `
|
||||
## Management Plugin url. (default: http://localhost:15672)
|
||||
@@ -258,6 +293,15 @@ var sampleConfig = `
|
||||
## Note that an empty array for both will include all queues
|
||||
queue_name_include = []
|
||||
queue_name_exclude = []
|
||||
|
||||
## Federation upstreams include and exclude when gathering the rabbitmq_federation measurement.
|
||||
## If neither are specified, metrics for all federation upstreams are gathered.
|
||||
## Federation link metrics will only be gathered for queues and exchanges
|
||||
## whose non-federation metrics will be collected (e.g a queue excluded
|
||||
## by the 'queue_name_exclude' option will also be excluded from federation).
|
||||
## Globs accepted.
|
||||
# federation_upstream_include = ["dataCentre-*"]
|
||||
# federation_upstream_exclude = []
|
||||
`
|
||||
|
||||
func boolToInt(b bool) int64 {
|
||||
@@ -294,12 +338,16 @@ func (r *RabbitMQ) Gather(acc telegraf.Accumulator) error {
|
||||
}
|
||||
}
|
||||
|
||||
// Create queue filter if not already created
|
||||
// Create gather filters if not already created
|
||||
if !r.filterCreated {
|
||||
err := r.createQueueFilter()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = r.createUpstreamFilter()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.filterCreated = true
|
||||
}
|
||||
|
||||
@@ -598,7 +646,7 @@ func gatherExchanges(r *RabbitMQ, acc telegraf.Accumulator) {
|
||||
}
|
||||
|
||||
for _, exchange := range exchanges {
|
||||
if !r.shouldGatherExchange(exchange) {
|
||||
if !r.shouldGatherExchange(exchange.Name) {
|
||||
continue
|
||||
}
|
||||
tags := map[string]string{
|
||||
@@ -624,6 +672,52 @@ func gatherExchanges(r *RabbitMQ, acc telegraf.Accumulator) {
|
||||
}
|
||||
}
|
||||
|
||||
func gatherFederationLinks(r *RabbitMQ, acc telegraf.Accumulator) {
|
||||
// Gather information about federation links
|
||||
federationLinks := make([]FederationLink, 0)
|
||||
err := r.requestJSON("/api/federation-links", &federationLinks)
|
||||
if err != nil {
|
||||
acc.AddError(err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, link := range federationLinks {
|
||||
if !r.shouldGatherFederationLink(link) {
|
||||
continue
|
||||
}
|
||||
|
||||
tags := map[string]string{
|
||||
"url": r.URL,
|
||||
"type": link.Type,
|
||||
"vhost": link.Vhost,
|
||||
"upstream": link.Upstream,
|
||||
}
|
||||
|
||||
if link.Type == "exchange" {
|
||||
tags["exchange"] = link.Exchange
|
||||
tags["upstream_exchange"] = link.UpstreamExchange
|
||||
} else {
|
||||
tags["queue"] = link.Queue
|
||||
tags["upstream_queue"] = link.UpstreamQueue
|
||||
}
|
||||
|
||||
acc.AddFields(
|
||||
"rabbitmq_federation",
|
||||
map[string]interface{}{
|
||||
"acks_uncommitted": link.LocalChannel.AcksUncommitted,
|
||||
"consumers": link.LocalChannel.ConsumerCount,
|
||||
"messages_unacknowledged": link.LocalChannel.MessagesUnacknowledged,
|
||||
"messages_uncommitted": link.LocalChannel.MessagesUncommitted,
|
||||
"messages_unconfirmed": link.LocalChannel.MessagesUnconfirmed,
|
||||
"messages_confirm": link.LocalChannel.MessageStats.Confirm,
|
||||
"messages_publish": link.LocalChannel.MessageStats.Publish,
|
||||
"messages_return_unroutable": link.LocalChannel.MessageStats.ReturnUnroutable,
|
||||
},
|
||||
tags,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RabbitMQ) shouldGatherNode(node Node) bool {
|
||||
if len(r.Nodes) == 0 {
|
||||
return true
|
||||
@@ -659,13 +753,23 @@ func (r *RabbitMQ) createQueueFilter() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RabbitMQ) shouldGatherExchange(exchange Exchange) bool {
|
||||
func (r *RabbitMQ) createUpstreamFilter() error {
|
||||
upstreamFilter, err := filter.NewIncludeExcludeFilter(r.FederationUpstreamInclude, r.FederationUpstreamExclude)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.upstreamFilter = upstreamFilter
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RabbitMQ) shouldGatherExchange(exchangeName string) bool {
|
||||
if len(r.Exchanges) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, name := range r.Exchanges {
|
||||
if name == exchange.Name {
|
||||
if name == exchangeName {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -673,6 +777,21 @@ func (r *RabbitMQ) shouldGatherExchange(exchange Exchange) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *RabbitMQ) shouldGatherFederationLink(link FederationLink) bool {
|
||||
if !r.upstreamFilter.Match(link.Upstream) {
|
||||
return false
|
||||
}
|
||||
|
||||
switch link.Type {
|
||||
case "exchange":
|
||||
return r.shouldGatherExchange(link.Exchange)
|
||||
case "queue":
|
||||
return r.queueFilter.Match(link.Queue)
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
inputs.Add("rabbitmq", func() telegraf.Input {
|
||||
return &RabbitMQ{
|
||||
|
||||
Reference in New Issue
Block a user