1 Star 0 Fork 0

卢甘霖/influxdb-java

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
INFLUXDB_MAPPER.md 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
gkatzioura 提交于 7年前 . Added spaces and commas

InfluxDBMapper

In case you want to use models only, you can use the InfluxDBMapper to save and load measurements. You can create models that specify the database the measurement and the retention policy.

@Measurement(name = "cpu",database="servers", retentionPolicy="autogen",timeUnit = TimeUnit.MILLISECONDS)
public class Cpu {
    @Column(name = "time")
    private Instant time;
    @Column(name = "host", tag = true)
    private String hostname;
    @Column(name = "region", tag = true)
    private String region;
    @Column(name = "idle")
    private Double idle;
    @Column(name = "happydevop")
    private Boolean happydevop;
    @Column(name = "uptimesecs")
    private Long uptimeSecs;
    // getters (and setters if you need)
}

Save operation using a model.

Cpu cpu = .., create the cpu measure
influxDBMapper.save(cpu);

Load data using a model.

Cpu persistedCpu = influxDBMapper.query(Cpu.class).get(0);

Load data using a query and specify the model for mapping.

Query query = ... create your query
List<Cpu> persistedMeasure = influxDBMapper.query(query,Cpu.class);

InfluxDBMapper limitations

Tags are automatically converted to strings, since tags are strings to influxdb Supported values for fields are boolean, int, long, double, Boolean, Integer, Long, Double. The time field should be of type instant. If you do not specify the time or set a value then the current system time shall be used with the timeunit specified.

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/Ganlin_Lu/influxdb-java.git
git@gitee.com:Ganlin_Lu/influxdb-java.git
Ganlin_Lu
influxdb-java
influxdb-java
master

搜索帮助