Search code examples
pythonpython-3.xinfluxdb

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.


Solution

  • 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.