0

我正在尝试使用 python 将一些测试数据插入到 InfluxDB 中,但是在查询数据时没有插入数据。

你知道可能是什么问题吗?

我正在使用文档中的代码:

from influxdb import InfluxDBClient


def main(host='localhost', port=8086):
    user = 'root'
    password = 'root'
    dbname = 'example'

    query = 'select value from cpu_load_short;'
    json_body = [
        {
            "measurement": "cpu_load_short",
            "tags": {
                "host": "server01",
                "region": "us-west"
            },
            "time": "2009-11-10T23:00:00Z",
            "fields": {
                "value": 0.64
            }
        }
    ]

    client = InfluxDBClient(host, port, user, password, dbname)

    #client = InfluxDBClient(host, port)

    print("Create database: " + dbname)
    client.create_database(dbname)

    print("Create a retention policy")
    client.create_retention_policy('awesome_policy', '3d', 3, default=True)


    print("Write points: {0}".format(json_body))
    client.write_points(json_body)

    print("Querying data: " + query)
    result = client.query(query)

    print("Result: {0}".format(result))




if __name__ == '__main__':

    main()    

当我从 CLI 检查数据库已成功创建但它为空时,这是代码的输出:

结果:'ResultSet({})'

谢谢!

4

0 回答 0