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

Add Streaming metrics #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.zegelin.prometheus.domain.Labels;

import javax.management.*;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
Expand Down Expand Up @@ -179,6 +181,30 @@ private Factory clientMetricFactory(final FactoryBuilder.CollectorConstructor co
.build();
}

private Optional<String> getHostname(String ip) {
try {
return Optional.of(InetAddress.getByName(ip).getHostName());
} catch (UnknownHostException e) {
return Optional.empty();
}
}

private Factory clientStreamingMetricFactory(final FactoryBuilder.CollectorConstructor collectorConstructor, final String jmxName, final String familyNameSuffix, final String help) {
final ObjectName objectNamePattern = format("org.apache.cassandra.metrics:type=Streaming,name=%s,scope=*", jmxName);
final String metricFamilyName = String.format("stream_%s", familyNameSuffix);

return new FactoryBuilder(collectorConstructor, objectNamePattern, metricFamilyName)
.withHelp(help)
.withModifier((keyPropertyList, labels) -> {
final String scope = keyPropertyList.get("scope");
labels.put("partner_endpoint", scope);
getHostname(scope).ifPresent(hostname -> labels.put("partner_hostname", hostname));
return true;
})
.build();

}

private Factory clientRequestMetricFactory(final FactoryBuilder.CollectorConstructor collectorConstructor, final String jmxName, final String familyNameSuffix, final String help) {
final ObjectName objectNamePattern = format("org.apache.cassandra.metrics:type=ClientRequest,name=%s,scope=*", jmxName);
final String metricFamilyName = String.format("client_request_%s", familyNameSuffix);
Expand Down Expand Up @@ -799,6 +825,12 @@ public List<Factory> get() {
builder.add(threadPoolMetric(functionalCollectorConstructor(numericGaugeAsGauge()), "MaxPoolSize", "maximum_tasks", null));
}

// org.apache.cassandra.metrics.Streaming
{
builder.add(clientStreamingMetricFactory(functionalCollectorConstructor(counterAsCounter()), "IncomingBytes", "incoming_bytes", "Streaming incoming bytes"));
builder.add(clientStreamingMetricFactory(functionalCollectorConstructor(counterAsCounter()), "OutgoingBytes", "outgoing_bytes", "Streaming outgoing bytes"));
}


return builder.build();
}
Expand Down