regexbashawkcassandranodetool

how to find total keyspace size using nodetool in cassandra?


I want to sum "Space used (total): 0" for all tables listed by nodetool tablestats metadata. can anyone have idea how to do this? please help.

Desired code: Add Space used (total) value for all tables; like below:

 for Table: dbtimestamp 
         size += value(Space used (total)) 
         Table: dbtimestamp_compressed 
         size += value((Space used (total)) 
         Table: migration_status 
         size += value((Space used (total))



----------------------------------------------------------------------------

nodetool tablestats metadata
    Total number of tables: 584
    ----------------
    Keyspace : metadata
            Read Count: 296
            Read Latency: 0.23686486486486488 ms
            Write Count: 68611
            Write Latency: 0.02151582107825276 ms
            Pending Flushes: 0
                    Table: dbtimestamp
                    SSTable count: 0
                    Space used (live): 0
                    Space used (total): 0
                    Space used by snapshots (total): 0
                    Off heap memory used (total): 0

                    Table: dbtimestamp_compressed
                    SSTable count: 0
                    Space used (live): 0
                    Space used (total): 0
                    Space used by snapshots (total): 0
                    Off heap memory used (total): 0

                    Table: migration_status
                    SSTable count: 2
                    Space used (live): 13014
                    Space used (total): 13014
                    Space used by snapshots (total): 0
                    Off heap memory used (total): 80

                    Table: reporttimestamp_by_type
                    SSTable count: 2
                    Space used (live): 121332
                    Space used (total): 121332
                    Space used by snapshots (total): 0
                    Off heap memory used (total): 112

Solution

  • Could you please try following(since you haven't mentioned samples so couldn't test it).

    awk '/Space used \(total\)/{sum+=$NF} END{print sum}'  Input_file