InfluxDB Setting¶
Docker-compose.yaml configuration for Influx v1.x¶
influxdb:
restart: on-failure:3
image: influxdb:1.8
ports:
- "8083:8083"
- "8086:8086"
- "8090:8090"
volumes:
- /<path_on_host>/<where_you_want_data>:/var/lib/influxdb
environment:
- INFLUXDB_DB=<your_db>
- INFLUXDB_USER=telegraf
- INFLUXDB_ADMIN_ENABLED=true
- INFLUXDB_ADMIN_USER=<your_user>
- INFLUXDB_ADMIN_PASSWORD=<your_password>
logging:
options:
max-size: 10m
Docker-compose.yaml configuration for Influx v2.x¶
influxdb:
image: influxdb:2.0.4
restart: 'always'
ports:
- "8086:8086"
volumes:
- /data/influxdb/data:/var/lib/influxdb2
environment:
- DOCKER_INFLUXDB_INIT_MODE=setup
- DOCKER_INFLUXDB_INIT_USERNAME=telegraf
- DOCKER_INFLUXDB_INIT_PASSWORD=my-password
- DOCKER_INFLUXDB_INIT_ORG=my-org
- DOCKER_INFLUXDB_INIT_BUCKET=my-bucket
- DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=my-super-secret-auth-token
Run InfluxDB container¶
docker-compose up -d
Use UI interface on:¶
http://localhost:8086/
How to write/delete data using CLI influx:¶
docker exec -it <influx-container> bash
influx write \
-b my-bucket \
-o my-org \
-p s \
'myMeasurement,host=myHost testField="testData" 1556896326' \
-t ${your-token}
influx delete \
-bucket my-bucket \
--org my-org \
--start 2001-03-01T00:00:00Z \
--stop 2021-04-14T00:00:00Z \
--token ${your-token}
Setting up retention policy¶
Retention policy controls how long do you want to keep data in the influxdb, you setup a name for your policy, which databse is affected, how long will you keep the data, replication and finaly group (DEFAULT in the case below) DEFAULT is used for all sources that do not specify the group when inserting data to InfluxDB.
docker exec <container_name> influx -execute CREATE RETENTION POLICY "<name_your_policy>" ON "<your_db>" DURATION 47h60m REPLICATION 1 DEFAULT
Altering an existing policy¶
docker exec <container_name> influx -execute ALTER RETENTION POLICY "autogen" on "<dbs>/<affected>" duration 100d
Deleting old data¶
Mind the quotation marks
delete from "<collection>" where "<field>" = '<value>'
Deleting old data in a specific field¶
When reconfiguring your sources, you may want to get rid of some old values in specific fields, so they do not clog your visualizations. You may do so using the folloging command:
docker exec <container_name> influx -execute DROP SERIES WHERE "<tag_key>" = '<tag_value>'
Downsampling¶
https://docs.influxdata.com/influxdb/v1.8/guides/downsample_and_retain/ if want to use multiple rules for different data sources, use the group name other than DEFAULT and configure your sources accordingly, for example in telegraf use:
Specific retention policies example (telegraf)¶
Used when you want to set different retention on different sources.
[[outputs.influxdb]
]
## Name of existing retention policy to write to. Empty string writes to
## the default retention policy. Only takes effect when using HTTP.
# retention_policy = "**telegraf1**"
docker exec <container_name> influx -execute CREATE RETENTION POLICY "<name_your_policy>" ON "<your_db>" DURATION 47h60m REPLICATION 1 **telegraf1**