Add total space used for a keyspace to nodetool tablestats

patch by Arun Ganesh; reviewed by Stefan Miklosovic, Brad Schoening for CASSANDRA-19671

Co-authored-by: Stefan Miklosovic <smiklosovic@apache.org>
This commit is contained in:
Arun Ganesh 2024-06-03 15:14:17 -07:00 committed by Stefan Miklosovic
parent 219eea33b6
commit b9f900947a
No known key found for this signature in database
GPG Key ID: 32F35CB2F546D93E
6 changed files with 45 additions and 1 deletions

View File

@ -1,4 +1,5 @@
5.1
* Add total space used for a keyspace to nodetool tablestats (CASSANDRA-19671)
* Ensure Relation#toRestriction() handles ReversedType properly (CASSANDRA-19950)
* Add JSON and YAML output option to nodetool gcstats (CASSANDRA-19771)
* Introduce metadata serialization version V4 (CASSANDRA-19970)

View File

@ -1958,7 +1958,21 @@ public class NodeProbe implements AutoCloseable
case "WriteTotalLatency":
case "ReadTotalLatency":
case "PendingFlushes":
return JMX.newMBeanProxy(mbeanServerConn, oName, CassandraMetricsRegistry.JmxCounterMBean.class).getCount();
{
// these are gauges for keyspace metrics, not counters
if (!Strings.isNullOrEmpty(ks) &&
Strings.isNullOrEmpty(cf) &&
(metricName.equals("TotalDiskSpaceUsed") ||
metricName.equals("LiveDiskSpaceUsed") ||
metricName.equals("MemtableSwitchCount")))
{
return JMX.newMBeanProxy(mbeanServerConn, oName, CassandraMetricsRegistry.JmxGaugeMBean.class).getValue();
}
else
{
return JMX.newMBeanProxy(mbeanServerConn, oName, CassandraMetricsRegistry.JmxCounterMBean.class).getCount();
}
}
case "CoordinatorReadLatency":
case "CoordinatorScanLatency":
case "ReadLatency":

View File

