【问题标题】:Checking health of all cassandra nodes检查所有 cassandra 节点的运行状况
【发布时间】:2017-11-14 00:39:12
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    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();
      });
    

    【讨论】:

    • 我必须使用 mocha 为它编写一个测试。是否有 nodetool 的模块或 nodejs 的类似模块?
    • 类似const { spawn } = require('child_process'); const ring = spawn('nodetool', ['ring']); 的东西?它是一个命令行实用程序。实际上也会用另一种机制更新上面的内容
    猜你喜欢
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 2016-11-30
    • 2021-06-06
    • 1970-01-01
    • 2020-06-16
    • 2015-11-16
    • 2019-04-25
    相关资源
    最近更新 更多