【问题标题】:Cassandra status check using nodejs使用 nodejs 检查 Cassandra 状态
【发布时间】:2018-08-22 21:49:59
【问题描述】:

我在三个环境中使用nodejs,并且Cassandra在所有三个节点中运行。

我完全理解使用nodetool status 我将能够获得每个节点的状态。但问题是如果我的当前节点宕机了,那么我将无法在当前节点执行nodetool状态,那么有没有办法使用nodejs Cassandra驱动来获取状态?

感谢任何帮助。

已编辑:

根据 dilsingi 的建议,我使用了 client.hosts,但问题是,在以下集群中,172.30.56.61 已关闭,但仍显示为可用。 如何获取每个节点的状态?

const cassandra = require('cassandra-driver');
const client = new cassandra.Client({ contactPoints: ['172.30.56.60','172.30.56.61','172.30.56.62'], keyspace: 'test', policies : { loadBalancing : new cassandra.policies.loadBalancing.RoundRobinPolicy }});

    async function read() {
        client.connect().then(function () {
          console.log('Connected to cluster with %d host(s): %j', client.hosts.length, client.hosts.keys());
          client.hosts.forEach(function (host) {
       console.log(host.address, host.datacenter, host.rack);
    });

        });
    }

    read();

nodeTool状态输出:

Datacenter: newyork
===================
Status=Up/Down

    |/ State=Normal/Leaving/Joining/Moving
    --  Address       Load       Tokens       Owns (effective)  Host ID                               Rack
    UN  172.30.56.62  1.13 MiB   256          34.8%             e93827b7-ba43-4fba-8a51-4876832b5b22  rack1
    DN  172.30.56.60  1.61 MiB   256          33.4%             e385af22-803e-4313-bee2-16219f73c213  rack1
    UN  172.30.56.61  779.4 KiB  256          31.8%             be7fc52e-c45d-4380-85a3-4cbf6d007a5d  rack1


Node Js Code :

    const cassandra = require('cassandra-driver');
    const client = new cassandra.Client({ contactPoints: ['172.30.56.60','172.30.56.61','172.30.56.62'], keyspace: 'qcs', policies : { loadBalancing : new cassandra.policies.loadBalancing.RoundRobinPolicy }});

    async function read() {
        client.connect().then(function () {
          console.log('Connected to cluster with %d host(s): %j', client.hosts.length, client.hosts.keys());
          client.hosts.forEach(function (host) {
               console.log(host.address, host.datacenter, host.rack, host.isUp(), host.canBeConsideredAsUp());
          });

        });
    }

    read();

NodeJs 输出:

    Connected to cluster with 3 host(s): ["172.30.56.60:9042","172.30.56.61:9042","172.30.56.62:9042"]
    172.30.56.60:9042 newyork rack1 true true
    172.30.56.61:9042 newyork rack1 true true
    172.30.56.62:9042 newyork rack1 true true

【问题讨论】:

  • 您会使用该状态进行进一步警报,还是只是让应用程序知道某个节点已关闭?
  • @dilsingi 只是为了让应用程序知道节点是否关闭。我可以通过 API / 客户端调用来获取数据。
  • @dilsingi 感谢您的回答,但 UP 和 canBeConsideredAsUp() 仍然显示为 true。这意味着它没有检测到关闭的节点
  • 但是nodetool状态显示为down

标签: node.js cassandra cassandra-3.0


【解决方案1】:

包括 (nodejs) 在内的一般驱动程序都知道整个 Cassandra 集群拓扑。在与连接字符串中的一个或多个节点 ip 地址初次接触时,驱动程序可以自动识别构成 cassandra 环的所有节点 ip。它足够智能,可以知道节点何时关闭或新节点何时加入集群。它甚至可以继续使用全新的节点(ips)而不是一开始。

因此不需要为节点状态编码,因为驱动程序会自动为您处理。建议在连接字符串中提供 1 个以上的 ip,以便在进行初始连接时提供冗余。

这里是 nodejs 驱动程序 documentation,这个 section 描述了“自动节点发现”功能和“集群和模式元数据”。

【讨论】:

  • 你能给我指出告诉每个节点状态的客户端代码
  • 谢谢@dilsingi 但问题仍然是:它没有给我状态:我根据您的建议编辑了问题,请阅读此
  • @Harry 您能否将“nodetool status”输出发布到其关闭的位置以及驱动程序代码输出您将其视为“UP”的位置吗?
  • 你可以检查问题,编辑内容
猜你喜欢
  • 2020-04-23
  • 1970-01-01
  • 2017-08-11
  • 2019-03-03
  • 2020-01-30
  • 2021-03-19
  • 2022-01-19
  • 2023-03-02
相关资源
最近更新 更多