Resources
Nodetool Cheatsheet
Complete Cassandra nodetool command reference for cluster management, maintenance, and monitoring!
📊 Status Commands
status, ring, info, version
🔧 Maintenance
repair, cleanup, flush, rebuild
📦 Compaction
compact, compactionstats
📸 Backups
snapshot, clearsnapshot
📊 Status & Information Commands
Cluster Status
# Show cluster status
nodetool status
# Output example:
# Datacenter: datacenter1
# Status=Up/Down
# State=Normal/Leaving/Joining/Moving
# Load: Total data size
# Tokens: Number of tokens
# Owns: % of ring owned
# Host ID: Unique node identifier
# Rack: Rack assignment
# Status for specific keyspace
nodetool status my_keyspace
# Resolve hostnames to IPs
nodetool status -r
nodetool status --resolve-ip
Ring Information
# Show token ring
nodetool ring
# Ring for specific keyspace
nodetool ring my_keyspace
# Describe ring (JSON format)
nodetool describering my_keyspace
Node Information
# Node info (uptime, load, memory)
nodetool info
# Cassandra version
nodetool version
# Get node's host ID
nodetool info | grep "ID"
# Check gossip info
nodetool gossipinfo
# Show datacenter/rack
nodetool getendpoints my_keyspace users 'partition_key'
Thread Pool Stats
# Thread pool statistics
nodetool tpstats
# Shows:
# - Active, Pending, Completed tasks
# - Blocked tasks
# - Dropped messages
🔧 Maintenance Commands
Flush (MemTable → SSTable)
# Flush all keyspaces
nodetool flush
# Flush specific keyspace
nodetool flush my_keyspace
# Flush specific table
nodetool flush my_keyspace users
# ⚡ Use before: snapshots, backups, restarts
Cleanup (Remove Extra Data)
# Cleanup after adding nodes (removes non-owned data)
nodetool cleanup
# Cleanup specific keyspace
nodetool cleanup my_keyspace
# Cleanup specific table
nodetool cleanup my_keyspace users
# With parallelism (number of jobs)
nodetool cleanup -j 2 my_keyspace
# ⚠️ Run AFTER adding nodes and repair completes
Refresh (Reload SSTables)
# Reload SSTables from disk
nodetool refresh my_keyspace users
# Use when: Copying SSTables manually, restoring backups
Rebuild (Stream Data from Another DC)
# Rebuild from another datacenter
nodetool rebuild -- dc1
# Rebuild specific keyspace
nodetool rebuild -ks my_keyspace -- dc1
# Use when: Adding new datacenter, node failure
Drain (Stop Writes, Flush All)
# Drain node before shutdown
nodetool drain
# What it does:
# 1. Stop accepting writes
# 2. Flush all memtables
# 3. Prepare for clean shutdown
# ✅ ALWAYS run before stopping Cassandra
🔨 Repair Commands
Full Repair
# Full repair (entire node)
nodetool repair
# Repair specific keyspace
nodetool repair my_keyspace
# Repair specific table
nodetool repair my_keyspace users
# ⚠️ Expensive! Better to use -pr or incremental
Primary Range Repair (Recommended)
# Repair only primary ranges (-pr)
nodetool repair -pr
# With full repair
nodetool repair -pr -full
# Specific keyspace
nodetool repair -pr my_keyspace
# ✅ Best practice: Run on ALL nodes weekly
# ✅ More efficient than full repair
Incremental Repair
# Incremental repair (faster)
nodetool repair -inc
# Incremental + primary range
nodetool repair -inc -pr
# ✅ Repairs only unrepaired SSTables
# ✅ Faster than full repair
Repair Options
# Local datacenter only
nodetool repair -pr -local
# Specific datacenter
nodetool repair -pr -dc dc1
# Specific hosts
nodetool repair -pr -hosts 192.168.1.10,192.168.1.11
# Parallel repair (jobs)
nodetool repair -pr -j 2
# Trace repair
nodetool repair -pr -tr
Repair Status
# View repair status
nodetool repair_admin list
# Cancel repair session
nodetool repair_admin cancel session_id
# Force terminate repair
nodetool repair_admin force-cancel session_id
Repair Best Practices
✅ Run weekly: nodetool repair -pr -full on ALL nodes
✅ One at a time: Don't repair multiple nodes simultaneously
✅ Off-peak hours: Run during low traffic
⚠️ gc_grace_seconds: Must repair within this window (default 10 days)
📦 Compaction Commands
Manual Compaction
# Compact all keyspaces
nodetool compact
# Compact specific keyspace
nodetool compact my_keyspace
# Compact specific table
nodetool compact my_keyspace users
# Split output (prevent huge SSTables)
nodetool compact -s my_keyspace users
# ⚠️ Usually NOT needed - auto-compaction handles it
Compaction Stats
# View compaction status
nodetool compactionstats
# Shows:
# - Pending tasks
# - Active compactions
# - Bytes compacted
# - Progress %
# Human-readable format
nodetool compactionstats -H
Compaction Control
# Stop compaction
nodetool stop COMPACTION
# Stop validation (repair)
nodetool stop VALIDATION
# Get compaction throughput (MB/s)
nodetool getcompactionthroughput
# Set compaction throughput (MB/s, 0=unlimited)
nodetool setcompactionthroughput 64
SSTable Operations
# View SSTable count
nodetool tablestats my_keyspace.users
# Upgrade SSTables to current format
nodetool upgradesstables
# Upgrade specific keyspace
nodetool upgradesstables my_keyspace
# Rewrite SSTables (don't change version)
nodetool scrub my_keyspace users
🌊 Streaming & Bootstrap Commands
Stream Throughput
# Get stream throughput (MB/s)
nodetool getstreamthroughput
# Set stream throughput (MB/s)
nodetool setstreamthroughput 200
# Set to unlimited (0)
nodetool setstreamthroughput 0
Bootstrap & Join
# Check if node is bootstrapped
nodetool info | grep "Load"
# Resume bootstrap (if failed)
# Edit cassandra.yaml: resume_bootstrap: true
# Then restart Cassandra
Decommission & Remove
# Decommission node (graceful removal)
nodetool decommission
# What it does:
# 1. Stream data to other nodes
# 2. Update token ownership
# 3. Remove node from cluster
# Force remove dead node (from another node)
nodetool removenode host_id
# Check remove status
nodetool removenode status
# Force remove (if stuck)
nodetool removenode force
📸 Snapshot & Backup Commands
Create Snapshots
# Snapshot all keyspaces
nodetool snapshot -t backup_20240115
# Snapshot specific keyspace
nodetool snapshot -t my_backup my_keyspace
# Snapshot specific table
nodetool snapshot -t users_backup my_keyspace users
# Snapshots stored in: /var/lib/cassandra/data/keyspace/table/snapshots/
List Snapshots
# List all snapshots
nodetool listsnapshots
# Output shows:
# - Snapshot name
# - Keyspace
# - Table
# - Size
# - True Size (actual disk usage)
Clear Snapshots
# Clear all snapshots
nodetool clearsnapshot
# Clear specific snapshot
nodetool clearsnapshot -t backup_20240115
# Clear snapshot for specific keyspace
nodetool clearsnapshot --all my_keyspace
# ⚠️ Snapshots consume disk space - clean regularly!
⚡ Performance Monitoring
Statistics Commands
# Table statistics (detailed)
nodetool tablestats
# Specific keyspace
nodetool tablestats my_keyspace
# Specific table
nodetool tablestats my_keyspace.users
# Human-readable format
nodetool tablestats -H
# Shows: Read/write latency, SSTable count, bloom filter false positives
Histogram Stats
# Table histograms (latency distribution)
nodetool tablehistograms my_keyspace users
# Shows:
# - Read latency percentiles
# - Write latency percentiles
# - Partition size
# - Cell count per partition
Probe & Metrics
# Connection stats
nodetool netstats
# GC stats
nodetool gcstats
# Proxy histogram stats
nodetool proxyhistograms
# Reset all histograms
nodetool resethistograms
Cache Management
# View cache info
nodetool info | grep -i cache
# Invalidate key cache
nodetool invalidatekeycache
# Invalidate row cache
nodetool invalidaterowcache
# Invalidate counter cache
nodetool invalidatecountercache
🔍 Troubleshooting Commands
Gossip Control
# Enable gossip
nodetool enablegossip
# Disable gossip (maintenance mode)
nodetool disablegossip
# Check gossip status
nodetool statusgossip
# View gossip info
nodetool gossipinfo
Binary Protocol (CQL)
# Enable native transport (CQL port 9042)
nodetool enablebinary
# Disable native transport
nodetool disablebinary
# Check status
nodetool statusbinary
Handoff & Hints
# Enable hinted handoff
nodetool enablehandoff
# Disable hinted handoff
nodetool disablehandoff
# Status hinted handoff
nodetool statushandoff
# Pause hints
nodetool pausehandoff
# Resume hints
nodetool resumehandoff
Auto-Compaction Control
# Enable auto-compaction
nodetool enableautocompaction
# Disable auto-compaction (maintenance)
nodetool disableautocompaction
# Disable for specific table
nodetool disableautocompaction my_keyspace users
JMX & Management
# Set log level
nodetool setlogginglevel org.apache.cassandra DEBUG
# Get log level
nodetool getlogginglevel org.apache.cassandra
# View schema version
nodetool describecluster
# Trigger GC
nodetool garbagecollect
📋 Quick Command Reference
| Command | Purpose | Frequency |
|---|---|---|
| nodetool status | Check cluster health | Daily |
| nodetool repair -pr | Repair primary ranges | Weekly |
| nodetool cleanup | Remove non-owned data | After adding nodes |
| nodetool flush | Flush memtables to disk | Before backups |
| nodetool snapshot | Create backup | As needed |
| nodetool drain | Prepare for shutdown | Before every restart |
| nodetool tpstats | Thread pool stats | When monitoring |
| nodetool tablestats | Table statistics | When investigating |
| nodetool compactionstats | Compaction progress | During compaction |
| nodetool rebuild | Stream from another DC | New DC setup |
🔄 Common Workflows
Safe Node Restart
# 1. Drain node
nodetool drain
# 2. Stop Cassandra
sudo systemctl stop cassandra
# 3. Start Cassandra
sudo systemctl start cassandra
# 4. Check status
nodetool status
Adding a New Node
# 1. Configure new node (cassandra.yaml)
# 2. Start Cassandra (auto-bootstrap)
# 3. Monitor bootstrap
nodetool status
# 4. After bootstrap completes, run cleanup on OLD nodes
nodetool cleanup
# 5. Run repair on new node
nodetool repair -pr
Removing a Node
# Option 1: Graceful (node is UP)
# Run on the node to remove:
nodetool decommission
# Option 2: Force remove (node is DOWN)
# Run on another node:
nodetool status # Get host_id
nodetool removenode host_id
Weekly Maintenance
# Run on each node (one at a time!)
# 1. Repair primary ranges
nodetool repair -pr -full
# 2. Clean old snapshots
nodetool clearsnapshot
# 3. Check cluster health
nodetool status
nodetool tpstats
Pro Tips
✅ DO:
- Run nodetool drain before restart
- Repair weekly with -pr flag
- Monitor tpstats for dropped messages
- Clean snapshots regularly
❌ DON'T:
- Repair all nodes simultaneously
- Run full repair without -pr
- Forget to cleanup after adding nodes
- Skip drain before shutdown
Advertisement
Responsive Ad