【问题标题】:Can't push metric values to InfluxDB无法将指标值推送到 InfluxDB
【发布时间】:2016-10-18 16:26:29
【问题描述】:

我尝试通过以下方式将一些测试指标推送到 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 日志是空的。

【问题讨论】:

    标签: python python-3.x influxdb


    【解决方案1】:

    time 字段格式实际上存在问题。我将其更改为以下内容:

    "time": datetime.utcnow().replace(minute=0, second=0, microsecond=0)
    

    然后一切都开始按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-27
      • 1970-01-01
      • 1970-01-01
      • 2016-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多