Skip to main content

TimeScale

tip
  • 适用于
    • 需要时序数据存储
  • 不适用于
    • 监控
    • Metrics
  • promscale 停止开发 promscale#1836
# 基于 postgres 上游构建的镜像
# https://github.com/timescale/timescaledb-docker
# timescale/timescaledb-postgis 包含 postgis 扩展
docker run --rm -it \
-p 5432:5432 \
-v $PWD/data:/var/lib/postgresql/data \
-e POSTGRES_DB=timescale \
-e POSTGRES_USER=timescale \
-e POSTGRES_PASSWORD=timescale \
--name timescaledb timescale/timescaledb:latest-pg12

# http://localhost:9201/metrics
# -log-level 默认 debug
# -async-acks 在写入到数据库之前响应 - 可能丢但 metric 场景下一般不影响
docker run --rm -it --link timescaledb:db \
-p 9201:9201 \
--name ts-prometheus timescale/timescale-prometheus \
-async-acks \
-db-host=db -db-name=timescale -db-port=5432 -db-user=timescale -db-password=timescale

prometheus --config.file=prometheus.yml

prometheus.yml

global:
scrape_interval: 15s

scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']

- job_name: 'node'
static_configs:
- targets: ['localhost:9100']

- job_name: 'tsdb-prom'
static_configs:
- targets: ['localhost:9201']

remote_write:
- url: 'http://localhost:9201/write'
remote_read:
- url: 'http://localhost:9201/read'

Notes

  • create_hypertable
SELECT create_hypertable('samples', 'ts', chunk_time_interval => INTERVAL '7 day');

select chunks_detailed_size('samples');
select * from timescaledb_information.chunks;