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

feat:Add exchanges filtering capabilities #275

Merged
merged 1 commit into from
May 17, 2022
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ SKIP_VHOST | ^$ |regex, matching vhost names are not exported. First performs IN
INCLUDE_VHOST | .* | regex vhost filter. Only queues in matching vhosts are exported
INCLUDE_QUEUES | .* | regex queue filter. Just matching names are exported
SKIP_QUEUES | ^$ |regex, matching queue names are not exported (useful for short-lived rpc queues). First performed INCLUDE, after SKIP
INCLUDE_EXCHANGES | .* | regex exchange filter. (Only exchanges in matching vhosts are exported)
SKIP_EXCHANGES | ^$ | regex, matching exchanges names are not exported. First performed INCLUDE, after SKIP
RABBIT_CAPABILITIES | bert,no_sort | comma-separated list of extended scraping capabilities supported by the target RabbitMQ server
RABBIT_EXPORTERS | exchange,node,queue | List of enabled modules. Possible modules: connections,shovel,federation,exchange,node,queue,memory
RABBIT_TIMEOUT | 30 | timeout in seconds for retrieving data from management plugin.
Expand Down
2 changes: 2 additions & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"key_file": "client-key.pem",
"insecure_skip_verify": false,
"exlude_metrics": [],
"include_exchanges": ".*",
"skip_exchanges": "^$",
"include_queues": ".*",
"skip_queues": "^$",
"skip_vhost": "^$",
Expand Down
16 changes: 16 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var (
KeyFile: "client-key.pem",
InsecureSkipVerify: false,
ExcludeMetrics: []string{},
SkipExchanges: regexp.MustCompile("^$"),
IncludeExchanges: regexp.MustCompile(".*"),
SkipQueues: regexp.MustCompile("^$"),
IncludeQueues: regexp.MustCompile(".*"),
SkipVHost: regexp.MustCompile("^$"),
Expand All @@ -49,10 +51,14 @@ type rabbitExporterConfig struct {
KeyFile string `json:"key_file"`
InsecureSkipVerify bool `json:"insecure_skip_verify"`
ExcludeMetrics []string `json:"exlude_metrics"`
SkipExchanges *regexp.Regexp `json:"-"`
IncludeExchanges *regexp.Regexp `json:"-"`
SkipQueues *regexp.Regexp `json:"-"`
IncludeQueues *regexp.Regexp `json:"-"`
SkipVHost *regexp.Regexp `json:"-"`
IncludeVHost *regexp.Regexp `json:"-"`
IncludeExchangesString string `json:"include_exchanges"`
SkipExchangesString string `json:"skip_exchanges"`
IncludeQueuesString string `json:"include_queues"`
SkipQueuesString string `json:"skip_queues"`
SkipVHostString string `json:"skip_vhost"`
Expand Down Expand Up @@ -91,6 +97,8 @@ func initConfigFromFile(configFile string) error {
}
}

config.SkipExchanges = regexp.MustCompile(config.SkipExchangesString)
config.IncludeExchanges = regexp.MustCompile(config.IncludeExchangesString)
config.SkipQueues = regexp.MustCompile(config.SkipQueuesString)
config.IncludeQueues = regexp.MustCompile(config.IncludeQueuesString)
config.SkipVHost = regexp.MustCompile(config.SkipVHostString)
Expand Down Expand Up @@ -173,6 +181,14 @@ func initConfig() {
config.ExcludeMetrics = strings.Split(ExcludeMetrics, ",")
}

if SkipExchanges := os.Getenv("SKIP_EXCHANGES"); SkipExchanges != "" {
config.SkipExchanges = regexp.MustCompile(SkipExchanges)
}

if IncludeExchanges := os.Getenv("INCLUDE_EXCHANGES"); IncludeExchanges != "" {
config.IncludeExchanges = regexp.MustCompile(IncludeExchanges)
}

if SkipQueues := os.Getenv("SKIP_QUEUES"); SkipQueues != "" {
config.SkipQueues = regexp.MustCompile(SkipQueues)
}
Expand Down
14 changes: 14 additions & 0 deletions exporter_exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ func (e exporterExchange) Collect(ctx context.Context, ch chan<- prometheus.Metr

for key, countvec := range e.exchangeMetrics {
for _, exchange := range exchangeData {
ename := exchange.labels["name"]
vname := exchange.labels["vhost"]
if vhostIncluded := config.IncludeVHost.MatchString(vname); !vhostIncluded {
continue
}
if skipVhost := config.SkipVHost.MatchString(vname); skipVhost {
continue
}
if exchangeIncluded := config.IncludeExchanges.MatchString(ename); !exchangeIncluded {
continue
}
if exchangeSkipped := config.SkipExchanges.MatchString(ename); exchangeSkipped {
continue
}
if value, ok := exchange.metrics[key]; ok {
// log.WithFields(log.Fields{"vhost": exchange.vhost, "exchange": exchange.name, "key": key, "value": value}).Debug("Set exchange metric for key")
ch <- prometheus.MustNewConstMetric(countvec, prometheus.CounterValue, value, cluster, exchange.labels["vhost"], exchange.labels["name"])
Expand Down
Loading