-1

I have filtered the bitrates from live streams and got the output below. I have constructed an API with Python and piped continuous data into influxdb, which should be monitored, like python api.py | python influx.py. However, I am unable to store this output into influxdb. If necessary I can show my API code.

Click here to show output to be stored in influxdb

#!usr/bin/python

import sys
import datetime
from influxdb import InfluxDBClient
from influxdb.client import InfluxDBClientError
from influxdb import DataFrameClient
import os
import time

client=InfluxDBClient('localhost',8086,'admin','admin',database='stackanm')
client.create_database('stackanm')
def store(bitrate,time):
      json=[
              {
              "measurement":"bitrates",
              "tags":{      
                       "time":time,
               "fields":{
                "bitrate":bitrate
                       }               
      }
      }
      ]
      client.write_points(json,time_precision='u')


f = os.fdopen(sys.stdin.fileno(),'r',0)
for line in f:
    elements = line.strip().split()
    if len(elements) == 1:
    bitrate = elements[0]

        unixtime = elements[1].split('.')
        stdtime = datetime.datetime.utcfromtimestamp(long(float(unixtime[1]))).strftime('%Y-%m-%dT%H:%M:%S')
        influxtime = ".".join([stdtime,unixtime[1]])
        store(bitrate,float(elements[1]),influxtime)

1 Answers1

0

You probably solved this by now but I just stumbled across it.

Are you sure that time is supposed to be listed as a tag?

I've been working on some python and influxdb stuff lately and have noticed that time seems to be outside of the tags in the JSON body.

Similar to:

 "points": [
        {
            "measurement": "cpu_load_short",
            "tags": {
                "host": "server01",
                "region": "us-west"
            },
            "time": "2009-11-10T23:00:00Z",
            "fields": {
                "value": 0.64
            }
        }
    ]
ddevalco
  • 1,209
  • 10
  • 20