Why InfluxDB?
InfluxDB is optimized for time-series data with:- High write throughput for sensor ingestion (100Hz+ supported)
- Efficient storage with automatic downsampling and retention policies
- Powerful querying using Flux language for feature engineering
- Cloud-managed infrastructure (no server maintenance)
- Free tier with 30-day retention and 10,000 write requests/day
Setup Process
Create InfluxDB Cloud account
Sign up for a free account at InfluxData Cloud.Recommended region: AWS us-east-1 (lowest latency for US-based deployments)
Create a bucket
Navigate to Load Data > Buckets in the InfluxDB UI.Click + Create Bucket and configure:
- Name:
sensor_data(must match backend configuration) - Retention: 30 days (free tier) or custom
- Description: Time-series data for predictive maintenance
Generate an API token
Go to Load Data > API Tokens and click + Generate API Token.Select All Access Token to grant read/write permissions.Store it securely in a password manager or environment file.
Get your organization ID
Click your user profile in the top-right corner and select About.Copy the Organization ID (a hexadecimal string like
a1b2c3d4e5f6g7h8).Environment Configuration
Local Development
Create abackend/.env file (or .env in the project root):
Docker Compose
Add environment variables todocker-compose.yml:
.env file in the same directory:
Production Deployment (Render)
In the Render dashboard, go to your service settings and add environment variables:| Key | Value |
|---|---|
INFLUX_URL | https://us-east-1-1.aws.cloud2.influxdata.com |
INFLUX_TOKEN | your-api-token-here |
INFLUX_ORG | a1b2c3d4e5f6g7h8 |
INFLUX_BUCKET | sensor_data |
ENVIRONMENT | production |
Vercel Frontend (Optional)
The frontend doesn’t need direct InfluxDB access (it queries the backend API), but you can configure the API URL:Verification
Test Database Connection
Use the FastAPI health endpoint to verify InfluxDB connectivity:db_connected: false, check:
- Token validity: Regenerate if expired
- Organization ID: Verify it matches your account
- Bucket existence: Ensure
sensor_databucket is created - Network access: Check firewall rules (InfluxDB Cloud uses HTTPS/443)
Manual Query Test
You can test the connection directly using the InfluxDB Python client:Data Schema
The system writes data to InfluxDB using these measurements:sensor_data (Raw Sensor Readings)
| Field | Type | Unit | Description |
|---|---|---|---|
voltage_v | float | Volts | Line voltage |
current_a | float | Amperes | Line current |
power_factor | float | Unitless | Power factor (0-1) |
vibration_g | float | g-force | Acceleration |
power_kw | float | Kilowatts | Active power |
asset_id: Unique asset identifier (e.g.,motor_01)operating_state:RUNNING,IDLE, orOFF
features (Engineered Features)
| Field | Description |
|---|---|
voltage_rolling_mean_1h | 1-hour moving average of voltage |
current_spike_count | Number of current spikes in 10-point window |
power_factor_efficiency_score | Normalized efficiency (0-100) |
vibration_intensity_rms | RMS vibration intensity |
voltage_stability | Deviation from 230V nominal |
power_vibration_ratio | Vibration per unit power factor |
anomalies (ML Predictions)
| Field | Description |
|---|---|
anomaly_score | Isolation Forest score (0-1) |
batch_anomaly_score | Batch model score (0-1) |
health_score | Overall health (0-100) |
risk_level | LOW, MODERATE, HIGH, CRITICAL |
degradation_index | Cumulative damage (0-1) |
damage_rate | Rate of health decline (per hour) |
rul_hours | Remaining useful life (hours) |
operator_logs (Maintenance Events)
| Field | Description |
|---|---|
message | Event description |
severity | INFO, WARNING, CRITICAL |
technician | Operator name |
Retention and Downsampling
Free Tier Limits
- Retention: 30 days
- Write rate: 10,000 writes/day
- Query rate: Unlimited
- Storage: 10 MB
Downsampling Task (Optional)
To reduce storage, create a downsampling task that aggregates 1-second data into 1-minute averages:Troubleshooting
Error: “unauthorized access”
Cause: Invalid or expired API token. Solution:- Regenerate a new API token in the InfluxDB UI
- Update the
INFLUX_TOKENenvironment variable - Restart the backend service
Error: “bucket not found”
Cause: TheINFLUX_BUCKET variable doesn’t match the actual bucket name.
Solution:
- Verify bucket name in InfluxDB UI matches
sensor_data - Or update
INFLUX_BUCKETto match your custom bucket name
Error: “organization not found”
Cause: IncorrectINFLUX_ORG value.
Solution:
- Go to InfluxDB UI > Profile > About
- Copy the Organization ID (not the organization name)
- Update
INFLUX_ORGwith the correct ID
High Write Latency
Cause: Cross-region latency (e.g., EU backend writing to US-East InfluxDB). Solution:- Use an InfluxDB region close to your backend deployment
- Enable batching in the write API (automatically handled by the backend)
Security Best Practices
Production Security Checklist
- ✅ Use All Access Tokens only in secure environments
- ✅ Generate scoped tokens (read-only, write-only) for specific services
- ✅ Rotate tokens every 90 days
- ✅ Store tokens in secret managers (AWS Secrets Manager, Vercel Secrets)
- ✅ Never log token values in application code
- ✅ Use environment variables, not hardcoded strings
- ✅ Enable IP allowlisting in InfluxDB Cloud (Enterprise plan)
Next Steps
Calibration Workflow
Configure baseline models using stored data
Data Generator
Populate InfluxDB with test sensor data