18

Recently I've started working on Grails integration with Cassandra using the Java driver for cassandra(cassandra-driver-core-2.0.2). So I was curious to know how we can find out how much size our table is taking to store the data in cassandra DB.

I have created a keyspace with name Customkeyspace and a column family called Movie in it. So I was curious to know which tool/Command I have to use to know the size of the keyspace/Column family ?

JavaRookie
  • 225
  • 1
  • 2
  • 9
  • Cassandra doesn't deal with tables but with `Column`s and `SuperColumn`s in a `KeySpace`. Also, These columns and SuperColumns can be clustered. Essentially, do you want to size the `KeySpace`? – Buhake Sindi Nov 19 '14 at 08:29
  • Thanks for the information, Yes I am interested in Knowing the size of a Keyspace as well as the Column family. – JavaRookie Nov 19 '14 at 08:32

4 Answers4

24

To get statistics regarding column families in Cassandra, you can simply run the command:

nodetool cfstats

It reports statistics about tables which include the live data size as well as on disk.

The documentation about this utility for Cassandra 2.1 is available here.

Tyler Dane
  • 951
  • 1
  • 14
  • 25
Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
  • 1
    So I run this command(nodetool cfstats) in the nodetool.I got this information-Table: movie SSTable count: 0 Space used (live): 0 Space used (total): 0 Space used by snapshots (total): 0 SSTable Compression Ratio: 0.0 Memtable cell count: 1887 Memtable data size: 49225....So why the no of bytes taken is showing in the Memtable data size ? Why the size is coming 0 in Space used(Live) and Space used(Total) ?..Furthermore if a user wants to know how much data size a row is taking in cassandra for a particular Column family ? how can we do that ? – JavaRookie Nov 19 '14 at 11:11
  • I would suspect it's because when your ran `nodetool cfstats`, you have just created the table and haven't flushed your writes to disk yet. – Erick Ramirez Feb 08 '15 at 01:16
7

I've created a small script to print nodetool results in a nice table:

#!/bin/sh
nodetool cfstats -H | awk -F ' *: *' '
  BEGIN { print "Keyspace,Table,Live,Total" }
  /^Keyspace : / { ks = $2 }
  /\tTable:/ { t = $2 }
  /\tSpace used .live/ { sp = $2 }
  /\tSpace used .total/ { print ks "," t "," sp "," $2 }
' | column -s , -t
lapo
  • 3,136
  • 26
  • 34
1

To get the statistics regarding column families in Cassandra with respect to keyspaces or tables, you can simply run the below command:

nodetool cfstats

Result: This will return the complete statistics related to available keyspaces.

But, in case you want to find out the statistics of specific keyspaces or tables, run below command:

For Keyspace(s) : nodetool cfstats <keyspace_name> OR nodetool cfstats -H <keyspace_name>

For Table(s) : nodetool tablestats <keyspace_name>.<table_name> OR nodetool tablestats -H <keyspace_name>.<table_name>

Note: -H denotes Human Readable format

For more details please refer, nodetool cfstats

Findings:

  1. You might see SSTable count as 0

  2. Space used (live) and Space used (total) as 0 bytes

To know WHY(s) of the above two findings please refer: Reason of why SSTable count shown as 0

Phuong Vu
  • 527
  • 4
  • 16
Vikash Choudhary
  • 1,439
  • 12
  • 9
  • @vikash-kumar-choudharyThe link showing the reason is broken. Can you please update? – Ish Jun 21 '19 at 07:27
  • Hi @Phuong Vu, For me, it's working. If you still face the issue, click on the given link to see the details: http://distributeddatastore.blogspot.com/2013/08/cassandra-sstable-storage-format.html – Vikash Choudhary Jun 21 '19 at 12:17
0

You can use both the command below based on old and new version of Cassandra.

nodetool cfstats or nodetool tablestats

Above command will give you size details about keyspace and table. Also you can refer below link to get more ddetails about how to use with different options https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/tools/nodetool/toolsTablestats.html

LetsNoSQL
  • 1,478
  • 1
  • 11
  • 23