我尝试以下列方式将一些测试指标推送到Influxdb:
import random
import json
from datetime import datetime
from influxdb import InfluxDBClient
test_client = InfluxDBClient("localhost", 8086, "myuser", "mypassword", "test")
def generate_send_fake(measname):
fake_point = [{
"measurement": measname,
"fields": {"value": random.randint(0, 100)},
"time": json.dumps((datetime.now().replace(minute=0, second=0, microsecond=0)).isoformat()).replace('"', '')
}]
return fake_point
test_client.write_points(generate_send_fake('test_meas_one'))
test_client.write_points(generate_send_fake('test_meas_two'))
此代码执行时没有错误/警告。但是,当我尝试通过InfluxDB控制台检查我的数据时,我看到以下内容:
> use test
Using database test
> show measurements
name: measurements
------------------
name
test_meas_one
test_meas_two
> select * from "test_meas_one"
> select * from "test_meas_two"
换句话说,虽然已经创建了指标本身,但没有数据点。我使用Ubuntu 16.04(64位)和Python 3.5。
如果重要的话,InfluxDB日志是空的。
答案 0 :(得分:1)
time
字段格式实际上存在问题。我将其更改为以下内容:
"time": datetime.utcnow().replace(minute=0, second=0, microsecond=0)
然后一切都按预期开始工作。