I am not able to write json files into a influx database in a local server.Are there any code files which I can go through?
Firstly, how are you trying to write JSON into InfluxDB? Are you talking
directly into InfluxDB or are you going via something such as telegraf?
Secondly, are you really trying to put an entire JSON record into Influx as a
single entry, or are you expecting to parse out the keys and values into
different Influx fields?
Thirdly, please show us exactly what you are doing and what error message you
get, or what fails to work, so we have some idea of where to start with
diagnosing your problem.
Antony.
I have a nested json.
for example:
{ ''compute 1" :{ ‘index’:0, ‘fan attributes’:[ {‘max speed’ : 200,‘min speed’:100},{max speed:300,‘min speed’ : 200}…],‘thermal sensor’ : [ {} ,{},…]}
“compute 2”:{},…}
I am trying to write this json file into influxdb directly using the code:
client.write_points(json_data,database=‘mydb’)
and I got the following errors:
1)point.get(‘measurement’, data.get(‘measurement’))))
AttributeError: ‘str’ object has no attribute 'get
I realised that write points will work only for a list of dictionaries
so then the appended the entire dictionary to a list by doing:
list_=
list_.append(json_data)
and then passed list_ through write points.Then I got the following error:
2)for field_key, field_value in sorted(iteritems(point[‘fields’])):
KeyError: ‘fields’
I am starting to learn this software and was wondering how to solve this problem.
Thank you.
Hi HarshitaVemula.
You need to convert json data to points before calling write_points.
a point contains measurement, tags, fields, and time.
{
"measurement": "cpu_load_short",
"tags": {
"host": "server01",
"region": "us-west"
},
"time": "2009-11-10T23:00:00Z",
"fields": {
"value": 0.64
}
}
Examples:
https://influxdb-python.readthedocs.io/en/latest/include-readme.html#examples
Concepts: