to access and controol influx db from its originated dashboard you can use this url:
ip(srvr):port(influx) ip:8086
structure of the influx db line protocol:
,<tag_key>=<tag_value> <field_key>=<field_value>
sample of data filing via pythoon:
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS
client = InfluxDBClient(url="http://localhost:8086", token="your-token", org="your-org")
write_api = client.write_api(write_options=SYNCHRONOUS)
point = Point("system_metrics") \
.tag("host", "server1") \
.tag("region", "us-west") \
.field("cpu_usage", 75.4) \
.field("memory_usage", 2048) \
.time(datetime.utcnow(), WritePrecision.NS)
write_api.write(bucket="your-bucket", record=point)
Influx CLI shell version is 1.6.7~rc0, is outdated and incompatible with InfluxDB 2.x.
Let’s install InfluxDB 2.x.
The influx
CLI version 1.6.7 is for InfluxDB 1.x, and it won’t work with InfluxDB 2.x. You need to install the InfluxDB 2.x CLI.
-
Download the CLI:
wget https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.7.3-linux-amd64.tar.gz
-
Extract the Archive:
tar xvzf influxdb2-client-2.7.3-linux-amd64.tar.gz
-
Move the Binary to
/usr/local/bin
:sudo mv influx /usr/local/bin/
-
Verify the Installation:
influx version
You should see something like:
Influx CLI 2.7.3 (git: fe6d7e6) build_date: 2023-10-10T16:30:34Z
Now that you have the correct CLI, let’s configure it to connect to your InfluxDB 2.x server.
-
Set Up a Configuration:
influx config create \ -n NAME_OF_CONFIG \ -u http://localhost:8086 \ -o ORG_NAME \ -t YOUT_TOKEN_HERE
-
Verify the Configuration:
influx config ls
-
Test the Connection:
influx ping
If successful, you’ll see:
{ "version": "2.6.1", "status": "ready" }
Now that you have the correct CLI installed and configured, here are the essential commands:
-
Check Version:
influx version
-
Ping the Server:
influx ping
-
List Organizations:
influx org list
-
List Buckets:
influx bucket list
-
List Tokens:
influx auth list
-
Write Data Using Line Protocol:
influx write --bucket your-bucket --precision ns "measurement,tag=value field=value timestamp"
Example:
influx write --bucket my-bucket --precision ns "cpu,host=server1 usage=75.4 1696166400000000000"
-
Write Data from a File:
influx write --bucket your-bucket --file /path/to/data.txt
-
Run a Flux Query:
influx query 'from(bucket: "your-bucket") |> range(start: -1h) |> filter(fn: (r) => r._measurement == "cpu")'
-
Export Query Results to CSV:
influx query 'from(bucket: "your-bucket") |> range(start: -1h)' --raw > output.csv
-
Delete Data:
influx delete --bucket your-bucket --start 2023-01-01T00:00:00Z --stop 2023-01-02T00:00:00Z --predicate '_measurement="cpu"'
-
Backup Data:
influx backup /path/to/backup --bucket your-bucket
-
Restore Data:
influx restore /path/to/backup
-
List Tasks:
influx task list
-
Create a Task:
influx task create --file /path/to/task.flux
-
Delete a Task:
influx task delete --task-id your-task-id
- Open your browser and navigate to
http://<your-server-ip>:8086
. - Use the Data Explorer to write Flux queries and visualize data.
- Check Buckets under Load Data to see stored data.
-
List All Measurements:
influx query 'from(bucket: "your-bucket") |> range(start: -1h) |> keys() |> keep(columns: ["_measurement"]) |> distinct()'
-
List All Fields in a Measurement:
influx query 'from(bucket: "your-bucket") |> range(start: -1h) |> filter(fn: (r) => r._measurement == "cpu") |> keys() |> keep(columns: ["_field"]) |> distinct()'
-
Query Specific Data:
influx query 'from(bucket: "your-bucket") |> range(start: -1h) |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage")'
-
Count Data Points:
influx query 'from(bucket: "your-bucket") |> range(start: -1h) |> filter(fn: (r) => r._measurement == "cpu") |> count()'
-
Check Logs: InfluxDB logs are located at
/var/log/influxdb/
. Usetail
to monitor logs in real-time:tail -f /var/log/influxdb/influxd.log
-
Check Disk Usage: Ensure your server has enough disk space for InfluxDB data:
df -h
-
Check InfluxDB Service Status:
sudo systemctl status influxdb
- Install the correct InfluxDB 2.x CLI.
- Configure the CLI with your organization and token.
- Use the provided commands to write, query, and manage data.
- Use the web dashboard for visualization and the CLI for advanced queries and management.
Let me know if you encounter any further issues!