diff --git a/build.gradle b/build.gradle index 30e6978..23b0384 100644 --- a/build.gradle +++ b/build.gradle @@ -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' diff --git a/src/main/java/biz/nellemann/hmci/HmcInstance.java b/src/main/java/biz/nellemann/hmci/HmcInstance.java index d7ecd37..a2b67a5 100644 --- a/src/main/java/biz/nellemann/hmci/HmcInstance.java +++ b/src/main/java/biz/nellemann/hmci/HmcInstance.java @@ -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(); diff --git a/src/main/java/biz/nellemann/hmci/InfluxClient.java b/src/main/java/biz/nellemann/hmci/InfluxClient.java index 4308f4e..2175b0a 100644 --- a/src/main/java/biz/nellemann/hmci/InfluxClient.java +++ b/src/main/java/biz/nellemann/hmci/InfluxClient.java @@ -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());