从 TSDB 里面复制一段时间内的指标出来,生成新的块。这些块可以上传到像 Grafana Mimir 或者 Thanos 这些基于对象存储的系统中,供使用者查询。
例如,先挑选 {user="foo"} 的数据,再用 mimirtool 推送到 foo 租户
项目的目的是实现某些数据的永久存储,如果你没有在用上述系统,请用 prom-migrator (或类似的工具) 转移数据
usage: prom-tsdb-copyer [<flags>] <source> <target>
普罗米修斯TSDB复制器
Flags:
-h, --help Show context-sensitive help (also try --help-long and --help-man).
-v, --version Show application version.
--from=FROM 数据开始时间
--to=TO 数据结束时间
-S, --query-duration=2h 切分查询的时长(增加这个值会加大内存使用)
-B, --block-duration=24h 切分新块的时长
-T, --thread=1 每个新块并行多少个查询(内存使用翻倍)(0=不限制)
-l, --label-query=LABEL-QUERY ...
查询label(k=v)
-L, --label-append=LABEL-APPEND ...
增加label(k=v)
--gc-pre-series=GC-PRE-SERIES
写入多少序列后GC
-d, --debug 输出Debug日志到终端
--show-metrics 输出监控指标到终端
--gc-after-flush 写入完成后手动GC
Args:
<source> 源TSDB文件夹
<target> 目标TSDB文件夹# 拷贝某一天的内容
prom-tsdb-copyer --from='2023-02-17 00:00:00' --to='2023-02-18 00:00:00' old_data/ new_data/
# 按查询内容拷贝
prom-tsdb-copyer --from='2023-02-17 00:00:00' --to='2023-02-18 00:00:00' -l job=nodes -l 'instance=~192\.168\.1\.\d+' -l 'hostname!=foonode' -l '__name__!~go.*' old_data/ new_data/
# 在拷贝的内容里加标签
prom-tsdb-copyer --from='2023-02-17 00:00:00' --to='2023-02-18 00:00:00' -L create_from=copyer -L storage=persistent old_data/ new_data/
# 并发拷贝
prom-tsdb-copyer --from='2023-02-17 00:00:00' --to='2023-02-18 00:00:00' -T4 old_data/ new_data/
# 按周分块
prom-tsdb-copyer --from='2023-02-17 00:00:00' --to='2023-02-18 00:00:00' -B 168h old_data/ new_data/- 按 切分查询的时长 分块,合理的方块可以有效降低内存使用量
- 例如 50k个15秒 的序列,按2小时分块只需要700多M内存,按24小时分块要4.8G内存
- 所有数据拷贝完成后,才调用
Compactor对写入的数据进行打包 - 并发只在分块逻辑中使用,压缩不进行并发操作
make- Q: 为什么新版完全移除了远程支持?
A: 它太慢了,并且远程读还需要转换数据类型
数据源: 有 1154916774 个指标的数据
时间跨度: 2023-02-24T14:00:00.692+08:00 => 2023-03-01T02:00:00+08:00
新旧版本处理速率基本一致,但新版本降低了40%的CPU时间,以及75%的内存使用量
意味着新版本可以使用更多的并发,提升CPU利用率
| 指标 | 旧版本 | 新版本 | 新版本(4并发) |
|---|---|---|---|
User time (seconds) |
537.73 | 344.23 (↓35.98%) | 362.53 (↓32.58%) |
System time (seconds) |
32.58 | 19.01 (↓41.65%) | 17.77 (↓45.46%) |
Percent of CPU this job got |
129% | 84% (↓34.88%) | 216% (↑67.44%) |
Elapsed (wall clock) time (h:mm:ss or m:ss) |
7:20.58 | 7:07.99 (↓2.86%) | 2:55.40 (↓60.19%) |
Average shared text size (kbytes) |
0 | 0 | 0 |
Average unshared data size (kbytes) |
0 | 0 | 0 |
Average stack size (kbytes) |
0 | 0 | 0 |
Average total size (kbytes) |
0 | 0 | 0 |
Maximum resident set size (kbytes) |
3499336 | 813832 (↓76.74%) | 3057436 (↓12.63%) |
Average resident set size (kbytes) |
0 | 0 | 0 |
Major (requiring I/O) page faults |
46 | 0 | 0 |
Minor (reclaiming a frame) page faults |
1818527 | 2241313 (↑23.25%) | 1296268 (↓28.72%) |
Voluntary context switches |
148016 | 134209 (↓9.33%) | 101190 (↓31.64%) |
Involuntary context switches |
37746 | 38977 (↑3.26%) | 37186 (↓1.48%) |
Swaps |
0 | 0 | 0 |
File system inputs |
2602496 | 64 (↓100.00%) | 288 (↓99.99%) |
File system outputs |
9757480 | 9741208 | 9689272 |
Socket messages sent |
0 | 0 | 0 |
Socket messages received |
0 | 0 | 0 |
Signals delivered |
0 | 0 | 0 |
Page size (bytes) |
4096 | 4096 | 4096 |
旧版本执行命令
注: 使用 commit-count 配置来保证旧版本不会在写入中途进行Commit操作,保证逻辑一致性
/bin/time -v prom-tsdb-copyer-linux-amd64 copy ./_old_data/ ./_new_data \
-S '0000-01-01 08:00:00' \
-E '9999-12-31 23:59:59.999' \
--commit-count=10485765156 \
>_test.log 2>&1新版本执行命令
/bin/time -v ./_dist/prom-tsdb-copyer ./_old_data/ ./_new_data/ \
--show-metrics \
--debug \
>_test2.log 2>&1