Linux/InfluxDB: Difference between revisions
Appearance
< Linux
Created page with " == Preparing v1 access via InfluxDB 2.x == * Create token in gui * access influx command line (docker exec -it influxdb sh) <pre> </pre> Category:Linux/Services Category:Linux" |
mNo edit summary |
||
| (11 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
== Preparing v1 access via InfluxDB 2.x == | |||
* Create token in gui | |||
** "Load Data" -> "API Tokens" | |||
* Get Bucket ID | |||
** "Load Data" -> "Buckets" | |||
* Get Organization Name | |||
** "User" -> "About" -> "Organization Profile" -> "Name" | |||
== Create new v1 user == | |||
* Access influx command line (docker exec -it influxdb sh) | |||
<pre> | |||
influx v1 auth create -o {orgName} --username {newuser} --password {newpass} -t {token} --read-bucket {bucketID} --write-bucket {bucketID} | |||
</pre> | |||
== | == Settings in Node-RED == | ||
<pre> | <pre> | ||
version = 1.x | |||
database = from previous step (e.g. mybucket) | |||
username = {newuser} | |||
password = {newpass} | |||
</pre> | |||
== Settings in Grafana == | |||
<pre> | |||
Name: InfluxDB | |||
Default: true | |||
Query Language: InfluxQL | |||
URL: http://{containername}:8086 | |||
Allowed cookies: | |||
Timeout: | |||
Database: mybucket | |||
User: {newuser} | |||
Password: {newpass} | |||
HTTP Method: GET | |||
</pre> | </pre> | ||
== Export == | |||
* container_run_list-measurements.sh | |||
<pre> | |||
# Configuration | |||
CONTAINER_NAME="influxdb" | |||
ORG="org" | |||
TOKEN="1234==" | |||
# Get list of measurements | |||
docker exec $CONTAINER_NAME influx query --org $ORG --token "$TOKEN" --raw 'import "influxdata/influxdb/schema" schema.measurements(bucket: "mybucket")'\ | |||
| cut -d, -f4 | tail -n +5 | head -n -1 \ | |||
> measurements.txt | |||
</pre> | |||
* container_run_export-measurements.sh | |||
<pre> | |||
# Configuration | |||
CONTAINER_NAME="influxdb" | |||
ORG="org" | |||
BUCKET="mybucket" | |||
TOKEN="1234==" | |||
OUTPUT_DIR="./exports" | |||
# Create output directory | |||
mkdir -p $OUTPUT_DIR | |||
while read measurement; do | |||
measurement=$(echo "$measurement" | tr -d '\r\n') | |||
SAFE_MEAS=$(echo "$measurement" | tr '/ ' '__') | |||
echo "Exporting $measurement" | |||
docker exec influxdb influx query ' | |||
from(bucket: "'"$BUCKET"'") | |||
|> range(start: 0) | |||
|> filter(fn: (r) => r._measurement == "'"$measurement"'") | |||
|> filter(fn: (r) => r._time < time(v: "2025-07-01T00:00:00Z")) | |||
|> keep(columns: ["_time", "_value", "_measurement"]) | |||
' --token "$TOKEN" --org "$ORG" --raw > "$OUTPUT_DIR/${SAFE_MEAS}.csv" | |||
done < measurements.txt | |||
</pre> | |||
== Links == | |||
* https://community.influxdata.com/t/unable-to-connect-v1-clients-to-influxdbv2/21630/7 | |||
[[Category:Linux/Services]] | [[Category:Linux/Services]] | ||
[[Category:Linux]] | [[Category:Linux]] | ||
Latest revision as of 21:25, 10 July 2025
Preparing v1 access via InfluxDB 2.x
- Create token in gui
- "Load Data" -> "API Tokens"
- Get Bucket ID
- "Load Data" -> "Buckets"
- Get Organization Name
- "User" -> "About" -> "Organization Profile" -> "Name"
Create new v1 user
- Access influx command line (docker exec -it influxdb sh)
influx v1 auth create -o {orgName} --username {newuser} --password {newpass} -t {token} --read-bucket {bucketID} --write-bucket {bucketID}
Settings in Node-RED
version = 1.x
database = from previous step (e.g. mybucket)
username = {newuser}
password = {newpass}
Settings in Grafana
Name: InfluxDB
Default: true
Query Language: InfluxQL
URL: http://{containername}:8086
Allowed cookies:
Timeout:
Database: mybucket
User: {newuser}
Password: {newpass}
HTTP Method: GET
Export
- container_run_list-measurements.sh
# Configuration CONTAINER_NAME="influxdb" ORG="org" TOKEN="1234==" # Get list of measurements docker exec $CONTAINER_NAME influx query --org $ORG --token "$TOKEN" --raw 'import "influxdata/influxdb/schema" schema.measurements(bucket: "mybucket")'\ | cut -d, -f4 | tail -n +5 | head -n -1 \ > measurements.txt
- container_run_export-measurements.sh
# Configuration
CONTAINER_NAME="influxdb"
ORG="org"
BUCKET="mybucket"
TOKEN="1234=="
OUTPUT_DIR="./exports"
# Create output directory
mkdir -p $OUTPUT_DIR
while read measurement; do
measurement=$(echo "$measurement" | tr -d '\r\n')
SAFE_MEAS=$(echo "$measurement" | tr '/ ' '__')
echo "Exporting $measurement"
docker exec influxdb influx query '
from(bucket: "'"$BUCKET"'")
|> range(start: 0)
|> filter(fn: (r) => r._measurement == "'"$measurement"'")
|> filter(fn: (r) => r._time < time(v: "2025-07-01T00:00:00Z"))
|> keep(columns: ["_time", "_value", "_measurement"])
' --token "$TOKEN" --org "$ORG" --raw > "$OUTPUT_DIR/${SAFE_MEAS}.csv"
done < measurements.txt