简体   繁体   中英

How can I check if the InfluxDB v2 is online and the credentials are valid using the InfluxDB client for java?

I'm using the InfluxDB 2 client for Java, and I was wondering how I would check if the InfluxDB is online and if the given credentials are valid.

In influxdb-java I used the.ping() function, but I can't seem to find such a function for the influxdb-client-java

There isn't an exact replacement for ping(), but you can use the REST endpoint /health instead. See: https://docs.influxdata.com/influxdb/v2.0/api/#operation/GetHealth

There is also a class you can use for this:

if (influxDb != null) {
    HealthCheck healthCheck = influxDb.health();
    if(healthCheck.getStatus() == StatusEnum.PASS) {
            // do what you want here
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM