了解Cassandra集群的性能特點有助於診斷和維護Cassandra。由於Cassandra使用JAVA開發的,所以它就提供了JMX環境下的一些管理工具來管理Cassandra,它們包括:Cassandra nodetool工具、DataStax OpsCenter管理控制台和JConsole。
使用nodetool工具
nodetool是一個命令行的工具集,它可以監控Cassandra和執行例行的數據庫操作。作為內建的工具,nodetool一般用於在節點上直接運行。
nodetool工具集支持大多數重要的JMX指標和操作,並且包含了一些為管理員准備的命令。這個工具集用得最多的還是輸出集群環的快速摘要和集群的當前狀況——也就是nodetool status。
nodetool工具集提供了一批用於查看表的指標、服務器指標和壓縮統計。
- nodetool cfstats顯示了每個表和keyspace的統計數據
- nodetool cfhistograms提供了表的統計數據,包括讀寫延遲,行大小,列的數量和SSTable的數量。
- nodetool netstats提供了網絡連接操作的統計數據。
- nodetool tpstats提供了如active、pending以及完成的任務等Cassandra操作的每個階段的狀態。
示例:
nodetool cfstats命令:
D:\EBOOK\NoSQL\apache-cassandra-2.2.6\bin>nodetool cfstats Starting NodeTool Keyspace: system_traces Read Count: 0 Read Latency: NaN ms. Write Count: 0 Write Latency: NaN ms. Pending Flushes: 0 Table: events SSTable count: 0 Space used (live): 0 Space used (total): 0 Space used by snapshots (total): 0 Off heap memory used (total): 0 SSTable Compression Ratio: 0.0 Number of keys (estimate): -1 Memtable cell count: 0 Memtable data size: 0 Memtable off heap memory used: 0 Memtable switch count: 0 Local read count: 0 Local read latency: NaN ms Local write count: 0 Local write latency: NaN ms Pending flushes: 0 Bloom filter false positives: 0 Bloom filter false ratio: 0.00000 Bloom filter space used: 0 Bloom filter off heap memory used: 0 Index summary off heap memory used: 0 Compression metadata off heap memory used: 0 Compacted partition minimum bytes: 0 Compacted partition maximum bytes: 0 Compacted partition mean bytes: 0 Average live cells per slice (last five minutes): NaN Maximum live cells per slice (last five minutes): 0 Average tombstones per slice (last five minutes): NaN Maximum tombstones per slice (last five minutes): 0 Table: sessions SSTable count: 0 Space used (live): 0 Space used (total): 0 Space used by snapshots (total): 0 Off heap memory used (total): 0 SSTable Compression Ratio: 0.0 Number of keys (estimate): -1 Memtable cell count: 0 Memtable data size: 0 Memtable off heap memory used: 0 Memtable switch count: 0 Local read count: 0 Local read latency: NaN ms Local write count: 0 Local write latency: NaN ms Pending flushes: 0 Bloom filter false positives: 0 Bloom filter false ratio: 0.00000 Bloom filter space used: 0 Bloom filter off heap memory used: 0 Index summary off heap memory used: 0 Compression metadata off heap memory used: 0 Compacted partition minimum bytes: 0 Compacted partition maximum bytes: 0 Compacted partition mean bytes: 0 Average live cells per slice (last five minutes): NaN Maximum live cells per slice (last five minutes): 0 Average tombstones per slice (last five minutes): NaN Maximum tombstones per slice (last five minutes): 0 ---------------- Keyspace: system Read Count: 52 Read Latency: 7.373384615384615 ms. Write Count: 105 ... ...
nodetool netstats命令:
D:\EBOOK\NoSQL\apache-cassandra-2.2.6\bin>nodetool netstats Starting NodeTool Mode: NORMAL Not sending any streams. Read Repair Statistics: Attempted: 0 Mismatch (Blocking): 0 Mismatch (Background): 0 Pool Name Active Pending Completed Large messages n/a 0 0 Small messages n/a 0 0 Gossip messages n/a 0 0 D:\EBOOK\NoSQL\apache-cassandra-2.2.6\bin>
nodetool tpstats命令:
D:\EBOOK\NoSQL\apache-cassandra-2.2.6\bin>nodetool tpstats Starting NodeTool Pool Name Active Pending Completed Blocked All time blocked MutationStage 0 0 209 0 0 ReadStage 0 0 1 0 0 RequestResponseStage 0 0 0 0 0 ReadRepairStage 0 0 0 0 0 CounterMutationStage 0 0 0 0 0 HintedHandoff 0 0 0 0 0 MiscStage 0 0 0 0 0 CompactionExecutor 0 0 145 0 0 MemtableReclaimMemory 0 0 7 0 0 PendingRangeCalculator 0 0 1 0 0 GossipStage 0 0 0 0 0 MigrationStage 0 0 0 0 0 MemtablePostFlush 0 0 35 0 0 ValidationExecutor 0 0 0 0 0 Sampler 0 0 0 0 0 MemtableFlushWriter 0 0 7 0 0 InternalResponseStage 0 0 0 0 0 AntiEntropyStage 0 0 0 0 0 CacheCleanupExecutor 0 0 0 0 0 Native-Transport-Requests 0 0 0 0 0 Message type Dropped READ 0 RANGE_SLICE 0 _TRACE 0 MUTATION 0 COUNTER_MUTATION 0 REQUEST_RESPONSE 0 PAGED_RANGE 0 READ_REPAIR 0 D:\EBOOK\NoSQL\apache-cassandra-2.2.6\bin>
DataStax OpsCenter
相對於nodetool而言,DataStax OpsCenter就方便多了。DataStax OpsCenter提供了統一的圖形化入口來監控和管理Cassandra集群。DataStax OpsCenter是與DataStax服務一起打包的。你可以注冊一個免費的版本用於開發或非生產環境下使用。
有一點屁民瑞威認為比較重要:那就是OpsCenter的監控指標和相關信息是存儲在Cassandra里面而不是存儲到其他地方,所以這就給我們一個好的學習使用Cassandra的例子。
關於這個工具的安裝和使用,屁民部落將在隨后的文章中提及。
JConsole
JConsole這個工具是JDK5.0以后自帶的用於監控JAVA程序。估計這個工具用得不多,也就不做過多介紹。有興趣的朋友可以查看其官方文檔。