Improved error handling.

This commit is contained in:
Mark Nellemann 2022-02-10 17:39:53 +01:00
parent e0dc65a1e6
commit 02804232b0
3 changed files with 9 additions and 4 deletions

View file

@ -29,7 +29,7 @@ dependencies {
implementation 'com.squareup.moshi:moshi:1.13.0'
implementation 'com.serjltt.moshi:moshi-lazy-adapters:2.2'
implementation 'org.tomlj:tomlj:1.0.0'
implementation 'org.influxdb:influxdb-java:2.21'
implementation 'org.influxdb:influxdb-java:2.22'
implementation 'org.slf4j:slf4j-api:1.7.35'
implementation 'org.slf4j:slf4j-simple:1.7.35'

View file

@ -91,7 +91,7 @@ class HmcInstance implements Runnable {
do {
Instant instantStart = Instant.now();
try {
if(doEnergy) {
if (doEnergy) {
getMetricsForEnergy();
}
getMetricsForSystems();
@ -107,9 +107,9 @@ class HmcInstance implements Runnable {
executions = 0;
discover();
}
} catch (Exception e) {
log.error("run()", e);
log.error("run() - fatal error: {}", e.getMessage());
throw new RuntimeException(e);
}
Instant instantEnd = Instant.now();

View file

@ -67,6 +67,7 @@ class InfluxClient {
try {
log.debug("Connecting to InfluxDB - {}", url);
influxDB = InfluxDBFactory.connect(url, username, password).setDatabase(database);
influxDB.version(); // This ensures that we actually try to connect to the db
batchPoints = BatchPoints.database(database).precision(TimeUnit.SECONDS).build();
connected = true;
} catch(Exception e) {
@ -95,8 +96,12 @@ class InfluxClient {
log.trace("writeBatchPoints()");
try {
influxDB.writeWithRetry(batchPoints);
errorCounter = 0;
} catch (InfluxDBException.DatabaseNotFoundException e) {
log.error("writeBatchPoints() - database \"{}\" not found/created: can't write data", database);
if(++errorCounter > 3) {
throw new RuntimeException(e);
}
} catch(Exception e) {
e.printStackTrace();
log.warn("writeBatchPoints() {}", e.getMessage());