Try to be more resilient to influx write errors.
This commit is contained in:
parent
1117709089
commit
497f999b77
|
@ -1,3 +1,3 @@
|
||||||
id = hmci
|
id = hmci
|
||||||
group = biz.nellemann.hmci
|
group = biz.nellemann.hmci
|
||||||
version = 1.1.0
|
version = 1.1.1
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
package biz.nellemann.hmci;
|
package biz.nellemann.hmci;
|
||||||
|
|
||||||
import biz.nellemann.hmci.Configuration.InfluxObject;
|
import biz.nellemann.hmci.Configuration.InfluxObject;
|
||||||
import org.influxdb.BatchOptions;
|
|
||||||
import org.influxdb.InfluxDB;
|
import org.influxdb.InfluxDB;
|
||||||
import org.influxdb.InfluxDBFactory;
|
import org.influxdb.InfluxDBFactory;
|
||||||
import org.influxdb.dto.BatchPoints;
|
import org.influxdb.dto.BatchPoints;
|
||||||
|
@ -36,8 +35,8 @@ class InfluxClient {
|
||||||
|
|
||||||
private final static Logger log = LoggerFactory.getLogger(InfluxClient.class);
|
private final static Logger log = LoggerFactory.getLogger(InfluxClient.class);
|
||||||
|
|
||||||
private static final int BATCH_ACTIONS_LIMIT = 5000;
|
//private static final int BATCH_ACTIONS_LIMIT = 5000;
|
||||||
private static final int BATCH_INTERVAL_DURATION = 1000;
|
//private static final int BATCH_INTERVAL_DURATION = 1000;
|
||||||
|
|
||||||
|
|
||||||
final private String url;
|
final private String url;
|
||||||
|
@ -47,6 +46,7 @@ class InfluxClient {
|
||||||
|
|
||||||
private InfluxDB influxDB;
|
private InfluxDB influxDB;
|
||||||
private BatchPoints batchPoints;
|
private BatchPoints batchPoints;
|
||||||
|
private int errorCounter = 0;
|
||||||
|
|
||||||
|
|
||||||
InfluxClient(InfluxObject config) {
|
InfluxClient(InfluxObject config) {
|
||||||
|
@ -64,7 +64,7 @@ class InfluxClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean connected = false;
|
boolean connected = false;
|
||||||
int errors = 0;
|
int loginErrors = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
|
@ -75,7 +75,7 @@ class InfluxClient {
|
||||||
connected = true;
|
connected = true;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
sleep(15 * 1000);
|
sleep(15 * 1000);
|
||||||
if(errors++ > 3) {
|
if(loginErrors++ > 3) {
|
||||||
log.error("login() error, giving up - " + e.getMessage());
|
log.error("login() error, giving up - " + e.getMessage());
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
} else {
|
} else {
|
||||||
|
@ -105,13 +105,17 @@ class InfluxClient {
|
||||||
synchronized void writeBatchPoints() throws Exception {
|
synchronized void writeBatchPoints() throws Exception {
|
||||||
log.debug("writeBatchPoints()");
|
log.debug("writeBatchPoints()");
|
||||||
try {
|
try {
|
||||||
influxDB.writeWithRetry(batchPoints);
|
influxDB.write(batchPoints);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
log.error("writeBatchPoints() error - " + e.getMessage());
|
log.error("writeBatchPoints() error - " + e.getMessage(), e);
|
||||||
|
if(++errorCounter > 3) {
|
||||||
|
log.info("writeBatchPoints() trying to logout / login");
|
||||||
|
errorCounter = 0;
|
||||||
logoff();
|
logoff();
|
||||||
login();
|
login();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue