InfluxDB는 시계열 데이터에 특화된 오픈소스 데이터베이스다. IoT 센서, 서버 메트릭, 애플리케이션 성능 모니터링(APM) 데이터를 고속으로 수집·쿼리한다.
핵심 개념
| 개념 | 설명 |
|---|
| Measurement | 테이블과 유사한 데이터 그룹 |
| Tag | 인덱싱된 메타데이터 (문자열) |
| Field | 실제 측정값 (숫자/문자열) |
| Timestamp | 나노초 정밀도 시간 |
| Bucket | 데이터 보존 정책이 있는 저장소 |
| Flux | InfluxDB 쿼리 언어 |
python
from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.write_api import SYNCHRONOUS
from datetime import datetime, timezone
client = InfluxDBClient(
url="http://localhost:8086",
token="my-token",
org="my-org"
)
write_api = client.write_api(write_options=SYNCHRONOUS)
point = (
Point("server_metrics")
.tag("host", "server01")
.tag("region", "ap-northeast-2")
.field("cpu_usage", 73.5)
.field("memory_usage", 8192)
.time(datetime.now(timezone.utc))
)
write_api.write(bucket="monitoring", org="my-org", record=point)
Flux 쿼리
flux
from(bucket: "monitoring")
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "server_metrics")
|> filter(fn: (r) => r._field == "cpu_usage")
|> aggregateWindow(every: 5m, fn: mean, createEmpty: false)
|> yield(name: "cpu_avg")
| 항목 | InfluxDB | TimescaleDB |
|---|
| 기반 | 전용 시계열 DB | PostgreSQL 확장 |
| 쿼리 언어 | Flux (전용) | 완전한 SQL |
| 조인 | 제한적 | PostgreSQL 조인 |
| 생태계 | InfluxData 스택 | PostgreSQL 생태계 |
관련 문서