yijia2413 / collections

useful collections from the Internet.
MIT License
0 stars 0 forks source link

influxdb-grafana-docker-compose.yml #1

Open yijia2413 opened 4 years ago

yijia2413 commented 4 years ago

docker-compose.yml

version: '3.5'
services:
  influxdb:
    image: influxdb:1.8.1-alpine
    ports:
      - "8086:8086"
    restart: always
    healthcheck:
      test: ["CMD-SHELL", "wget --server-response --spider --quiet http://localhost:8086/ping"]
    volumes:
      - influxdb-storage:/var/lib/influxdb/
    environment:
      - INFLUXDB_DB=db0
      - INFLUXDB_ADMIN_USER=root
      - INFLUXDB_ADMIN_PASSWORD=root

  chronograf:
    image: chronograf:latest
    ports:
      - "8888:8888"
    restart: always
    healthcheck:
      test: ["CMD-SHELL", "ps aux | grep chronograf | grep -v grep || exit 1"]
    depends_on:
      - influxdb
  grafana:
    image: grafana/grafana:latest
    ports:
      - '3000:3000'
    volumes:
      - grafana-storage:/var/lib/grafana
    depends_on:
      - influxdb
    environment:
      - GF_SECURITY_ADMIN_USER=admin
      - GF_SECURITY_ADMIN_PASSWORD=admin
volumes:
  influxdb-storage:
  grafana-storage:

Just change users, passwords with your own settings, then run docker-compose up -d

enable flux

docker exec -it ${your_influxdb_container} influx

 cat << EOF >> /etc/influxdb/influxdb.conf
[http]
flux-enabled = true
EOF
yijia2413 commented 4 years ago

init db and set retention policies

healthcheck:
      # not a good idea create db here, but works fine
      test: "wget --server-response --spider --quiet http://localhost:8086/ping \
        && [[ -e /tmpflag ]] || (touch /tmpflag && echo 'create database prometheus' | influx \
        && echo 'create database koios' | influx \
        && echo 'alter RETENTION POLICY \"autogen\" on aiops duration 30d REPLICATION  1' | influx \
        && echo 'alter RETENTION POLICY \"autogen\" on koios duration 30d REPLICATION  1' | influx \
        && echo 'alter RETENTION POLICY \"autogen\" on prometheus duration 30d REPLICATION  1' | influx)"
      interval: 3s
      timeout: 10s
      retries: 10

因为 healthcheck 是持续运行的,所以用 shell 创建一个临时文件作为 flag,如果没创建,则创建,并建立数据库,设置retention等;如果文件已经存在,则后续代码不执行,只检查ping