Use default influx batch options.

This commit is contained in:
Mark Nellemann 2020-09-02 09:27:38 +02:00
parent e3717529b5
commit c198c370ff
2 changed files with 14 additions and 15 deletions

View file

@ -12,6 +12,13 @@ Small utility to fetch metrics from one or more HMC's and push those to an Influ
- Run the *bin/hmci* program in a shell, as a @reboot cron task or setup a proper service :) - Run the *bin/hmci* program in a shell, as a @reboot cron task or setup a proper service :)
### Notes
Examples on how to change the default retention policy:
ALTER RETENTION POLICY "autogen" ON "hmci" DURATION 156w
ALTER RETENTION POLICY "autogen" ON "hmci" DURATION 90d
## Development Information ## Development Information

View file

@ -37,6 +37,7 @@ class InfluxClient {
InfluxDB influxDB InfluxDB influxDB
BatchPoints batchPoints BatchPoints batchPoints
InfluxClient(String url, String username, String password, String database) { InfluxClient(String url, String username, String password, String database) {
this.url = url this.url = url
this.username = username this.username = username
@ -44,6 +45,7 @@ class InfluxClient {
this.database = database this.database = database
} }
void login() { void login() {
if(!influxDB) { if(!influxDB) {
try { try {
@ -51,9 +53,8 @@ class InfluxClient {
createDatabase() createDatabase()
// Enable batch writes to get better performance. // Enable batch writes to get better performance.
BatchOptions options = BatchOptions.DEFAULTS.actions(300).flushDuration(500); //BatchOptions options = BatchOptions.DEFAULTS.actions(300).flushDuration(500);
influxDB.enableBatch(options); influxDB.enableBatch(BatchOptions.DEFAULTS);
//influxDB.setLogLevel(InfluxDB.LogLevel.BASIC); //influxDB.setLogLevel(InfluxDB.LogLevel.BASIC);
batchPoints = BatchPoints.database(database).precision(TimeUnit.SECONDS).build(); batchPoints = BatchPoints.database(database).precision(TimeUnit.SECONDS).build();
@ -65,6 +66,7 @@ class InfluxClient {
} }
} }
void logoff() { void logoff() {
influxDB?.close(); influxDB?.close();
influxDB = null influxDB = null
@ -72,18 +74,9 @@ class InfluxClient {
void createDatabase() { void createDatabase() {
// Create a database... // Create our database... with a default retention of 156w == 3 years
influxDB.query(new Query("CREATE DATABASE " + database)); influxDB.query(new Query("CREATE DATABASE " + database + " WITH DURATION 156w"));
influxDB.setDatabase(database); influxDB.setDatabase(database);
/*
// ... and a retention policy, if necessary.
String retentionPolicyName = "HMCI_ONE_YEAR";
influxDB.query(new Query("CREATE RETENTION POLICY " + retentionPolicyName
+ " ON " + database + " DURATION 365d REPLICATION 1 DEFAULT"));
influxDB.setRetentionPolicy(retentionPolicyName);
*/
} }
@ -96,7 +89,6 @@ class InfluxClient {
logoff() logoff()
login() login()
} }
//influxDB.flush()
} }