@ -34,6 +34,8 @@ public class StatsKeyspace
public long readCount;
public long writeCount;
public int pendingFlushes;
public long spaceUsedLive;
public long spaceUsedTotal;
private double totalReadTime;
private double totalWriteTime;
@ -43,6 +45,12 @@ public class StatsKeyspace
this.name = keyspaceName;
}
public void initialize()
{
spaceUsedLive = (long) probe.getColumnFamilyMetric(name, null, "LiveDiskSpaceUsed");
spaceUsedTotal = (long) probe.getColumnFamilyMetric(name, null, "TotalDiskSpaceUsed");
}
public void add(ColumnFamilyStoreMBean table)
{
String tableName = table.getTableName();

View File

@ -82,6 +82,8 @@ public class TableStatsHolder implements StatsHolder
mpKeyspace.put("write_count", keyspace.writeCount);
mpKeyspace.put("write_latency_ms", keyspace.writeLatency());
mpKeyspace.put("pending_flushes", keyspace.pendingFlushes);
mpKeyspace.put("space_used_live", format(keyspace.spaceUsedLive, humanReadable));
mpKeyspace.put("space_used_total", format(keyspace.spaceUsedTotal, humanReadable));
// store each table's metrics to map
List<StatsTable> tables = keyspace.tables;
@ -197,6 +199,7 @@ public class TableStatsHolder implements StatsHolder
if (stats == null)
{
stats = new StatsKeyspace(probe, keyspaceName);
stats.initialize();
keyspaceStats.put(keyspaceName, stats);
}
stats.add(tableProxy);

View File

@ -67,6 +67,8 @@ public class TableStatsPrinter<T extends StatsHolder>
out.println("\tWrite Count: " + keyspace.writeCount);
out.println("\tWrite Latency: " + FBUtilities.prettyPrintLatency(keyspace.writeLatency()));
out.println("\tPending Flushes: " + keyspace.pendingFlushes);
out.println("\tSpace used (live): " + formatDataSize(keyspace.spaceUsedLive, data.humanReadable));
out.println("\tSpace used (total): " + formatDataSize(keyspace.spaceUsedTotal, data.humanReadable));
// print each table's information
List<StatsTable> tables = keyspace.tables;

View File

@ -523,6 +523,8 @@ public class TableStatsPrinterTest extends TableStatsTestBase
"\tWrite Count: 12\n" +
"\tWrite Latency: 0.000 ms\n" +
"\tPending Flushes: 233666\n" +
"\tSpace used (live): 0\n" +
"\tSpace used (total): 0\n" +
String.format(duplicateTabs(expectedDefaultTable1Output), "table1") +
String.format(duplicateTabs(expectedDefaultTable2Output), "table2") +
String.format(duplicateTabs(expectedDefaultTable3Output), "table3") +
@ -533,6 +535,8 @@ public class TableStatsPrinterTest extends TableStatsTestBase
"\tWrite Count: 3\n" +
"\tWrite Latency: 0.000 ms\n" +
"\tPending Flushes: 4449\n" +
"\tSpace used (live): 0\n" +
"\tSpace used (total): 0\n" +
String.format(duplicateTabs(expectedDefaultTable4Output), "table4") +
String.format(duplicateTabs(expectedDefaultTable5Output), "table5") +
"----------------\n" +
@ -542,6 +546,8 @@ public class TableStatsPrinterTest extends TableStatsTestBase
"\tWrite Count: 0\n" +
"\tWrite Latency: NaN ms\n" +
"\tPending Flushes: 66\n" +
"\tSpace used (live): 0\n" +
"\tSpace used (total): 0\n" +
String.format(duplicateTabs(expectedDefaultTable6Output), "table6") +
"----------------\n";
@ -559,6 +565,8 @@ public class TableStatsPrinterTest extends TableStatsTestBase
"\tWrite Count: 12\n" +
"\tWrite Latency: 0.000 ms\n" +
"\tPending Flushes: 233666\n" +
"\tSpace used (live): 0 bytes\n" +
"\tSpace used (total): 0 bytes\n" +
String.format(duplicateTabs(expectedDefaultHumanReadableTable1Output), "table1") +
String.format(duplicateTabs(expectedDefaultHumanReadableTable2Output), "table2") +
String.format(duplicateTabs(expectedDefaultHumanReadableTable3Output), "table3") +
@ -569,6 +577,8 @@ public class TableStatsPrinterTest extends TableStatsTestBase
"\tWrite Count: 3\n" +
"\tWrite Latency: 0.000 ms\n" +
"\tPending Flushes: 4449\n" +
"\tSpace used (live): 0 bytes\n" +
"\tSpace used (total): 0 bytes\n" +
String.format(duplicateTabs(expectedDefaultHumanReadableTable4Output), "table4") +
String.format(duplicateTabs(expectedDefaultHumanReadableTable5Output), "table5") +
"----------------\n" +
@ -578,6 +588,8 @@ public class TableStatsPrinterTest extends TableStatsTestBase
"\tWrite Count: 0\n" +
"\tWrite Latency: NaN ms\n" +
"\tPending Flushes: 66\n" +
"\tSpace used (live): 0 bytes\n" +
"\tSpace used (total): 0 bytes\n" +
String.format(duplicateTabs(expectedDefaultHumanReadableTable6Output), "table6") +
"----------------\n";
@ -746,9 +758,11 @@ public class TableStatsPrinterTest extends TableStatsTestBase
" }\n" +
" },\n" +
" \"read_latency_ms\" : 0.0,\n" +
" \"space_used_live\" : \"0\",\n" +
" \"pending_flushes\" : 66,\n" +
" \"write_count\" : 0,\n" +
" \"read_latency\" : 0.0,\n" +
" \"space_used_total\" : \"0\",\n" +
" \"read_count\" : 5\n" +
" },\n" +
" \"total_number_of_tables\" : 0\n" +
@ -813,9 +827,11 @@ public class TableStatsPrinterTest extends TableStatsTestBase
" percent_repaired: 0.0\n" +
" space_used_by_snapshots_total: '0'\n" +
" read_latency_ms: 0.0\n" +
" space_used_live: '0'\n" +
" pending_flushes: 66\n" +
" write_count: 0\n" +
" read_latency: 0.0\n" +
" space_used_total: '0'\n" +
" read_count: 5\n" +
"total_number_of_tables: 0\n" +
"\n");