InfluxDB: Getting started
How to get started with InfluxDB
👋 Welcome to the Stackhero documentation!
Stackhero offers a ready-to-use InfluxDB cloud solution that provides a host of benefits, including:
- Unlimited writes, queries, dashboards, tasks, and buckets.
- Unlimited data retention time.
- Unlimited network and disk transfers.
- Effortless updates with just a click.
- Optimal performance and robust security powered by a private and dedicated VM.
Save time and simplify your life: it only takes 5 minutes to try Stackhero's InfluxDB cloud hosting solution!
Handling InfluxDB users
InfluxDB doesn't provide a way to create and manage users directly through its web UI. Fortunately, you can use the InfluxDB CLI for these tasks.
Using the InfluxDB CLI
You can access the InfluxDB CLI via Docker. For example, run the following command:
docker run -it -u 0 bitnami/influxdb:2.7.11 /bin/bash
Don't forget to replace
2.7.11with your InfluxDB version.
Once the container starts, create a configuration. Remember to replace <XXXXXX>.stackhero-network.com with your actual InfluxDB domain:
influx config create \
--config-name adminConfig \
--active \
--username-password admin \
--org admin \
--host-url https://<XXXXXX>.stackhero-network.com
After this step, you'll be able to use the InfluxDB CLI. For instance, to create a new user, run:
influx user create --name <user> --password <password>
Avoid disk space saturation
InfluxDB is designed as a time series database and often handles a large number of metrics. As these databases typically do not delete data automatically, your database can grow indefinitely and use up all available disk space.
To prevent disk space saturation, InfluxDB offers two solutions:
- Retention policies: Delete data older than a defined date. For example, you might decide to remove data older than 365 days.
- Downsampling data: Reduce data resolution over time. For example, if you record a temperature every second, you might want to:
- Keep temperature data with 1-second resolution for the last 5 minutes.
- Maintain maximum, minimum, and average temperatures with 1-minute resolution for the past 24 hours.
- Store maximum, minimum, and average temperatures with 1-hour resolution for older data.
Using retention policies allows you to store historical data for extended periods without needing terabytes of storage space. You will find more information about downsampling in the official documentation.
Handling InfluxDB data retention
By default, InfluxDB stores data indefinitely. While this behaviour is typical for traditional databases, it is not ideal for time series databases, which should remove outdated data to prevent uncontrolled growth.
For example, if you are storing battery voltage data, it might only be relevant for a few days rather than years. To avoid filling up your disk, it is crucial to set a retention period for each of your buckets.
To configure data retention:
- Open your InfluxDB web UI.
- Click on "Data", then "Buckets".
- Click on "Settings" next to the bucket you want to configure.
- Select "Delete data older than" and choose your desired retention period.
Don't forget that data older than the selected retention period will be permanently deleted!
Keep in mind that data in InfluxDB is organised into shards. Shards containing only outdated data are deleted automatically, but if a shard contains a mix of outdated and current data, it will not be removed. By default, without a defined retention policy, shards hold 7 days of data. This means that when you set a retention policy, nearly 7 days' worth of outdated data might still be preserved alongside your current data. You will find more information about shards in the official documentation.
Send data from Node.js to InfluxDB
You will find examples on how to send data from Node.js to an InfluxDB service in this repository: https://github.com/stackhero-io/influxdbGettingStarted