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. and 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:

        ping_result = bucket.ping()

    Which returns a PingResult object, encapsulating a payload similar to this:

    {
        "config_rev": 501,
        "id": "0x7fecb15526d0/e9097b2135f47b2d",
        "sdk": "libcouchbase/3.0.6_2_ga1e9e1ca91 PYCBC/3.0.6.dev5+g207fb829",
        "services": {
            "cbas": [
                {
                    "id": "0x7fec91445c40",
                    "latency_us": 1583,
                    "local": "127.0.0.1:51749",
                    "remote": "127.0.0.1:8095",
                    "status": "ok"
                }
            ],
            "fts": [
                {
                    "id": "0x7feca14a60e0",
                    "latency_us": 1252,
                    "local": "127.0.0.1:51748",
                    "remote": "127.0.0.1:8094",
                    "status": "ok"
                }
            ],
            "kv": [
                {
                    "id": "0x7fec9152fe30",
                    "latency_us": 1554,
                    "local": "127.0.0.1:51745",
                    "namespace": "default",
                    "remote": "127.0.0.1:11210",
                    "status": "ok"
                }
            ],
            "n1ql": [
                {
                    "id": "0x7fecb1454090",
                    "latency_us": 1711,
                    "local": "127.0.0.1:51746",
                    "remote": "127.0.0.1:8093",
                    "status": "ok"
                }
            ],
            "views": [
                {
                    "id": "0x7fecb1443400",
                    "latency_us": 1829,
                    "local": "127.0.0.1:51747",
                    "remote": "127.0.0.1:8092",
                    "status": "ok"
                }
            ]
        },
        "version": 1
    }

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

    def ok(bucket):
        result = bucket.ping()
        for endpoint, reports in result.endpoints.items():
            for report in reports:
                if not report.state == PingState.OK:
                    return False
        return True

    You can also specify a subset of services to ping, if you are only interested in a particular set of services and don’t wish to actively ping the others:

    ping_result = bucket.ping(PingOptions(service_types=[ServiceType.Query])

    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.

    diag_result = cluster.diagnostics()
    print(diag_result.as_json())

    Which will print the diagnostics result as a json string. For instance, on a single node cluster that has had n1ql queries and kv operations executed, you will see something like:

    {
        "_id": "0x7f8e8d464350",
        "_version": 1,
        "_sdk": "libcouchbase/3.0.6_2_ga1e9e1ca91 PYCBC/3.0.6.dev5+g207fb829",
        "_endpoints": {
            "kv": [
                {
                    "id": "c89f4c25513f1fb3",
                    "last_activity_us": 3181,
                    "local": "127.0.0.1:60360",
                    "remote": "127.0.0.1:11210",
                    "status": "connected",
                    "type": "kv"
                }
            ],
            "config": [
                {
                    "id": "0x7f8e9d53e440",
                    "last_activity_us": 163988,
                    "local": "127.0.0.1:60148",
                    "remote": "127.0.0.1:11210",
                    "status": "connected",
                    "type": "config"
                }
            ],
            "n1ql": [
                {
                    "id": "0x7f8e5d44d8e0",
                    "last_activity_us": 354,
                    "local": "127.0.0.1:60162",
                    "remote": "127.0.0.1:8093",
                    "status": "connected",
                    "type": "n1ql"
                }
            ]
        }
    }