Etaoin Etaoin - 1 year ago 190
Python Question

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((, second=0, microsecond=0)).isoformat()).replace('"', '')

return fake_point


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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download