I have created a database in InfluxD using Python with a code like this:
from influxdb import InfluxDBClient
host = 'xx.xxx.xx.xxx'
port = 8086
username = 'user'
password = 'password'
database = 'dbname'
client = InfluxDBClient(host = host,
port = port,
username = username,
password = password,
verify_ssl = True)
client.create_database(database)
I can see that the database has been created correctly by using:
client.get_list_database()
Result:
[{'name':'dbname'}]
After that, I sent some data (time series) to the database with the next code. As you can see, the data is stored in a data table (measurement) called Hourly_data
. I have checked that the information has been stored in the database by using Grafana. Just to let you know, the data that I sent to the database (dataframe
in the code) is a dataframe with a datetime
index called date
and several time series for different variables.
def data_to_influxdb(data,table_name):
connection_info = {'host' : "XX.XXX.XX.XXX",
'port' : 8086,
'user' : 'user',
'password' : 'password',
'database' : 'dbname',
'server_tz' : 'Atlantic/Canary',
'reference_tz': 'UTC'}
client = DataFrameClient(connection_info['host'], connection_info['port'], \
connection_info['user'], connection_info['password'], \
connection_info['database'])
client.write_points(data, measurement=table_name, \
database=connection_info['database'], protocol='json',
batch_size = 20000)
# Close session
client.close()
return
table_name = 'Hourly_data'
data_to_influxdb(dataFrame, tablename)
I want to get the date of the most recent data in the database (the date corresponding to the last written point). The problem comes when I try to query some data from the database using the DataFrameClient. I always get an empty dictionary, no matters what I code. I have tried with this code and several modifications, but nothing works:
connection_info = {'host' : "XX.XXX.XX.XXX",
'port' : 8086,
'user' : 'user',
'password' : 'password',
'database' : 'dbname'}
client = DataFrameClient(
host = connection_info['host'],
port = connection_info['port'],
username = connection_info['user'],
password = connection_info['password'],
database = connection_info['database'],
)
query = 'SELECT "*" FROM "dbname"."autogen"."Hourly_data"'
client.query(query = query)
This is what I get: {}
Other alternatives that I have used:
query = 'SELECT * FROM dbname'
query = 'SELECT * FROM XXX' # wrong name on purpose also turns out into an empty dict {}
I checked the retention policy and it seems to be fine:
client.query('SHOW RETENTION POLICIES')
ResultSet({'('results', None)': [{'name': 'autogen', 'duration': '0s', 'shardGroupDuration': '168h0m0s', 'replicaN': 1, 'default': True}]})