-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data is not inserting into InfluxDB 2.0 through python client influxdb_client #90
Comments
Hi @ssaurav-1987, If you want to use the client = InfluxDBClient(url=URL, token=TOKEN, org=ORG)
write_api = client.write_api(write_options=ASYNCHRONOUS)
datasave = write_api.write(BUCKET, ORG, series) #Writing to Influx
datasave.get()
print("DB Written : ", series) Please consider use a batching API if your file is huge. We have an example for that: import_data_set.py. Regards |
Hi
Hi @bednar Thank you for helping me here, but have some confusion.
|
I tried above continious query in influx 1.8 |
|
|
Let's try write a small piece of your data into InfluxDB 2 by synchronous configuration and we will see where is a problem: write_api = client.write_api(write_options=SYNCHRONOUS) |
I tried with SYNCHRONOUS now and for datasave.get() function it is giving error: and After removing of datasave.get() from code and executed code and below output: |
But no data is entered into DB |
Try initiliaze client with debug and you will see pure HTTP request/response client = InfluxDBClient(url="http://localhost:9999", token="my-token", org="my-org", debug=True) |
I enabled Debug and got this in response: Total record : 1 |
I think that the problem is in your |
Okay, let me convert to UTC and will try to submit again |
Hi @bednar |
It looks like you mix field that is |
Hi @bednar It is working, I will have to lot of R&D in there. Also sharing some continuous query link, please have a look one you free, I am unable to get how to set this query. https://www.youtube.com/watch?v=0syXa8cBY-Y Thank you once again, means alot to get help here. |
I have written python script in that I am collecting data from spreadsheet and making list of json data that will be json object that have list of json data. I have configured bucket, organisation, token. And tried to insert DB but it is not inserting into DB and even I am not getting error into that
Please find below my code and kindly help me where I am missing:
#!/opt/anaconda3/bin/python3
from influxdb_client import InfluxDBClient
from influxdb_client.client.write_api import ASYNCHRONOUS
import random
import json
from datetime import datetime
import pandas as pd
import logging
logging.basicConfig(filename='/InfluxDB/test.log', format='%(filename)s: %(message)s',level=logging.DEBUG)
excel_data_df = pd.read_excel('/RouterSwitchData.xlsx')
json_data = json.loads(excel_data_df.to_json(orient='records'))
series=[]
counter=0
json_body={}
for item in json_data:
current_traffic_signal = random.uniform(1.00,8.00)
json_body = {
"measurement": "devicelink",
"tags": {
"devicename": item["DeviceName"],
"device_circle": item["Circle"],
"device_subcircle":item["SubCircle"],
},
"time": datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"),
"fields": {
"device_name": item["DeviceName"],
"device_ip_address":item["IP_Address_Device"],
"device_port":item["port"],
"device_circle":item["Circle"],
"device_subcircle":item["SubCircle"],
"neighbour_device_name":item["Neighbour_Device"],
"neighbour_device_ip_address":item["IP_Address_Neighbour_Dev"],
"neighbour_device_port": item["Neighbour_dev_port"],
"neighbour_device_circle":item["Neighbour_Circle"],
"neighbour_device_subcircle":item["Neighbour_subcircle"],
"device_link_capacity":item["capacity_of_link(gig/sec)"],
"device_threshold%":item["Threshold(%)"],
"current_taffic_signal":(current_traffic_signal),
"current_traffic_rate %":((current_traffic_signal/int(item['capacity_of_link(gig/sec)']))*100)
}
series.append(json_body)
#jsondata= json.dumps(series)
counter=counter+1
print("Total record : ",counter)
URL="http://localhost:9999"
TOKEN=$TOKEN
ORG="analytics"
BUCKET="DeviceAnalysis"
client = InfluxDBClient(url=URL, token=TOKEN, org=ORG)
write_api = client.write_api(write_options=ASYNCHRONOUS)
datasave = write_api.write(BUCKET, ORG, series) #Writing to InfluxDB
print("DB Written : ",datasave)
The text was updated successfully, but these errors were encountered: