InfluxDB

InfluxDB

https://docs.influxdata.com/influxdb/v1.8/administration/authentication_and_authorization/

Flux

https://docs.influxdata.com/flux/v0.x/get-started/

Queries

SQL

CREATE USER polyU_HK WITH PASSWORD '***'
GRANT READ ON "telegraf" TO "***"
SHOW DATABASES
USE database
SHOW measurements
SELECT * FROM measurements
create retention policy "rp_f26" on "telegraf" duration 3w replication 1 default
drop retention policy "auto_gen"

Query the latest record only.

SELECT LAST("tag_value") FROM "kafka_consumer" WHERE ("host"='f26dht') AND ("tag_code"='v5678')

docker compose influxdb and telegraf

services:

  telegraf:
    image: telegraf:latest
    volumes:
    - ./telegraf/etc/telegraf.conf:/etc/telegraf/telegraf.conf:ro
    depends_on:
      - influxdb
    links:
      - influxdb
    networks:
      - dtlab
    ports:
    - '8125:8125'
  influxdb:
    image: influxdb:latest
    container_name: influxdb
    restart: always
    environment:
      - INFLUXDB_DB=cadslab
      - INFLUXDB_ADMIN_USER=cadslab
      - INFLUXDB_ADMIN_PASSWORD=cadslab
    networks:
      - dtlab
    ports:
      - '8086:8086'
    volumes:
      - influxdb_data:/var/lib/influxdb

  # telegraf:
  #   image: telegraf:latest
  #   volumes:
  #   - ./telegraf/etc/telegraf.conf:/etc/telegraf/telegraf.conf:ro
  #   depends_on:
  #     - postgres
  #   links:
  #     - postgres
  #   networks:
  #     - dtlab
  #   ports:
  #   - '8125:8125'
  # postgres:
  #   image: postgres:latest
  #   restart: always
  #   ports:
  #     - '5432:5432'
  #   environment:
  #     POSTGRES_PASSWORD: postgres
  #     POSTGRES_USER: postgres
  #     POSTGRES_DB: postgres
  #   networks:
  #     - dtlab
  #   volumes:
  #     - postgres_storage:/var/lib/postgresql/data


networks:
  dtlab:
    driver: bridge

volumes:
  influxdb_data: {}
  postgres_storage: {}

Mannual backup and restore

# Let's get into the container
docker exec -it addon_a0d7b954_influxdb bash

# We create a temporary backup directory
mkdir -p /share/backup/influxdb/

# Create the backup to our new share directory
influxd backup -database homeassistant -portable /share/backup/influxdb/

# Exit the container
exit

# (Optional) Set so all users can read the backup data
sudo chmod a+r /usr/share/hassio/share/backup/influxdb/*

# (Optional) Afterwards remove the backup
sudo rm -rf /usr/share/hassio/share/backup/influxdb/*
Previous
Next