检查所有cassandra节点的运行状况

时间:2017-06-12 13:48:48

标签: node.js cassandra cassandra-node-driver

我正在编写测试来检查cassandra键空间和表的元数据信息。 我还想检查哪个节点已启动或哪个节点已关闭。我怎么能这样做?

1 个答案:

答案 0 :(得分:5)

nodetool实用程序使您可以访问诊断和操作信息。

nodetool ring

将为您提供环中节点及其状态的列表。

从node.js驱动程序中,您还可以获取信息。 Client具有hosts属性。每个主机都有一个isUp功能,您可以使用它。 example显示使用元数据:

"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();
  });
相关问题