【发布时间】:2021-04-26 01:33:15
【问题描述】:
我想从 prometheus 导出数据并导入到另一个。 找到了三个帖子,都说把snapshots到storage.tsdb.path/snapshots下的新帖子就可以了。
但是我无法重现它。 Prometheus 似乎从不承认我在日志中复制的快照(请参阅我的上一部分),但我不知道为什么,我没有发现与此问题相关的任何内容...
请让我知道我错过了什么...这似乎是一件容易的事,但我无法弄清楚。
我在Prometheus User Group也问过这个问题,但还没有人回复。
参考帖子
-
https://www.robustperception.io/taking-snapshots-of-prometheus-data
这篇文章说将 storage.tsdb.path 指向快照目录会起作用,我试过但没有用。
- https://devopstales.github.io/home/backup-and-retore-prometheus/
- https://suraj.io/post/how-to-backup-and-restore-prometheus/
我做了什么
我使用 docker 并执行以下步骤。
- 使用
--web.enable-admin-api运行prometheus 容器 - api $curl -XPOST http://localhost:9090/api/v1/admin/tsdb/snapshot 的快照
- 使用 docker cp 复制快照。并检查目录大小约为 250M。 $ du -sh 快照 2.5 亿张快照
我尝试了两种导入数据的方法
- 复制到另一个 prometheus 容器。
- 将快照复制到 /data/snapshots 并将 /data 挂载到 prometheus 的 storage.tsdb.path。 注意:除快照目录外,/data 为空。
我的测试是在 2021/4/22 完成的,我的数据是在 2021/4/16 左右。所有容器的保留时间默认为 15 天。
我期望看到的
我使用 Grafana 的“探索”功能检查指标“向上”并尝试查看 4/16 的数据,但没有任何显示。
你看到了什么?在什么情况下?
方式 1 和方式 2 的容器仅在 2021/4/22 开始时显示指标,但在 2021/4/16 时没有指标。
环境
- 系统信息:
我的主机是运行 Ubuntu 18.04 的 vmware player 16 虚拟机
Linux 5.4.0-70-generic x86_64
- 普罗米修斯版本:
我正在使用 Prometheus 的容器版本。 prometheus,版本 2.25.2(分支:HEAD,修订:bda05a23ada314a0b9806a362da39b7a1a4e04c3) 构建用户:root@de38ec01ef10 建造日期:20210316-18:07:52 去版本:go1.15.10 平台:linux/amd64
- Prometheus 配置文件:
global:
scrape_interval: 10s
scrape_timeout: 5s
evaluation_interval: 15s
external_labels:
monitor: 'monitor'
alerting:
alertmanagers:
- static_configs:
- targets:
- alertmanager:9093
rule_files:
- "/prom_setup/alert.rules"
# - "second.rules"
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets:
- 192.168.41.164:9090
- job_name: 'host_A'
static_configs:
- targets: ['192.168.41.164:9100']
- job_name: 'container_A'
static_configs:
- targets: ['cadvisor:8080']
- docker-compose 文件:
prometheus:
container_name: promethues
image: prom/prometheus
privileged: true
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
# try to mount only snapshots to prometheus
- ./prom_data/:/prometheus/data/
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--web.enable-lifecycle'
# to enable snapshot
- '--web.enable-admin-api'
主机上的文件权限
- 数据目录
drwxrwxrwx 5 lou lou 4096 Apr 22 08:28 prom_data/
- 快照目录
drwxrwxrwx 4 lou lou 4096 Apr 22 08:28 snapshots/
$ du -sh snapshots
250M snapshots
- 日志:
promethues | level=info ts=2021-04-22T00:28:20.992Z caller=main.go:366 msg="No time or size retention was set so using the default time retention" duration=15d
promethues | level=info ts=2021-04-22T00:28:20.993Z caller=main.go:404 msg="Starting Prometheus" version="(version=2.25.2, branch=HEAD, revision=bda05a23ada314a0b9806a362da39b7a1a4e04c3)"
promethues | level=info ts=2021-04-22T00:28:20.993Z caller=main.go:409 build_context="(go=go1.15.10, user=root@de38ec01ef10, date=20210316-18:07:52)"
promethues | level=info ts=2021-04-22T00:28:20.993Z caller=main.go:410 host_details="(Linux 5.4.0-70-generic #78~18.04.1-Ubuntu SMP Sat Mar 20 14:10:07 UTC 2021 x86_64 8fa848a981f9 (none))"
promethues | level=info ts=2021-04-22T00:28:20.993Z caller=main.go:411 fd_limits="(soft=1048576, hard=1048576)"
promethues | level=info ts=2021-04-22T00:28:20.993Z caller=main.go:412 vm_limits="(soft=unlimited, hard=unlimited)"
promethues | level=info ts=2021-04-22T00:28:20.998Z caller=web.go:532 component=web msg="Start listening for connections" address=0.0.0.0:9090
promethues | level=info ts=2021-04-22T00:28:21.003Z caller=main.go:779 msg="Starting TSDB ..."
promethues | level=info ts=2021-04-22T00:28:21.008Z caller=head.go:668 component=tsdb msg="Replaying on-disk memory mappable chunks if any"
promethues | level=info ts=2021-04-22T00:28:21.008Z caller=head.go:682 component=tsdb msg="On-disk memory mappable chunks replay completed" duration=4.448µs
promethues | level=info ts=2021-04-22T00:28:21.008Z caller=head.go:688 component=tsdb msg="Replaying WAL, this may take a while"
promethues | level=info ts=2021-04-22T00:28:21.008Z caller=head.go:740 component=tsdb msg="WAL segment loaded" segment=0 maxSegment=0
promethues | level=info ts=2021-04-22T00:28:21.008Z caller=head.go:745 component=tsdb msg="WAL replay completed" checkpoint_replay_duration=24.518µs wal_replay_duration=292.774µs total_replay_duration=360.306µs
promethues | level=info ts=2021-04-22T00:28:21.009Z caller=tls_config.go:191 component=web msg="TLS is disabled." http2=false
promethues | level=info ts=2021-04-22T00:28:21.009Z caller=main.go:799 fs_type=EXT4_SUPER_MAGIC
promethues | level=info ts=2021-04-22T00:28:21.010Z caller=main.go:802 msg="TSDB started"
promethues | level=info ts=2021-04-22T00:28:21.010Z caller=main.go:928 msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
promethues | level=info ts=2021-04-22T00:28:21.011Z caller=main.go:959 msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml totalDuration=1.487753ms remote_storage=2.162µs web_handler=883ns query_engine=1.467µs scrape=420.502µs scrape_sd=113.37µs notify=17.922µs notify_sd=28.211µs rules=550.056µs
promethues | level=info ts=2021-04-22T00:28:21.011Z caller=main.go:751 msg="Server is ready to receive web requests."
【问题讨论】:
-
运气好吗?我有几乎相同的问题?
-
@dcg 对不起,不。我还在 Kubuntu 14.04 上进行了测试,但没有运气..
标签: linux prometheus metrics snapshot