Skip to content

Commit

Permalink
Nodetool command to get dynamic snitch scores (#122)
Browse files Browse the repository at this point in the history
* snitch scores

* handle when dynamic snitch not used

* formatting
  • Loading branch information
amandachow authored and Mattheo committed Sep 10, 2020
1 parent d3c4c9f commit 5c7de03
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/java/org/apache/cassandra/tools/NodeProbe.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.apache.cassandra.gms.FailureDetectorMBean;
import org.apache.cassandra.gms.Gossiper;
import org.apache.cassandra.gms.GossiperMBean;
import org.apache.cassandra.locator.DynamicEndpointSnitchMBean;
import org.apache.cassandra.locator.EndpointSnitchInfoMBean;
import org.apache.cassandra.metrics.CassandraMetricsRegistry;
import org.apache.cassandra.metrics.ColumnFamilyMetrics.Sampler;
Expand Down Expand Up @@ -726,6 +727,18 @@ public void truncate(String keyspaceName, String cfName)
}
}

public DynamicEndpointSnitchMBean getDynamicEndpointSnitchProxy()
{
try
{
return JMX.newMBeanProxy(mbeanServerConn, new ObjectName("org.apache.cassandra.db:type=DynamicEndpointSnitch"), DynamicEndpointSnitchMBean.class);
}
catch (MalformedObjectNameException e)
{
throw new RuntimeException(e);
}
}

public EndpointSnitchInfoMBean getEndpointSnitchInfoProxy()
{
try
Expand Down
3 changes: 2 additions & 1 deletion src/java/org/apache/cassandra/tools/NodeTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ public int execute(String... args)
GetLoggingLevels.class,
FailureDetectorInfo.class,
RefreshSizeEstimates.class,
ForceTerminateRepairSessions.class
ForceTerminateRepairSessions.class,
DynamicEndpointSnitchStats.class
);

Cli.CliBuilder<Consumer<INodeProbeFactory>> builder = Cli.builder("nodetool");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.cassandra.tools.nodetool;

import static java.lang.String.format;
import io.airlift.command.Command;

import java.net.InetAddress;
import java.util.List;
import java.util.Map;

import javax.management.InstanceNotFoundException;

import org.apache.cassandra.locator.DynamicEndpointSnitch;
import org.apache.cassandra.locator.DynamicEndpointSnitchMBean;
import org.apache.cassandra.tools.NodeProbe;
import org.apache.cassandra.tools.NodeTool.NodeToolCmd;

@Command(name = "dynamicendpointsnitchstats", description = "Print the dynamic snitch configurations of a cluster and the current scores of all nodes")
public class DynamicEndpointSnitchStats extends NodeToolCmd
{
@Override
public void execute(NodeProbe probe)
{
try
{
DynamicEndpointSnitchMBean dynamicSnitchProxy = probe.getDynamicEndpointSnitchProxy();
// display snitch configuration
System.out.println("Dynamic Endpoint Snitch Configuration:");
System.out.println("\tUpdate Interval (ms): " + dynamicSnitchProxy.getUpdateInterval());
System.out.println("\tReset Interval (ms): " + dynamicSnitchProxy.getResetInterval());
System.out.println("\tBadness Threshold: " + dynamicSnitchProxy.getBadnessThreshold());
System.out.println("\tSubsnitch: " + dynamicSnitchProxy.getSubsnitchClassName());
System.out.println("\tSeverity: " + dynamicSnitchProxy.getSeverity());
// display snitch scores for each node
System.out.println("Dynamic Endpoint Snitch Scores:");
Map<InetAddress, Double> snitchScores = dynamicSnitchProxy.getScores();
for (InetAddress address : snitchScores.keySet())
{
System.out.println(format("\t%s: %s", address.getCanonicalHostName(), snitchScores.get(address)));
}
} catch (RuntimeException e) {
if ((e.getCause() instanceof InstanceNotFoundException)) {
System.out.println("Error getting DynamicEndpointSnitch proxy--Dynamic snitch may not be enabled on this cluster.");
}
}

}
}

0 comments on commit 5c7de03

Please sign in to comment.