Save time with InfluxDB stacks

Save time and money using InfluxDB stacks. Here’s a few ideal use cases:

Automate deployments with GitOps and stacks

GitOps is popular way to configure and automate deployments. Use InfluxDB stacks in a GitOps workflow to automatically update distributed instances of InfluxDB OSS or InfluxDB Cloud.

To automate an InfluxDB deployment with GitOps and stacks, complete the following steps:

  1. Set up a GitHub repository
  2. Add existing resources to the GitHub repository
  3. Automate the creation of a stack for each folder
  4. Set up Github Actions or CircleCI

Set up a GitHub repository

Set up a GitHub repository to back your InfluxDB instance. Determine how you want to organize the resources in your stacks within your Github repository. For example, organize resources under folders for specific teams or functions.

We recommend storing all resources for one stack in the same folder. For example, if you monitor Redis, create a redis stack and put your Redis monitoring resources (a Telegraf configuration, four dashboards, a label, and two alert checks) into one Redis folder, each resource in a separate file. Then, when you need to update a Redis resource, it’s easy to find and make changes in one location.

Typically, we do not recommend using the same resource in multiple stacks. If your organization uses the same resource in multiple stacks, before you delete a stack, verify the stack does not include resources that another stack depends on. Stacks with buckets often contain data used by many different templates. Because of this, we recommend keeping buckets separate from the other stacks.

Add existing resources to the GitHub repository

Skip this section if you are starting from scratch or don’t have existing resources you want to add to your stack.

Use the influx export command to quickly export resources. Keep all your resources in a single file or have files for each one. You can always split or combine them later.

For example, if you export resources for three stacks: buckets, redis, and mysql, your folder structure might look something like this when you are done:

  1. influxdb-assets/
  2. ├── buckets/
  3. ├── telegraf_bucket.yml
  4. ├── redis/
  5. ├── redis_overview_dashboard.yml
  6. ├── redis_label.yml
  7. ├── redis_cpu_check.yml
  8. └── redis_mem_check.yml
  9. ├── mysql/
  10. ├── mysql_assets.yml
  11. └── README.md

When you export a resource, InfluxDB creates a meta.name for that resource. These resource names should be unique inside your InfluxDB instance. Use a good naming convention to prevent duplicate meta.names. Changing the meta.name of the InfluxDB resource will cause the stack to orphan the resource with the previous name and create a new resource with the updated name.

Add the exported resources to your new GitHub repository.

Automate the creation of a stack for each folder

To automatically create a stack from each folder in your GitHub repository, create a shell script to check for an existing stack and if the stack isn’t found, use the influx stacks init command to create a new stack. The following sample script creates a redis stack and automatically applies those changes to your instance:

  1. echo "Checking for existing redis stack..."
  2. REDIS_STACK_ID=$(influx stacks --stack-name redis --json | jq -r '.[0].ID')
  3. if [ "$REDIS_STACK_ID" == "null" ]; then
  4. echo "No stack found. Initializing our stack..."
  5. REDIS_STACK_ID=$(influx stacks init -n redis --json | jq -r '.ID')
  6. fi
  7. # Setting the base path
  8. BASE_PATH="$(pwd)"
  9. echo "Applying our redis stack..."
  10. cat $BASE_PATH/redis/*.yml | \
  11. influx apply --force true --stack-id $REDIS_STACK_ID -q

The --json flag in the InfluxDB CLI is very useful when scripting against the CLI. This flag lets you grab important information easily using jq.

Repeat this step for each of the stacks in your repository. When a resource in your stack changes, re-run this script to apply updated resources to your InfluxDB instance. Re-applying a stack with an updated resource won’t add, delete, or duplicate resources.

Set up Github Actions or CircleCI

Once you have a script to apply changes being made to your local instance, automate the deployment to other environments as needed. Use the InfluxDB CLI to maintain multiple configuration profiles to easily switch profile and issue commands against other InfluxDB instances. To apply the same script to a different InfluxDB instance, change your active configuration profile using the influx config set command. Or set the desired profile dynamically using the -c, --active-config flag.

Before you run automation scripts against shared environments, we recommend manually running the steps in your script.

Verify your deployment automation software lets you run a custom script, and then set up the custom script you’ve built locally another environment. For example, here’s a custom Github Action that automates deployment:

  1. name: deploy-influxdb-resources
  2. on:
  3. push:
  4. branches: [ master ]
  5. jobs:
  6. deploy:
  7. runs-on: ubuntu-latest
  8. steps:
  9. - uses: actions/checkout@v2
  10. with:
  11. ref: ${{ github.ref }}
  12. - name: Deploys repo to cloud
  13. env:
  14. # These secrets can be configured in the Github repo to connect to
  15. # your InfluxDB instance.
  16. INFLUX_TOKEN: ${{ secrets.INFLUX_TOKEN }}
  17. INFLUX_ORG: ${{ secrets.INFLUX_ORG }}
  18. INFLUX_URL: ${{ secrets.INFLUX_URL }}
  19. GITHUB_REPO: ${{ github.repository }}
  20. GITHUB_BRANCH: ${{ github.ref }}
  21. run: |
  22. cd /tmp
  23. wget https://dl.influxdata.com/platform/nightlies/influx_nightly_linux_amd64.tar.gz
  24. tar xvfz influx_nightly_linux_amd64.tar.gz
  25. sudo cp influx_nightly_linux_amd64/influx /usr/local/bin/
  26. cd $GITHUB_WORKSPACE
  27. # This runs the script to set up your stacks
  28. chmod +x ./setup.sh
  29. ./setup.sh prod

For more information about using GitHub Actions in your project, check out the complete Github Actions documentation.

Apply updates from source-controlled templates

You can use a variety of InfluxDB templates from many different sources including Community Templates or self-built custom templates. As templates are updated over time, stacks let you gracefully apply updates without creating duplicate resources.

Apply template updates across multiple InfluxDB instances

In many cases, you may have more than one instance of InfluxDB running and want to apply the same template to each separate instance. Using stacks, you can make changes to a stack on one instance, export the stack as a template and then apply the changes to your other InfluxDB instances.

Develop templates

InfluxDB stacks aid in developing and maintaining InfluxDB templates. Stacks let you modify and update template manifests and apply those changes in any stack that uses the template.