Skip to content

Commit

Permalink
Add advanced config options for InfluxDB
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrin committed May 17, 2018
1 parent 3d29cda commit 2b0c479
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### v0.2.3

- Added advanced configuration options for InfluxDB

### v0.2.2

- Fixed a rare crash when hcidump was returning invalid data
Expand Down
18 changes: 18 additions & 0 deletions ruuvi-collector.properties.example
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,27 @@
# NOTE: the influxdb_legacy storage method does not support extended values
#storage.values=extended


#
# Advanced configuration - Change these only if you know what you are doing
#

# Commands for starting the BLE scanning and the dump.
# The scan command is only executed, output and exit is ignored. Setting this blank will disable this command.
# The dump command is executed and it's output is parsed, the collector will exit when/if this command ends
# In general you want to change these only if you intend to use wrapper scripts or you need to use absolute paths to the executables
#command.scan=hcitool lescan --duplicates --passive
#command.dump=hcidump --raw

# Retention policy to use (note: you must create it yourself)
#influxRetentionPolicy=autogen

# Use gzip, saves bandwidth at minimal CPU cost
#influxGzip=true

# Use batch mode, improved performance at the cost of increased delay for measurements to show up. Does not affect the timestamps.
#influxBatch=true

# Maximum number of datapoints and maximum time waited in milliseconds before sending a batch. Has no effect if batch mode disabled.
#influxBatchMaxSize=2000
#influxBatchMaxTime=100
48 changes: 48 additions & 0 deletions src/main/java/fi/tkgwf/ruuvi/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public abstract class Config {
private static String influxMeasurement = "ruuvi_measurements";
private static String influxUser = "ruuvi";
private static String influxPassword = "ruuvi";
private static String influxRetentionPolicy = "autogen";
private static boolean influxGzip = true;
private static boolean influxBatch = true;
private static int influxBatchMaxSize = 2000;
private static int influxBatchMaxTimeMs = 100;
private static long measurementUpdateLimit = 9900;
private static String storageMethod = "influxdb";
private static String storageValues = "extended";
Expand Down Expand Up @@ -110,6 +115,29 @@ private static void readConfig() {
case "command.dump":
dumpCommand = value.split(" ");
break;
case "influxRetentionPolicy":
influxRetentionPolicy = value;
break;
case "influxGzip":
influxGzip = Boolean.parseBoolean(value);
break;
case "influxBatch":
influxBatch = Boolean.parseBoolean(value);
break;
case "influxBatchMaxSize":
try {
influxBatchMaxSize = Integer.parseInt(value);
} catch (NumberFormatException ex) {
LOG.warn("Malformed number format for influxBatchMaxSize: '" + value + '\'');
}
break;
case "influxBatchMaxTime":
try {
influxBatchMaxTimeMs = Integer.parseInt(value);
} catch (NumberFormatException ex) {
LOG.warn("Malformed number format for influxBatchMaxTime: '" + value + '\'');
}
break;
}
}
}
Expand Down Expand Up @@ -182,6 +210,26 @@ public static String getInfluxPassword() {
return influxPassword;
}

public static String getInfluxRetentionPolicy() {
return influxRetentionPolicy;
}

public static boolean isInfluxGzip() {
return influxGzip;
}

public static boolean isInfluxBatch() {
return influxBatch;
}

public static int getInfluxBatchMaxSize() {
return influxBatchMaxSize;
}

public static int getInfluxBatchMaxTimeMs() {
return influxBatchMaxTimeMs;
}

public static long getMeasurementUpdateLimit() {
return measurementUpdateLimit;
}
Expand Down
39 changes: 35 additions & 4 deletions src/main/java/fi/tkgwf/ruuvi/db/InfluxDBConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,41 @@ public class InfluxDBConnection implements DBConnection {
private final InfluxDB influxDB;

public InfluxDBConnection() {
influxDB = InfluxDBFactory.connect(Config.getInfluxUrl(), Config.getInfluxUser(), Config.getInfluxPassword());
influxDB.setDatabase(Config.getInfluxDatabase());
influxDB.enableGzip();
influxDB.enableBatch(2000, 100, TimeUnit.MILLISECONDS); // TODO: make these configurable
this(
Config.getInfluxUrl(),
Config.getInfluxUser(),
Config.getInfluxPassword(),
Config.getInfluxDatabase(),
Config.getInfluxRetentionPolicy(),
Config.isInfluxGzip(),
Config.isInfluxBatch(),
Config.getInfluxBatchMaxSize(),
Config.getInfluxBatchMaxTimeMs()
);
}

public InfluxDBConnection(
String url,
String user,
String password,
String database,
String retentionPolicy,
boolean gzip,
boolean batch,
int batchSize,
int batchTime
) {
influxDB = InfluxDBFactory.connect(url, user, password).setDatabase(database).setRetentionPolicy(retentionPolicy);
if (gzip) {
influxDB.enableGzip();
} else {
influxDB.disableGzip();
}
if (batch) {
influxDB.enableBatch(batchSize, batchTime, TimeUnit.MILLISECONDS);
} else {
influxDB.disableBatch();
}
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fi/tkgwf/ruuvi/utils/InfluxDataMigrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class InfluxDataMigrator {
public synchronized void migrate() {
LOG.info("Starting migration...");
long start = System.currentTimeMillis();
DBConnection db = new InfluxDBConnection();
DBConnection db = Config.getDBConnection();
// Theres a hard limit (?) of 5 concurrent queries per instance
InfluxDB influx1 = createInfluxDB();
InfluxDB influx2 = createInfluxDB();
Expand Down

0 comments on commit 2b0c479

Please sign in to comment.