π InfluxDB Bucket Creation β Detailed Documentation¶
π§ What is a Bucket?¶
In InfluxDB, a bucket is a logical container where time series data is stored. Think of it as a combination of a database and a retention policy:
- It defines where data is stored
- It determines how long the data is retained
Buckets are tied to an organization (org) and can be used to:
- Collect sensor data
- Store application metrics
- Analyze log files
- Visualize historical trends
π οΈ Prerequisites¶
Before creating a bucket, ensure you have the following:
| Requirement | Description |
|---|---|
| β InfluxDB account | Cloud or local OSS instance |
β
Organization (org) ID |
Identifies your workspace in InfluxDB |
| β Authentication token | Admin or write access token |
| β CLI or API tool access | Optional, for non-UI methods |
π Bucket Attributes¶
| Attribute | Description |
|---|---|
name |
Unique name of the bucket |
org |
Organization under which the bucket is created |
retentionRules |
Duration to keep data (default = infinite) |
description |
(Optional) Notes about the bucketβs purpose |
1οΈβ£ Method 1: Creating a Bucket via InfluxDB UI¶
π Step-by-step Guide:¶
- Log In
- Navigate to your InfluxDB dashboard (e.g.,
https://cloud2.influxdata.com). - Sign in with your credentials.
- Navigate to your InfluxDB dashboard (e.g.,
- Access the Buckets Page
- On the left panel, go to βDataβ β βBucketsβ.
- Create a New Bucket
- Click β+ Create Bucketβ.
- Fill in the form:
- Bucket Name:
iot_sensor_data - Retention Period:
- Default: Infinite
- Custom: e.g.,
30 days,1 year, etc.
- Optional: Add a description for better organization.
- Bucket Name:
- Click βCreateβ to finish.
π Note:¶
You can edit the bucket name later, but retention rules cannot be changed post-creation via the UI.
2οΈβ£ Method 2: Creating a Bucket via InfluxDB CLI¶
π§ Requirements:¶
Ensure the influx CLI is installed and configured:
influx config list
β Example Command¶
influx bucket create \
--name iot_sensor_data \
--org my_org \
--retention 30d \
--description "Storing sensor data from IoT devices"
π§Ύ Flags Description:¶
| Flag | Description |
|---|---|
--name |
Bucket name |
--org |
Your organization name or ID |
--retention |
Retention duration (e.g., 720h, 0s for infinite) |
--description |
Optional description of the bucket |
π Verify Creation¶
influx bucket list
3οΈβ£ Method 3: Creating a Bucket via InfluxDB API¶
π‘ Endpoint:¶
POST /api/v2/buckets
π Headers:¶
Authorization: Token YOUR_API_TOKEN
Content-Type: application/json
π Sample Request Body:¶
{
"name": "iot_sensor_data",
"orgID": "your_org_id_here",
"description": "Stores IoT device data",
"retentionRules": [
{
"type": "expire",
"everySeconds": 2592000
}
]
}
2592000seconds = 30 days
π¬ Sample cURL:¶
curl --request POST \
https://us-west-2-1.aws.cloud2.influxdata.com/api/v2/buckets \
--header "Authorization: Token YOUR_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"name": "iot_sensor_data",
"orgID": "your_org_id_here",
"description": "Stores IoT device data",
"retentionRules": [
{
"type": "expire",
"everySeconds": 2592000
}
]
}'
β Best Practices¶
| Tip | Description |
|---|---|
| β Use meaningful names | e.g., prod_telemetry, dev_logs, metrics_internal |
| β³ Apply appropriate retention | Prevent bloated storage and unnecessary costs |
| π¦ Separate buckets for environments | e.g., dev_, test_, prod_ buckets |
| π Apply access controls | Use authorization tokens with specific permissions |
π Post-Creation Operations¶
βΊοΈ Write Data to Bucket¶
Using the CLI:
influx write \
--bucket iot_sensor_data \
--org my_org \
--precision s \
--format lp \
--file ./data.lp
Using Python client:
python
CopyEdit
from influxdb_client import InfluxDBClient, Point
client = InfluxDBClient(
url="https://your-instance-url",
token="YOUR_TOKEN",
org="your_org"
)
write_api = client.write_api()
write_api.write(bucket="iot_sensor_data", record=Point("temperature").tag("device", "sensor1").field("value", 25.3))
π Query Data¶
Flux query via CLI:
influx query 'from(bucket:"iot_sensor_data") |> range(start: -1h)'
π§Ή Clean-Up (Optional)¶
Delete a Bucket¶
CLI:
influx bucket delete --name iot_sensor_data --org my_org
API:
DELETE /api/v2/buckets/{bucketID}