use of com.influxdb.client.WriteApiBlocking in project oner365-cloud by xiaozhao32.
the class InfluxdbTest method writeData.
/**
* 保存
*/
public static void writeData(InfluxDBClient client, String bucket, String org) {
// 1.Use InfluxDB Line Protocol to write data
String data = "mem,host=host1 used_percent=23.43234543";
WriteApiBlocking writeApi = client.getWriteApiBlocking();
writeApi.writeRecord(bucket, org, WritePrecision.NS, data);
// 2.Use a Data Point to write data
Point point = Point.measurement("mem").addTag("host", "host2").addField("used_percent", 23.43234543).time(Instant.now(), WritePrecision.NS);
WriteApiBlocking writeApi2 = client.getWriteApiBlocking();
writeApi2.writePoint(bucket, org, point);
// 3. Use POJO and corresponding class to write data
Mem mem = new Mem();
mem.setHost("host3");
mem.setUsedPercent(23.43234543);
mem.setTime(Instant.now());
WriteApiBlocking writeApi3 = client.getWriteApiBlocking();
writeApi3.writeMeasurement(bucket, org, WritePrecision.NS, mem);
}
Aggregations