InfluxDB
Overview
InfluxDB is a high-performance time series database used for storing metrics, telemetry, and sensor data.
Deployment
Kubernetes Resources
| Resource |
Name |
Namespace |
| Deployment |
influxdb |
databases |
| Service |
influxdb |
databases |
| PVC |
influxdb-data |
databases |
Configuration
apiVersion: apps/v1
kind: Deployment
metadata:
name: influxdb
namespace: databases
spec:
replicas: 1
template:
spec:
containers:
- name: influxdb
image: influxdb:2.7
ports:
- containerPort: 8086
volumeMounts:
- name: data
mountPath: /var/lib/influxdb2
Access
Connection Details
| Property |
Value |
| Host |
influxdb.databases.svc |
| Port |
8086 |
| Protocol |
HTTP |
| External |
influxdb.ajandrews.pro |
Authentication
- Method: Token-based
- Organization: Primary org
- Bucket: metrics
Data Model
Concepts
| Term |
Description |
| Bucket |
Data container (like database) |
| Measurement |
Like a table |
| Tag |
Indexed metadata |
| Field |
Actual values |
| Timestamp |
Time of data point |
Line Protocol
measurement,tag1=value1,tag2=value2 field1=value1,field2=value2 timestamp
Example:
cpu,host=server01,region=us-west usage=75.5,temp=65 1609459200000000000
Buckets
| Bucket |
Retention |
Purpose |
| metrics |
30 days |
Application metrics |
| telemetry |
7 days |
High-frequency data |
| long-term |
365 days |
Aggregated data |
Creating Bucket
influx bucket create \
--name my-bucket \
--retention 30d \
--org my-org
Queries (Flux)
Basic Query
from(bucket: "metrics")
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "cpu")
|> filter(fn: (r) => r._field == "usage")
Aggregation
from(bucket: "metrics")
|> range(start: -24h)
|> filter(fn: (r) => r._measurement == "cpu")
|> aggregateWindow(every: 1h, fn: mean)
Downsampling Task
option task = {name: "downsample", every: 1h}
from(bucket: "metrics")
|> range(start: -1h)
|> aggregateWindow(every: 5m, fn: mean)
|> to(bucket: "long-term")
API Endpoints
| Endpoint |
Description |
/api/v2/query |
Query data |
/api/v2/write |
Write data |
/api/v2/buckets |
Manage buckets |
/health |
Health check |
Write API
curl -XPOST "http://influxdb:8086/api/v2/write?bucket=metrics" \
-H "Authorization: Token $TOKEN" \
-H "Content-Type: text/plain" \
--data-raw "cpu,host=server01 usage=75.5"
Retention Policies
Automatic Deletion
Data older than retention period is automatically deleted.
Manual Cleanup
influx delete \
--bucket metrics \
--start 2024-01-01T00:00:00Z \
--stop 2024-01-15T00:00:00Z
Monitoring
Key Metrics
| Metric |
Description |
influxdb_uptime |
Server uptime |
influxdb_organizations_total |
Org count |
influxdb_buckets_total |
Bucket count |
go_memstats_alloc_bytes |
Memory usage |
Grafana Integration
InfluxDB data source configured in Grafana for visualization.
Backup
Backup Command
influx backup /backup/influxdb \
--bucket metrics \
--org my-org
Restore Command
influx restore /backup/influxdb \
--bucket metrics \
--org my-org
Troubleshooting
Common Issues
| Issue |
Cause |
Resolution |
| Write timeout |
High load |
Check resources |
| Query timeout |
Large dataset |
Add time filter |
| Token invalid |
Expired/wrong |
Regenerate token |