User Tools

Site Tools


adm:using_influxdb_api

Using the Influx Command Line Interface

Install influx client

sudo apt install influxdb-client

Setup Admin User

Start influx terminal with command “influx”

influx
>>>CREATE USER influx WITH PASSWORD 'yourSecretInfluxPassword' WITH ALL PRIVILEGES;

>>>SHOW USERS;

Type influx on the local host where influx is installed. There are many useful commands, such as:

Using Influx on localhost with SSL installed

influx -ssl -unsafeSsl -username '<username>' -password '<passwd>' -format=json -pretty


>SHOW DATABASES   #will list databases
>USE <database>
>SELECT * FROM "mqttData"
>DROP DATABASE <database name>   #will delete database permanently!

Using the Influx DB api

It may be useful to run a query on the influx DB from the command line, for trouble shooting, or if you want to obtain raw data to integrate into other applications.

If you haven't disabled it, then by default you should be able to run queries like this:

From the influx DB docs

curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=mydb" --data-urlencode "q=SELECT \"value\" FROM \"cpu_load_short\" WHERE \"region\"='us-west'"

Using typical Zibawa data

curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=dab31" --data-urlencode "q=SELECT \"value\" FROM \"mqttData\" "

For db, use “dab”+ your account number. (This number should also be what appears on your Grafana Datasource).

Substitute “value” for whatever you are using as a json key for the data you are sending.

Value must be for your DATA and not a TAG.

This should give response:

> SELECT * FROM "mqttData"
{
    "results": [
        {
            "series": [
                {
                    "name": "mqttData",
                    "columns": [
                        "time",
                        "channel_id",
                        "device_id",
                        "status",
                        "value"
                    ],
                    "values": [
                        [
                            1487703089000000000,
                            "1",
                            "1",
                            "testing",
                            2189.22
                        ]
                    ]
                }
            ]
        }
    ]
}

Currently Zibawa only uses one table “mqttData”.

Making Queries

A typical query would be

select * from mqttData where device_id = x5df6 and channel_id = 1 limit 1;
adm/using_influxdb_api.txt · Last modified: 2017/10/19 19:14 by matt