diff --git a/.env b/.env index 6da89c6..e12c467 100644 --- a/.env +++ b/.env @@ -1,5 +1,12 @@ -INFLUXDB_USERNAME=admin -INFLUXDB_PASSWORD=admin - -GRAFANA_USERNAME=admin -GRAFANA_PASSWORD=admin +INFLUXDB_USERNAME=admin +INFLUXDB_PASSWORD=secure_influx_adm_password +INFLUXDB_ORG=my_org +INFLUXDB_BUCKET=default_bucket +INFLUXDB_ADMIN_TOKEN=a_secure_admin_token +V1_DB_NAME=db0 +V1_RP_NAME=v1-rp +V1_AUTH_USERNAME=v1_admin +V1_AUTH_PASSWORD=v1_secure_password + +GRAFANA_USERNAME=root +GRAFANA_PASSWORD=root diff --git a/README.md b/README.md index 26fb99b..0bf77f9 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ Multi-container Docker app built from the following services: Useful for quickly setting up a monitoring stack for performance testing. Combine with [serverless-artillery](https://github.com/Nordstrom/serverless-artillery) and [artillery-plugin-influxdb](https://github.com/Nordstrom/artillery-plugin-influxdb) to create a performance testing environment in minutes. +Now with built-in support for influxDB 2.x + ## Quick Start To start the app: @@ -68,10 +70,14 @@ The app creates a default InfluxDB database called `db0`. ## Data Sources -The app creates a Grafana data source called `InfluxDB` that's connected to the default IndfluxDB database (e.g. `db0`). +The app creates two Grafana data sources called `InfluxDB(GraphQL)` (with legacy authentication) and `InfluxDB(Flux)` which are connected to the default IndfluxDB database. To provision additional data sources, see the Grafana [documentation](http://docs.grafana.org/administration/provisioning/#datasources) and add a config file to `./grafana-provisioning/datasources/` before starting the app. +## InfluxDB scripts + +Scripts located in `influxDB-scripts` are excuted after the inital setup task of influxDB. At the moment, the script `setup-v1.sh` takes care of the `dbrp` mappings and the creation of v1 compatible users. + ## Dashboards By default, the app does not create any Grafana dashboards. An example dashboard that's configured to work with [artillery-plugin-influxdb](https://github.com/Nordstrom/artillery-plugin-influxdb) is located at `./grafana-provisioning/dashboards/artillery.json.example`. To use this dashboard, rename it to `artillery.json`. diff --git a/docker-compose.yml b/docker-compose.yml index 37b3fb0..ae77983 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,10 +6,18 @@ services: - '8086:8086' volumes: - influxdb-storage:/var/lib/influxdb + - ./influxDB-scripts:/docker-entrypoint-initdb.d environment: - - INFLUXDB_DB=db0 - - INFLUXDB_ADMIN_USER=${INFLUXDB_USERNAME} - - INFLUXDB_ADMIN_PASSWORD=${INFLUXDB_PASSWORD} + - DOCKER_INFLUXDB_INIT_MODE=setup + - DOCKER_INFLUXDB_INIT_USERNAME=${INFLUXDB_USERNAME} + - DOCKER_INFLUXDB_INIT_PASSWORD=${INFLUXDB_PASSWORD} + - DOCKER_INFLUXDB_INIT_ORG=${INFLUXDB_ORG} + - DOCKER_INFLUXDB_INIT_BUCKET=${INFLUXDB_BUCKET} + - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=${INFLUXDB_ADMIN_TOKEN} + - V1_DB_NAME=${V1_DB_NAME} + - V1_RP_NAME=${V1_RP_NAME} + - V1_AUTH_USERNAME=${V1_AUTH_USERNAME} + - V1_AUTH_PASSWORD=${V1_AUTH_PASSWORD} chronograf: image: chronograf:latest ports: @@ -28,12 +36,18 @@ services: - '3000:3000' volumes: - grafana-storage:/var/lib/grafana - - ./grafana-provisioning/:/etc/grafana/provisioning + - ./grafana-provisioning/:/etc/grafana/provisioning/ depends_on: - influxdb environment: - GF_SECURITY_ADMIN_USER=${GRAFANA_USERNAME} - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD} + - V1_DB_NAME=${V1_DB_NAME} + - V1_AUTH_USERNAME=${V1_AUTH_USERNAME} + - V1_AUTH_PASSWORD=${V1_AUTH_PASSWORD} + - DOCKER_INFLUXDB_INIT_ORG=${INFLUXDB_ORG} + - DOCKER_INFLUXDB_INIT_BUCKET=${INFLUXDB_BUCKET} + - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=${INFLUXDB_ADMIN_TOKEN} volumes: influxdb-storage: chronograf-storage: diff --git a/grafana-provisioning/datasources/datasource.yml b/grafana-provisioning/datasources/datasource.yml index 29f8f09..6cde4ff 100644 --- a/grafana-provisioning/datasources/datasource.yml +++ b/grafana-provisioning/datasources/datasource.yml @@ -1,11 +1,25 @@ apiVersion: 1 datasources: - - name: InfluxDB + - name: InfluxDB(GraphQL) type: influxdb access: proxy - database: db0 - user: admin - password: admin + database: $V1_DB_NAME + user: $V1_AUTH_USERNAME + secureJsonData: + password: $V1_AUTH_PASSWORD url: http://influxdb:8086 isDefault: true editable: true + + - name: InfluxDB(Flux) + version: 2 + type: influxdb + access: proxy + url: http://influxdb:8086 + jsonData: + defaultBucket: $DOCKER_INFLUXDB_INIT_BUCKET + httpMode: POST + organization: $DOCKER_INFLUXDB_INIT_ORG + version: Flux + secureJsonData: + token: $DOCKER_INFLUXDB_INIT_ADMIN_TOKEN diff --git a/influxDB-scripts/setup-v1.sh b/influxDB-scripts/setup-v1.sh new file mode 100644 index 0000000..5a4ab0d --- /dev/null +++ b/influxDB-scripts/setup-v1.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +BUCKET_ID=`influx bucket list --name $DOCKER_INFLUXDB_INIT_BUCKET | tail -1 | head -c 16` + +influx v1 dbrp create \ + --bucket-id ${BUCKET_ID} \ + --db ${V1_DB_NAME} \ + --rp ${V1_RP_NAME} \ + --default \ + --org ${DOCKER_INFLUXDB_INIT_ORG} + + +influx v1 auth create \ + --username ${V1_AUTH_USERNAME} \ + --password ${V1_AUTH_PASSWORD} \ + --write-bucket ${BUCKET_ID} \ + --read-bucket ${BUCKET_ID} \ + --org ${DOCKER_INFLUXDB_INIT_ORG} \ No newline at end of file