Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add group exclusion #127

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ This image is configurable using different flags
| tls.insecure-skip-tls-verify | false | If true, the server's certificate will not be checked for validity |
| topic.filter | .* | Regex that determines which topics to collect |
| group.filter | .* | Regex that determines which consumer groups to collect |
| group.exclude | ^$ | Regex that determines which consumer groups to exclude |
| web.listen-address | :9308 | Address to listen on for web interface and telemetry |
| web.telemetry-path | /metrics | Path under which to expose metrics |
| log.level | info | Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal] |
Expand Down
9 changes: 6 additions & 3 deletions kafka_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type Exporter struct {
client sarama.Client
topicFilter *regexp.Regexp
groupFilter *regexp.Regexp
groupExclude *regexp.Regexp
mu sync.Mutex
useZooKeeperLag bool
zookeeperClient *kazoo.Kazoo
Expand Down Expand Up @@ -113,7 +114,7 @@ func canReadFile(path string) bool {
}

// NewExporter returns an initialized Exporter.
func NewExporter(opts kafkaOpts, topicFilter string, groupFilter string) (*Exporter, error) {
func NewExporter(opts kafkaOpts, topicFilter string, groupFilter string, groupExclude string) (*Exporter, error) {
var zookeeperClient *kazoo.Kazoo
config := sarama.NewConfig()
config.ClientID = clientID
Expand Down Expand Up @@ -191,6 +192,7 @@ func NewExporter(opts kafkaOpts, topicFilter string, groupFilter string) (*Expor
client: client,
topicFilter: regexp.MustCompile(topicFilter),
groupFilter: regexp.MustCompile(groupFilter),
groupExclude: regexp.MustCompile(groupExclude),
useZooKeeperLag: opts.useZooKeeperLag,
zookeeperClient: zookeeperClient,
nextMetadataRefresh: time.Now(),
Expand Down Expand Up @@ -372,7 +374,7 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
}
groupIds := make([]string, 0)
for groupId := range groups.Groups {
if e.groupFilter.MatchString(groupId) {
if e.groupFilter.MatchString(groupId) && !e.groupExclude.MatchString(groupId) {
groupIds = append(groupIds, groupId)
}
}
Expand Down Expand Up @@ -472,6 +474,7 @@ func main() {
metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
topicFilter = kingpin.Flag("topic.filter", "Regex that determines which topics to collect.").Default(".*").String()
groupFilter = kingpin.Flag("group.filter", "Regex that determines which consumer groups to collect.").Default(".*").String()
groupExclude = kingpin.Flag("group.exclude", "Regex that determines which consumer groups to exclude.").Default("^$").String()
logSarama = kingpin.Flag("log.enable-sarama", "Turn on Sarama logging.").Default("false").Bool()

opts = kafkaOpts{}
Expand Down Expand Up @@ -603,7 +606,7 @@ func main() {
sarama.Logger = log.New(os.Stdout, "[sarama] ", log.LstdFlags)
}

exporter, err := NewExporter(opts, *topicFilter, *groupFilter)
exporter, err := NewExporter(opts, *topicFilter, *groupFilter, *groupExclude)
if err != nil {
plog.Fatalln(err)
}
Expand Down