如何在cassandra中使用nodetool查找总键空间大小?

时间:2019-01-29 07:46:21

标签: regex bash awk cassandra-3.0 nodetool

我想为 nodetool tablestats元数据列出的所有表总计“ 已用空间(总计):0 ”。谁能知道该怎么做?请帮忙。

所需代码:为所有表添加已用空间(总计)值;如下所示:

 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

2 个答案:

答案 0 :(得分:1)

请您尝试以下操作(因为您没有提到示例,因此无法对其进行测试)。

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

答案 1 :(得分:0)

我得到了答案,我在awk语句中拼写了'END'命令,如下所示进行了纠正:

nodetool tablestats metadata -H | awk '/Space used \(total\):/ {sum += $4} END {print sum}'