From 2553aa67273de482a644ee15ab9379c68c0850f6 Mon Sep 17 00:00:00 2001 From: Jonathan Ballet Date: Tue, 25 May 2021 16:54:00 +0200 Subject: [PATCH] Exclude keyspaces matching regex patterns Instead of matching a specific keyspace name, --exclude-keyspaces now takes a regex as an argument; every keyspaces which match the regex will be ignored. This is not entirely backward compatible, as `--exclude-keyspaces=foobar` will exclude `foobar`, but also `some_foobar_keyspace` as well. --- README.md | 2 +- .../cassandra/exporter/FactoriesSupplier.java | 2 +- .../cassandra/exporter/cli/HarvesterOptions.java | 3 ++- .../StorageServiceMBeanMetricFamilyCollector.java | 2 +- install-ccm.sh | 12 +++++++++--- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c14e86f..ba943a2 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ The available command line options may be seen by passing `-h`/`--help`: Record the cumulative time taken to run each collector and export the results. --exclude-keyspaces= - + Exclude keyspaces matching the specified regex pattern. -e, --exclude=EXCLUSION... Exclude a metric family or MBean from exposition. EXCLUSION may be the full name of a metric family diff --git a/common/src/main/java/com/zegelin/cassandra/exporter/FactoriesSupplier.java b/common/src/main/java/com/zegelin/cassandra/exporter/FactoriesSupplier.java index 2d88503..2f369bd 100644 --- a/common/src/main/java/com/zegelin/cassandra/exporter/FactoriesSupplier.java +++ b/common/src/main/java/com/zegelin/cassandra/exporter/FactoriesSupplier.java @@ -370,7 +370,7 @@ private Iterator tableMetricFactory(final Set tableMe final String keyspaceName = keyPropertyList.get("keyspace"); - if (excludedKeyspaces.contains(keyspaceName)) { + if (excludedKeyspaces.stream().anyMatch(p -> keyspaceName.matches(p))) { return false; } diff --git a/common/src/main/java/com/zegelin/cassandra/exporter/cli/HarvesterOptions.java b/common/src/main/java/com/zegelin/cassandra/exporter/cli/HarvesterOptions.java index dea9e82..1623b50 100644 --- a/common/src/main/java/com/zegelin/cassandra/exporter/cli/HarvesterOptions.java +++ b/common/src/main/java/com/zegelin/cassandra/exporter/cli/HarvesterOptions.java @@ -140,7 +140,8 @@ public void setNoFastFloat(final boolean noFastFloat) { public boolean collectorTimingEnabled; - @Option(names = "--exclude-keyspaces") + @Option(names = "--exclude-keyspaces", + description = "Exclude keyspaces matching the specified regex pattern.") public Set excludedKeyspaces = new HashSet<>(); @Option(names = "--exclude-system-tables", diff --git a/common/src/main/java/com/zegelin/cassandra/exporter/collector/StorageServiceMBeanMetricFamilyCollector.java b/common/src/main/java/com/zegelin/cassandra/exporter/collector/StorageServiceMBeanMetricFamilyCollector.java index f7cc897..cd80c45 100644 --- a/common/src/main/java/com/zegelin/cassandra/exporter/collector/StorageServiceMBeanMetricFamilyCollector.java +++ b/common/src/main/java/com/zegelin/cassandra/exporter/collector/StorageServiceMBeanMetricFamilyCollector.java @@ -93,7 +93,7 @@ public Stream collect() { { final Stream ownershipMetricStream = metadataFactory.keyspaces().stream() - .filter(keyspace -> !excludedKeyspaces.contains(keyspace)) + .filter(keyspace -> !excludedKeyspaces.stream().anyMatch(p -> keyspace.matches(p))) .flatMap(keyspace -> { try { return storageServiceMBean.effectiveOwnership(keyspace).entrySet().stream() diff --git a/install-ccm.sh b/install-ccm.sh index a86c7fc..7f01612 100755 --- a/install-ccm.sh +++ b/install-ccm.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash +HERE="$(dirname "$(readlink -f "$0")")" + +AGENT="$HERE/agent/target/cassandra-exporter-agent-0.9.11-SNAPSHOT.jar" + find . -path '*/node*/conf/cassandra-env.sh' | while read file; do echo "Processing $file" @@ -7,6 +11,8 @@ find . -path '*/node*/conf/cassandra-env.sh' | while read file; do sed -i -e "/cassandra-exporter/d" "${file}" - echo "JVM_OPTS=\"\$JVM_OPTS -javaagent:/home/adam/Projects/cassandra-exporter/agent/target/cassandra-exporter-agent-0.9.4-SNAPSHOT.jar=--listen=:${port},--cache=true,--enable-collector-timing\"" >> \ - "${file}" -done; \ No newline at end of file + cat <> "${file}" +JVM_OPTS="\$JVM_OPTS -javaagent:$AGENT=--listen=:${port},--enable-collector-timing" +EOF + +done;