Skip to content

Commit

Permalink
Fix metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ines potier committed Nov 11, 2024
1 parent 69b9a55 commit 3a0d443
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
package com.palantir.cassandra.metrics;

import java.net.InetAddress;
import java.util.Optional;
import java.util.function.Supplier;

import com.google.common.net.InetAddresses;

import com.codahale.metrics.Gauge;
import com.codahale.metrics.Snapshot;
import com.sun.istack.internal.NotNull;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.db.Directories;
import org.apache.cassandra.metrics.CassandraMetricsRegistry;
Expand All @@ -37,7 +39,7 @@ public class FailureDetectorMetrics
static
{
Metrics.register(
new CassandraMetricsRegistry.MetricName(groupName, "FailureDetector", "FailureDetectorPhiThreshold", null), new Gauge<Double>()
createMetricName("FailureDetectorPhiThreshold"), new Gauge<Double>()
{
public Double getValue()
{
Expand All @@ -61,16 +63,25 @@ public static void unregister(InetAddress ep)
Metrics.remove(createMetricName(ep, "FailureDetectorArrivalIntervals"));
}

private static CassandraMetricsRegistry.MetricName createMetricName(InetAddress ep, String name)
private static CassandraMetricsRegistry.MetricName createMetricName(String name)
{
return new CassandraMetricsRegistry.MetricName(groupName, "FailureDetector", name, mBeanName("", name));
}

private static CassandraMetricsRegistry.MetricName createMetricName(@NotNull InetAddress ep, String name)
{
String endpoint = InetAddresses.toAddrString(ep);
return new CassandraMetricsRegistry.MetricName(groupName, "FailureDetector", name, endpoint, mBeanName(endpoint, name));
}

private static String mBeanName(String endpoint, String name)
{
StringBuilder mbeanName = new StringBuilder();
mbeanName.append(groupName).append(":");
mbeanName.append("type=FailureDetector");
mbeanName.append(",endpoint=").append(endpoint);
if(!endpoint.isEmpty())
mbeanName.append(",endpoint=").append(endpoint);
mbeanName.append(",name=").append(name);

return new CassandraMetricsRegistry.MetricName(groupName, "FailureDetector", name, endpoint, mbeanName.toString());
return mbeanName.toString();
}
}

0 comments on commit 3a0d443

Please sign in to comment.