TestInflux
package com.abc; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; public class TestInflux { public static void main(String[] args) throws Exception { //user、password、url(http://ip:port)、database、retention policy //retention policy:数据存储策略(默认策略为autogen,会永久保留数据)InfluxDB没有删除数据操作,规定数据的保留时间达到清除数据的目的 InfluxDBConnection influxDBConnection = new InfluxDBConnection("admin", "admin", "http://127.0.0.1:8086", "db_name", ""); //influxdb的tag表示带索引的列,非必须。tag只能为字符串类型。 Map<String, String> tags = new HashMap<String, String>(); tags.put("tag", "abc"); //influxdb的field表示不带索引的列。field 类型无限制 Map<String, Object> fields = new HashMap<String, Object>(); fields.put("field1", 1234); fields.put("field2", "xyzfeafef"); // 数值型,InfluxDB的字段类型,由第一天插入的值得类型决定 // fields.put("field3", 3.141592657); //influxdb使用timestemp(唯一主键) // 时间使用毫秒为单位 influxDBConnection.insert("table_name", tags, fields); } }
有些事情,没经历过不知道原理,没失败过不明白奥妙,没痛苦过不了解真谛。临渊羡鱼,不如退而结网!

浙公网安备 33010602011771号