Diagnosing and preventing Network Problems with Health Check

    +
    In today’s distributed and virtual environments, users will often not have full administrative control over their whole network. Health Check introduces Ping to check nodes are still healthy, and to force idle connections to be kept alive in environments with eager shutdowns of unused resources. Diagnostics requests a report from a node, giving instant health check information.

    Diagnosing problems in distributed environments is far from easy, so Couchbase provides a Health Check API with Ping() for active monitoring. ans Diagnostics() for a look at what the client believes is the current state of the cluster. More extensive discussion of the uses of Health Check can be found in the Health Check Concept Guide.

    Ping

    At its simplest, ping provides information about the current state of the connections in the Couchbase Cluster, by actively polling:

    void printDiagnostics(Bucket bucket) {
        bucket.ping();
        DiagnosticsReport report = cluster.diagnostics();
        System.out.println(report.exportToJson(true));
    }

    Which, for a single-node test cluster, will return a payload similar to this:

    {
      "services" : {
        "view" : [ {
          "last_activity_us" : 2863,
          "state" : "connected",
          "id" : "0x46ee8659",
          "remote" : "localhost:8092",
          "local" : "localhost:53309"
        } ],
        "fts" : [ {
          "last_activity_us" : 2625,
          "state" : "connected",
          "id" : "0x1c5de614",
          "remote" : "localhost:8094",
          "local" : "localhost:53308"
        } ],
        "kv" : [ {
          "last_activity_us" : 19243,
          "state" : "connected",
          "id" : "0x7d942ebb",
          "remote" : "localhost:11210",
          "local" : "localhost:53307"
        } ],
        "n1ql" : [ {
          "last_activity_us" : 1963,
          "state" : "connected",
          "id" : "0x8de927d",
          "remote" : "localhost:8093",
          "local" : "localhost:53310"
        } ]
      },
      "sdk" : "couchbase-java-client/2.5.8 (git: 2.5.8, core: 1.5.8) (Mac OS X/10.13.4 x86_64; Java HotSpot(TM) 64-Bit Server VM 1.8.0_171-b11)",
      "id" : "9c7e2ac7-9a41-4e67-8cdf-bf16abaa35a4",
      "version" : 1
    }

    If you only wish to know if there’s a connection that’s up, filter out the rest of the information:

    boolean allEndpointsConnected(DiagnosticsReport report) {
        for (EndpointHealth endpoint : report.endpoints()) {
            if (endpoint.state() != LifecycleState.CONNECTED) {
                return false;
            }
        }
        return true;
    }

    Diagnostics

    Diagnostics returns a list of the nodes that the SDK currently has (or had) a connection to, and the current status of the connection. However this call does not actively poll the nodes, reporting instead the state the last time it tried to access each node. If you want the current status, then use Ping.

    bucket.diagnostics((err, res) => {
        console.log(res)
    })
    /*
    {
        "id":"0x10290d100","kv":[
            {
                "id":"0000000072b21d66",
                "last_activity_us":2363294,
                "local":"10.112.195.1:51473",
                "remote":"10.112.195.101:11210",
                "status":"connected"
            },
            {
                "id":"000000000ba84e5e",
                "last_activity_us":7369021,
                "local":"10.112.195.1:51486",
                "remote":"10.112.195.102:11210",
                "status":"connected"
            },
            {
                "id":"0000000077689398",
                "last_activity_us":4855640,
                "local":"10.112.195.1:51409",
                "remote":"10.112.195.103:11210",
                "status":"connected"
            }
        ],
        "sdk":"libcouchbase/2.9.5-njs couchnode/2.6.9 (node/10.16.0; v8/6.8.275.32-node.52; ssl/1.1.1b)",
        "version":1
    }
    */