Skip to content

driftingboy/tsdb

Repository files navigation

tsdb

从零开始的时序化数据库

功能点

存储数据如下(y轴表示时间线,也就是一个个的监控指标;x轴表示时间)

metric
^
│   . . . . . . . . . . . . . . . . .   . .   node_cpu{cpu="cpu0",mode="idle"}
│     . . . . . . . . . . . . . . . . . . .   node_cpu{cpu="cpu0",mode="system"}
│     . . . . . . . . . .   . . . . . . . .   node_load1{}
│     . . . . . . . . . . . . . . . .   . .  
v
    <----------------------------------> time
  1. 基于某指标(metric)或者叫某时间线(time-series)搜索某段时间时间的样本(sample)
    # 比如查询 某个metric 在 2021-08-29 17:34:44 到 2021-08-29 17:35:44 的数据
    select ...
    where y = http_request_total{status="200", method="GET"} AND
    x in [1630229684, 1630229744]
  2. 基于 labels 查询
  3. metricName (__name__) 模糊查询

⚠️ api_http_requests_total{method="POST", handler="/messages"} 等同于 {__name__="api_http_requests_total",method="POST", handler="/messages"}

type Metric LabelSet

type LabelSet map[LabelName]LabelValue

type LabelName string

type LabelValue string

整体架构

技术点

实现步骤

  • 建模
  • 内存存储与查询
  • 持久化
    • 倒排序索引
    • 数据压缩
    • compaction
  • 可用性
    • wal 日志

reference

Fackbook 2015 年发表的论文

prometheus TSDB 的演变过程

从零开始实现一个时序数据库

压缩算法

虚拟内存

理解指标和时间序列

mmap Roaring Bitmap fastRegexMatcher

About

从零开始的时序化数据库

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages