influxdb使用笔记

2019-11-22  本文已影响0人  魂狩

安装方式

#ubuntu下
curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add -
source /etc/lsb-release
echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
apt update
apt-get install influxdb

配置文件位于/etc/influxdb/influxdb.conf

重要语句:

笔记

简单demo:

from influxdb import InfluxDBClient
import datetime
client = InfluxDBClient('10.10.10.10', 8086, 'admin', 'admin', 'test') # ip 端口 用户名 密码 数据库名
body = [
    {
        "measurement": "hello",
        "tags": {
            "class": 1
        },
        "fields": {
            "name": "Hyc",
            "age": 3
        },
    }
]
client.write_points(body)
t=datetime.datetime.utcnow().isoformat()+'z'
result = client.query("select * from hello where time < '%s' order by time desc"%t)
t=result.get_points()
for x in t:
    print(x)
 #聚合时可以选择按天,中国时区,这样可以避免结果多一天的情况
result = client.query("SELECT count(age) FROM hello where time >= '2019-10-18T00:00:00+08:00' and time < '2019-10-23T00:00:00+08:00' group by time(1d) TZ('Asia/Shanghai')")
t=result.get_points()
for x in t:
    print(x)
上一篇下一篇

猜你喜欢

热点阅读