Connecting and accessing data from InfluxDB to Jupyter Notebook

Hey ,

I have been trying to access influxdb self hosted data through jupyter notebook.
ref link: Streaming Time Series with Jupyter and InfluxDB | Blog | InfluxData
.
from influxdb import InfluxDBClient
from datetime import datetime
import os

from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS
client= InfluxDBClient(url="", token=token, org=org,bucket=bucket,host=influxdb_host)

Code has been sucessfully executed upto here and i have been trying the next step suggested in the ref link and have been getting an import error for stream although i have sucessfully imported hvplot.

def source_data(auto_refresh: int, query: str, sink: Stream):
    rx \
        .interval(period=timedelta(seconds=auto_refresh)) \
        .pipe(ops.map(lambda start: f'from(bucket: "my-bucket") '
                                    f'|> range(start: -{auto_refresh}s, stop: now()) '
                                    f'{query}')) \
        .pipe(ops.map(lambda query: client.query_api().query_data_frame(query, data_frame_index=['_time']))) \
        .pipe(ops.map(lambda data_frame: data_frame.drop(columns=['result', 'table']))) \
        .subscribe(observer=lambda data_frame: sink.emit(data_frame), on_error=lambda error: print(error))
    pass

Is this the right way to extract the self hosted data to jupyter notebook ? or have I been looking into the wrong references.

Please suggest any reference links to extract selfhosted data from influx db to jupyter notebook.

Thanks,
Deepika

Hi @Deepika,

thanks for using our client.

Do you have installed the streamz?

This is an example how to “stream” data from InfluxDB to Jupiter Notebook. There is also a simple example: “How to query data from InfluxDB 2.0 using Flux and predict the stock price. (ML example using Keras)”:

Regards

Hi @Deepika,

Did you get it working?

I’m trying to do something similar with a Notebook and InfluxDB but using a simple IoT table of power in watts recorded every 1 second, with unix time (no ms or ns).

I seem to be getting a table OK but it’s not being populated. Or it’s not handling the scale properly.
I tried to use the cpu example as a template but my power values go from around 100w to 3000w wheras the cpu example is expecting a cpu %age. Could be that maybe?

Cheers
Vitch