As a database administrator, you will constantly monitor and check the health status of your Cassandra nodes. Cassandra provides a native command-line tool that allows us to do just that.
In this tutorial, you will learn how to use the Apache Cassandra nodetool command to monitor the health of your cluster.
What Is Nodetool?
The nodetool is a command-line utility that allows you to easily manage your Apache Cassandra cluster. Using the nodetool command, you can create backups, manage logs and flush the cluster, manage the cluster daemon, and more.
Checking Your Cluster Health with Nodetool
The nodetool command allows us to gather information about the cluster such as its state, resource usage, IDs, etc.
The command syntax is as shown:
If you installed Apache Cassandra via the archive, you can find the nodetool command in the bin directory:
The command accepts the options such as:
- -h – Specifies the hostname or IP address of the target node.
- -p – Defines the port number on which the cluster is running.
- -pwf – Sets the path to the password file.
- -pw – Specifies the password to login into the cluster.
- -r – Shows the node names instead of IP addresses.
- Keyspace – Defines the keyspace name.
Example:
The following example shows how to check the cluster health of the local node:
The command returns the cluster information as shown in the following output:
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns Host ID Rack
UN 127.0.0.1 217.76 KiB 16 ? 98e7247d-735a-4552-9c8f-beeb964e50b6 rack1
The status command returns the information such as:
- Status – This shows whether the node is running or not.
- State – This indicates the stat of the node to the cluster.
- Address – This represents the address of the node.
- Load – Shows the size under the Cassandra data directory (excluding snapshots).
- Tokens – Represents the number of tokens for that specific node.
- Owns – Indicates the percentage of data held by the node within the data center.
- Host ID – Represents the network ID of the node.
- Rack – Shows the rack to which the node belongs.
Checking Node Health with the Info Command
You can also use the nodetool info command to show the detailed information about the node. An example is as shown:
The command should return the information as:
Gossip active : true
Native Transport active: true
Load : 217.76 KiB
Generation No : 1661396337
Uptime (seconds) : 7381
Heap Memory (MB) : 301.87 / 1914.94
Off Heap Memory (MB) : 0.00
Data Center : datacenter1
Rack : rack1
Exceptions : 0
Key Cache : entries 40, size 3.44 KiB, capacity 95 MiB, 169 hits, 212 requests, 0.797 recent hit rate, 14400 save period in seconds
Row Cache : entries 0, size 0 bytes, capacity 0 bytes, 0 hits, 0 requests, NaN recent hit rate, 0 save period in seconds
Counter Cache : entries 0, size 0 bytes, capacity 47 MiB, 0 hits, 0 requests, NaN recent hit rate, 7200 save period in seconds
Percent Repaired : 100.0%
Token : (invoke with -T/--tokens to see all 16 tokens)
Conclusion
This article discussed how to use the nodetool command to gather the health information about your Apache Cassandra cluster.
Thanks for reading!