DEBUG.WIKI
IPPeak:从目标地区访问网页,住宅代理、SEO 监测、广告验证
阿里云;从建站到云上业务;云服务器 · 数据库 · 对象存储;查看产品 →
搬瓦工;先看线路,再选 VPS;CN2 GIA · 对应线路套餐;查看线路 →

解决 VictoriaMetrics 报错 out of retention 数据丢弃

分析 VictoriaMetrics 写入远端指标报 cannot insert data out of retention 的时间戳超期原因,提供 retentionPeriod 参数调优方案。

问题现象

向 VictoriaMetrics 写入历史指标或回放数据时返回 HTTP 400:

cannot insert data with timestamp 1690000000000 out of retention "1month"; minimum allowed timestamp is 1692000000000

客户端数据丢弃计数持续增加。

触发根因

  1. VictoriaMetrics 启动时配置了数据保留周期 -retentionPeriod(例如 1 表示 1 个月)。
  2. 写入数据的时间戳早于当前时间减去保留周期,系统为了防止历史数据无序插入(Out-of-order)和内存膨胀,直接拒绝接收过期分区数据。

解决步骤与操作命令

步骤一:调整 VictoriaMetrics 保留周期参数

修改服务启动命令或配置文件中的 -retentionPeriod 参数:

# 修改 systemd 配置文件或 Docker 启动命令
/usr/local/bin/victoria-metrics-prod   -retentionPeriod=12m \            # 调整为 12 个月(1年)
  -storageDataPath=/var/lib/victoria-metrics-data   -httpListenAddr=:8428

步骤二:重启服务以加载新配置

sudo systemctl daemon-reload
sudo systemctl restart victoria-metrics

步骤三:验证保留周期生效

访问状态页面验证:

curl -s http://localhost:8428/metrics | grep "vm_retention"

验证确认

重新发送历史时序指标测试:

curl -d 'test_metric{host="prod"} 100 1690000000' -X POST 'http://localhost:8428/api/v1/import/prometheus'

返回 HTTP 204 No Content 即代表数据成功写入存储。