import com.cnbm.influx.config.InfluxClient; import com.cnbm.influx.template.Event; import com.influxdb.client.InfluxDBClient; import com.influxdb.client.InfluxDBClientFactory; import com.influxdb.client.WriteApi; import com.influxdb.client.domain.WritePrecision; import com.influxdb.client.write.Point; import java.time.Instant; import java.util.ArrayList; import java.util.List; /** * @Desc: "" * @Author: caixiang * @DATE: 2022/7/1 16:39 */ public class Main2 { public static void main(String[] args) { //方式1 Point point = Point.measurement("ASProcessCompleteEvent") .addTag("transationId", "112311") .addTag("argName", "argName11") .addField("argValue", 3D) .time(Instant.now().toEpochMilli(), WritePrecision.MS); InfluxClient.Client.getWriteApi().writePoint(point); // //方式2 // char[] token = "lkBsC27QZr1W50BSPlGxpTqNNpwuUk5uz1dZZRPSPbCG5VmNDDUo8P3UkZIhGWwfJwkuz6ZGZ7Et4_KBaG3gHw==".toCharArray(); // String org = "qgs"; // String bucket = "mytest"; // InfluxDBClient influxDBClient = InfluxDBClientFactory.create("http://192.168.0.170:8086", token, org, bucket); // WriteApi writeApi = influxDBClient.makeWriteApi(); // Point point = Point.measurement("ASProcessCompleteEvent") // .addTag("transationId", "112311") // .addTag("argName", "argName11") // .addField("argValue", 7D) // .time(Instant.now().toEpochMilli(), WritePrecision.MS); // // // Point point2 = Point.measurement("ASProcessCompleteEvent") // .addTag("transationId", "222312") // .addTag("argName", "argName11") // .addField("argValue", 8D) // .time(Instant.now().toEpochMilli(), WritePrecision.MS); // List list = new ArrayList<>(); // list.add(point); // list.add(point2); // writeApi.writePoints(list); // //一定要close ,不如write 不了数据 // influxDBClient.close(); } }