简体   繁体   中英

Can't push metric values to InfluxDB

I try to push some test metrics to Influxdb in a following manner:

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'))

This code executes without errors/warnings. However, when I try to check my data through InfluxDB console I see following:

> 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"

In other words, there are no data points, though metrics themselves were created. I use Ubuntu 16.04 (64-bit) and Python 3.5.

InfluxDB log is empty if that matters.

There was actually a problem with time field format. I changed it to following:

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

And then everything began to work as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM