|
@@ -1,12 +1,14 @@
|
|
|
package com.usky.common.influx.core;
|
|
|
|
|
|
import lombok.Data;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.influxdb.InfluxDB;
|
|
|
import org.influxdb.InfluxDBFactory;
|
|
|
import org.influxdb.dto.Query;
|
|
|
import org.influxdb.dto.QueryResult;
|
|
|
|
|
|
@Data
|
|
|
+@Slf4j
|
|
|
public class InfluxDbUtils {
|
|
|
|
|
|
private String userName;
|
|
@@ -16,11 +18,11 @@ public class InfluxDbUtils {
|
|
|
private String retentionPolicy;
|
|
|
// InfluxDB实例
|
|
|
private InfluxDB influxDB;
|
|
|
-
|
|
|
// 数据保存策略
|
|
|
public static String policyNamePix = "logRetentionPolicy_";
|
|
|
|
|
|
-
|
|
|
+ public InfluxDbUtils() {
|
|
|
+ }
|
|
|
|
|
|
public InfluxDbUtils(String userName, String password, String url, String database,
|
|
|
String retentionPolicy) {
|
|
@@ -42,11 +44,10 @@ public class InfluxDbUtils {
|
|
|
influxDB = InfluxDBFactory.connect(url, userName, password);
|
|
|
}
|
|
|
try {
|
|
|
-// createDB(database);
|
|
|
+// createDB(database);
|
|
|
influxDB.setDatabase(database);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
-// log.error("create influx db failed, error: {}", e.getMessage());
|
|
|
+ log.error("create influx db failed, error: {}", e.getMessage());
|
|
|
} finally {
|
|
|
influxDB.setRetentionPolicy(retentionPolicy);
|
|
|
}
|