I am writing tests to check metadata information of cassandra keyspace and tables. I also want to check which node is up or which is down in a cluster. how can I do it?
The nodetool utility gives you access to diagnostic and operational information.
nodetool ring
will give you a list of the nodes in the ring and their state.
From the node.js driver you can also get the information. The Client has a hosts
attribute. Each host has a isUp function you can use. An example shows using the metadata:
"use strict";
const cassandra = require('cassandra-driver');
const client = new cassandra.Client({ contactPoints: ['127.0.0.1'] });
client.connect()
.then(function () {
console.log('Connected to cluster with %d host(s): %j', client.hosts.length);
client.hosts.forEach(function (host) {
console.log('Host %s v%s on rack %s, dc %s, isUp: %s', host.address, host.cassandraVersion, host.rack, host.datacenter, host.isUp());
});
console.log('Shutting down');
return client.shutdown();
})
.catch(function (err) {
console.error('There was an error when connecting', err);
return client.shutdown();
});