Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write into influxdb using line Protocol with Python

I am using line protocol and Python to write into InfluxDB. Below is the code that creates DB and working fine.

 client = InfluxDBClient(host, port, user, password, dbname)
    print("Creating database: " + dbname)
    client.create_database(dbname)
    print("Database created: " + dbname)

I want to write below mention sample data using Line protocol into influxDB

Sample lines of data of Line protocol looks like

interface,path=address,element=link value=3
interface,path=address,element=link value=7
interface,path=address,element=link value=4

I am using latest version of InfluxDB which supports line protocol.

Any idea about how the client.write statement looks like for python client?

like image 481
Ammad Avatar asked Feb 06 '23 07:02

Ammad


1 Answers

You can use line protocol from python3 to insert data.

    >>> from influxdb import InfluxDBClient 
    >>> client = InfluxDBClient(host='127.0.0.1', port=8086, username='admin', password='password', ssl=False, verify_ssl=False)
    >>> client.write(['interface,path=address,elementss=link value=3'],{'db':'yourdb'},204,'line')
like image 54
kavinda Avatar answered Feb 25 '23 04:02

kavinda