Skip to content

Commit

Permalink
Report network cache info in nodetool
Browse files Browse the repository at this point in the history
Patch by Ningzi Zhan; reviewed by brandonwilliams and smiklosovic for
CASSANDRA-18400
  • Loading branch information
qannap authored and driftx committed May 24, 2023
1 parent dc6ad3f commit 54528bf
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
@@ -1,4 +1,5 @@
4.0.10
* Report network cache info in nodetool (CASSANDRa-18400)
* Partial compaction can resurrect deleted data (CASSANDRA-18507)
* Allow internal address to change with reconnecting snitches (CASSANDRA-16718)
* Fix quoting in toCqlString methods of UDTs and aggregates (CASSANDRA-17918)
Expand Down
5 changes: 5 additions & 0 deletions src/java/org/apache/cassandra/metrics/BufferPoolMetrics.java
Expand Up @@ -31,6 +31,9 @@ public class BufferPoolMetrics
/** Total number of misses */
public final Meter misses;

/** Total threshold for a certain type of buffer pool*/
public final Gauge<Long> capacity;

/** Total size of buffer pools, in bytes, including overflow allocation */
public final Gauge<Long> size;

Expand All @@ -52,6 +55,8 @@ public BufferPoolMetrics(String scope, BufferPool bufferPool)

misses = Metrics.meter(factory.createMetricName("Misses"));

capacity = Metrics.register(factory.createMetricName("Capacity"), bufferPool::memoryUsageThreshold);

overflowSize = Metrics.register(factory.createMetricName("OverflowSize"), bufferPool::overflowMemoryInBytes);

usedSize = Metrics.register(factory.createMetricName("UsedSize"), bufferPool::usedSizeInBytes);
Expand Down
38 changes: 36 additions & 2 deletions src/java/org/apache/cassandra/tools/NodeProbe.java
Expand Up @@ -1404,7 +1404,7 @@ public Object getCacheMetric(String cacheType, String metricName)
new ObjectName("org.apache.cassandra.metrics:type=Cache,scope=" + cacheType + ",name=MissLatency"),
CassandraMetricsRegistry.JmxTimerMBean.class).getDurationUnit();
default:
throw new RuntimeException("Unknown cache metric name.");
throw new RuntimeException("Unknown Cache metric name " + metricName);

}
}
Expand All @@ -1414,6 +1414,40 @@ public Object getCacheMetric(String cacheType, String metricName)
}
}

/**
* Retrieve buffer pool metrics based on the buffer pool type
* @param poolType networking chunk-cache
* @param metricName UsedSize Size
* @return
*/
public Object getBufferPoolMetric(String poolType, String metricName)
{
try
{
switch (metricName)
{
case "UsedSize":
case "OverflowSize":
case "Capacity":
case "Size":
return JMX.newMBeanProxy(mbeanServerConn,
new ObjectName("org.apache.cassandra.metrics:type=BufferPool,scope=" + poolType + ",name=" + metricName),
CassandraMetricsRegistry.JmxGaugeMBean.class).getValue();
case "Hits":
case "Misses":
return JMX.newMBeanProxy(mbeanServerConn,
new ObjectName("org.apache.cassandra.metrics:type=BufferPool,scope=" + poolType + ",name=" + metricName),
CassandraMetricsRegistry.JmxMeterMBean.class).getCount();
default:
throw new RuntimeException("Unknown BufferPool metric name " + metricName);
}
}
catch (MalformedObjectNameException e)
{
throw new RuntimeException(e);
}
}

private static Multimap<String, String> getJmxThreadPools(MBeanServerConnection mbeanServerConn)
{
try
Expand Down Expand Up @@ -1465,7 +1499,7 @@ public Object getThreadPoolMetric(String pathName, String poolName, String metri
case ThreadPoolMetrics.CURRENTLY_BLOCKED_TASKS:
return JMX.newMBeanProxy(mbeanServerConn, oName, JmxReporter.JmxCounterMBean.class).getCount();
default:
throw new AssertionError("Unknown metric name " + metricName);
throw new AssertionError("Unknown ThreadPools metric name " + metricName);
}
}
catch (Exception e)
Expand Down
16 changes: 16 additions & 0 deletions src/java/org/apache/cassandra/tools/nodetool/Info.java
Expand Up @@ -140,6 +140,22 @@ public void execute(NodeProbe probe)
// Chunk cache is not on.
}

// network Cache: capacity, size
try
{
out.printf("%-23s: size %s, overflow size: %s, capacity %s%n", "Network Cache",
FileUtils.stringifyFileSize((long) probe.getBufferPoolMetric("networking", "Size")),
FileUtils.stringifyFileSize((long) probe.getBufferPoolMetric("networking", "OverflowSize")),
FileUtils.stringifyFileSize((long) probe.getBufferPoolMetric("networking", "Capacity")));
}
catch (RuntimeException e)
{
if (!(e.getCause() instanceof InstanceNotFoundException))
throw e;

// network cache is not on.
}

// Global table stats
out.printf("%-23s: %s%%%n", "Percent Repaired", probe.getColumnFamilyMetric(null, null, "PercentRepaired"));

Expand Down

0 comments on commit 54528bf

Please sign in to comment.