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

More options added #16

Closed
wants to merge 18 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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ dependency-reduced-pom.xml
*.releaseBackup
release.properties

*.srl

55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,17 @@ The available command line options may be seen by passing `-h`/`--help`:
[--jmx-service-url=URL] [--jmx-user=NAME]
[--keyspace-metrics=FILTER] [--node-metrics=FILTER]
[--table-metrics=FILTER]
[--exclude-keyspaces=<excludedKeyspaces>]... [-g=LABEL
[--exclude-keyspaces=<excludedKeyspaces>]...
[--ssl=MODE]
[--ssl-client-authentication=CLIENT-AUTHENTICATION]
[--ssl-implementation=IMPLEMENTATION]
[--ssl-reload-interval=SECONDS]
[--ssl-server-certificate=SERVER-CERTIFICATE]
[--ssl-server-key=SERVER-KEY]
[--ssl-server-key-password=SERVER-KEY-PASSWORD]
[--ssl-trusted-certificate=TRUSTED-CERTIFICATE]
[--ssl-ciphers=CIPHER[,CIPHER...]]...
[--ssl-protocols=PROTOCOL[,PROTOCOL...]]... [-g=LABEL
[,LABEL...]]... [-l=[ADDRESS][:PORT]]... [-t=LABEL[,
LABEL...]]... [-e=EXCLUSION...]...
-g, --global-labels=LABEL[,LABEL...]
Expand Down Expand Up @@ -180,6 +190,49 @@ The available command line options may be seen by passing `-h`/`--help`:
or PORT will be interpreted as a decimal IPv4 address.
This option may be specified more than once to listen
on multiple addresses. Defaults to '0.0.0.0:9500'
--ssl=MODE Enable or disable secured communication with SSL. Valid
modes: DISABLE, ENABLE, OPTIONAL. Optional support
requires Netty version 4.0.45 or later. Defaults to
DISABLE.
--ssl-implementation=IMPLEMENTATION
SSL implementation to use for secure communication.
OpenSSL requires platform specific libraries. Valid
implementations: OPENSSL, JDK, DISCOVER. Defaults to
DISCOVER which will use OpenSSL if required libraries
are discoverable.
--ssl-ciphers=CIPHER[,CIPHER...]
A comma-separated list of SSL cipher suites to enable,
in the order of preference. Defaults to system
settings.
--ssl-protocols=PROTOCOL[,PROTOCOL...]
A comma-separated list of TLS protocol versions to
enable. Defaults to system settings.
--ssl-reload-interval=SECONDS
Interval in seconds by which keys and certificates will
be reloaded. Defaults to 0 which will disable run-time
reload of certificates.
--ssl-server-key=SERVER-KEY
Path to the private key file for the SSL server. Must be
provided together with a server-certificate. The file
should contain a PKCS#8 private key in PEM format.
--ssl-server-key-password=SERVER-KEY-PASSWORD
Path to the private key password file for the SSL
server. This is only required if the server-key is
password protected. The file should contain a clear
text password for the server-key.
--ssl-server-certificate=SERVER-CERTIFICATE
Path to the certificate chain file for the SSL server.
Must be provided together with a server-key. The file
should contain an X.509 certificate chain in PEM
format.
--ssl-client-authentication=CLIENT-AUTHENTICATION
Set SSL client authentication mode. Valid options: NONE,
OPTIONAL, REQUIRE, VALIDATE. Defaults to NONE.
--ssl-trusted-certificate=TRUSTED-CERTIFICATE
Path to trusted certificates for verifying the remote
endpoint's certificate. The file should contain an X.
509 certificate collection in PEM format. Defaults to
the system setting.
--family-help=VALUE Include or exclude metric family help in the exposition
format. AUTOMATIC excludes help strings when the user
agent is Prometheus and includes them for all other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Void call() throws Exception {

final MBeanServerInterceptorHarvester harvester = new MBeanServerInterceptorHarvester(harvesterOptions);

final Server server = Server.start(httpServerOptions.listenAddresses, harvester, httpServerOptions.helpExposition);
final Server server = Server.start(harvester, httpServerOptions);

Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
Expand Down
12 changes: 12 additions & 0 deletions bin/generate_cert_for_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

RESOURCE_PATH="common/src/test/resources"

# Generate a private key and store it both unecrypted and encrypted (password protected)
# Create a self-signed certificate for the key
mkdir -p ${RESOURCE_PATH}/cert
rm -f ${RESOURCE_PATH}/cert/*
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -outform PEM -out ${RESOURCE_PATH}/cert/key.pem
echo -n "password" > ${RESOURCE_PATH}/cert/protected-key.pass
openssl pkcs8 -topk8 -v1 PBE-SHA1-RC4-128 -in ${RESOURCE_PATH}/cert/key.pem -out ${RESOURCE_PATH}/cert/protected-key.pem -passout file:${RESOURCE_PATH}/cert/protected-key.pass
openssl req -x509 -new -key ${RESOURCE_PATH}/cert/key.pem -sha256 -days 10000 -out ${RESOURCE_PATH}/cert/cert.pem -subj '/CN=localhost/O=Example Company/C=SE' -nodes
26 changes: 25 additions & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,25 @@
<name>Cassandra Exporter Common</name>

<properties>
<version.picocli>3.6.1</version.picocli>
<version.picocli>3.9.5</version.picocli>
</properties>

<dependencies>
<!-- Bring in improved resource leak detection in netty for utests. See #46-->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.0.53.Final</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<scope>provided</scope>
</dependency>


<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
Expand All @@ -46,5 +55,20 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.12.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>2.0.28.Final</version>
<scope>test</scope>
</dependency>


</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package com.zegelin.cassandra.exporter;

import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.zegelin.function.FloatFloatFunction;
import com.zegelin.cassandra.exporter.collector.dynamic.FunctionalMetricFamilyCollector.CollectorFunction;
import com.zegelin.cassandra.exporter.collector.dynamic.FunctionalMetricFamilyCollector.LabeledObjectGroup;
import com.zegelin.prometheus.domain.*;
import com.zegelin.prometheus.domain.Interval.Quantile;

import org.apache.cassandra.metrics.CassandraMetricsRegistry.JmxCounterMBean;
import org.apache.cassandra.metrics.CassandraMetricsRegistry.JmxGaugeMBean;
import org.apache.cassandra.metrics.CassandraMetricsRegistry.JmxMeterMBean;
import org.apache.cassandra.utils.EstimatedHistogram;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public final class CollectorFunctions {
Expand Down Expand Up @@ -124,7 +133,8 @@ public static CollectorFunction<JmxGaugeMBean> numericGaugeAsCounter() {
/**
* Collect a {@link JmxGaugeMBean} with a Cassandra {@link EstimatedHistogram} value as a Prometheus summary
*/
public static CollectorFunction<JmxGaugeMBean> histogramGaugeAsSummary(final FloatFloatFunction bucketScaleFunction) {
public static CollectorFunction<JmxGaugeMBean> histogramGaugeAsSummary(final FloatFloatFunction bucketScaleFunction,Set<Quantile> excludeQuantiles) {
Set<Quantile> includedQuantiles =excludeQuantiles==null?Interval.Quantile.STANDARD_PERCENTILES:Sets.difference(Interval.Quantile.STANDARD_PERCENTILES,excludeQuantiles);
return group -> {
final Stream<SummaryMetricFamily.Summary> summaryStream = group.labeledObjects().entrySet().stream()
.map(e -> new Object() {
Expand All @@ -135,12 +145,11 @@ public static CollectorFunction<JmxGaugeMBean> histogramGaugeAsSummary(final Flo
final long[] bucketData = (long[]) e.gauge.getValue();

if (bucketData.length == 0) {
return new SummaryMetricFamily.Summary(e.labels, Float.NaN, Float.NaN, Interval.asIntervals(Interval.Quantile.STANDARD_PERCENTILES, q -> Float.NaN));
return new SummaryMetricFamily.Summary(e.labels, Float.NaN, Float.NaN, Interval.asIntervals(includedQuantiles, q -> Float.NaN));
}

final EstimatedHistogram histogram = new EstimatedHistogram(bucketData);

final Iterable<Interval> quantiles = Interval.asIntervals(Interval.Quantile.STANDARD_PERCENTILES, q -> bucketScaleFunction.apply((float) histogram.percentile(q.value)));
final Iterable<Interval> quantiles = Interval.asIntervals(includedQuantiles, q -> bucketScaleFunction.apply((float) histogram.percentile(q.value)));

return new SummaryMetricFamily.Summary(e.labels, Float.NaN, histogram.count(), quantiles);
});
Expand All @@ -149,31 +158,41 @@ public static CollectorFunction<JmxGaugeMBean> histogramGaugeAsSummary(final Flo
};
}

public static CollectorFunction<JmxGaugeMBean> histogramGaugeAsSummary() {
return histogramGaugeAsSummary(l -> l);
public static CollectorFunction<JmxGaugeMBean> histogramGaugeAsSummary(Set<Quantile> excludeQuantiles) {
return histogramGaugeAsSummary((l -> l),excludeQuantiles);
}

/**
* Collect a {@link SamplingCounting} as a Prometheus summary
*/
protected static CollectorFunction<SamplingCounting> samplingAndCountingAsSummary(final FloatFloatFunction quantileScaleFunction) {
protected static CollectorFunction<SamplingCounting> samplingAndCountingAsSummary(final FloatFloatFunction quantileScaleFunction,Set<Quantile> excludeQuantiles) {
return group -> {
final Stream<SummaryMetricFamily.Summary> summaryStream = group.labeledObjects().entrySet().stream()
.map(e -> new Object() {
final Labels labels = e.getKey();
final SamplingCounting samplingCounting = e.getValue();
})
.map(e -> {
final Iterable<Interval> quantiles = Iterables.transform(e.samplingCounting.getIntervals(), i -> i.transform(quantileScaleFunction));


Iterator<Interval> itr = e.samplingCounting.getIntervals().iterator();
ArrayList<Interval> filtered = Lists.newArrayList();
while(itr.hasNext()) {
Interval interval = itr.next();
if(excludeQuantiles.contains(interval.quantile)) {
continue;
}
filtered.add(interval);
}

final Iterable<Interval> quantiles = Iterables.transform(filtered, i -> i.transform(quantileScaleFunction));
return new SummaryMetricFamily.Summary(e.labels, Float.NaN, e.samplingCounting.getCount(), quantiles);
});

return Stream.of(new SummaryMetricFamily(group.name(), group.help(), summaryStream));
};
}

public static CollectorFunction<SamplingCounting> samplingAndCountingAsSummary() {
return samplingAndCountingAsSummary(FloatFloatFunction.identity());
public static CollectorFunction<SamplingCounting> samplingAndCountingAsSummary(Set<Quantile> excludeQuantiles) {
return samplingAndCountingAsSummary(FloatFloatFunction.identity(),excludeQuantiles);
}
}
Loading