You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何延长Jenkins Prometheus插件的数据保留时长?

Jenkins Prometheus插件指标数据保留时长延长方法

问题背景

我们已在Jenkins实例中安装Prometheus插件,指标可通过https://jenkins-url/prometheus端点获取,但现有数据仅保留2天,希望了解是否有方法延长该数据保留时长。

Jenkins executor Panel

当前Jenkins Prometheus插件配置

插件配置文件org.jenkinsci.plugins.prometheus.config.PrometheusConfiguration.xml内容如下:

<?xml version='1.1' encoding='UTF-8'?>
<org.jenkinsci.plugins.prometheus.config.PrometheusConfiguration plugin="prometheus@2.0.10">
  <urlName>prometheus</urlName>
  <additionalPath></additionalPath>
  <defaultNamespace>default</defaultNamespace>
  <jobAttributeName>jenkins_job</jobAttributeName>
  <useAuthenticatedEndpoint>true</useAuthenticatedEndpoint>
  <collectingMetricsPeriodInSeconds>120</collectingMetricsPeriodInSeconds>
  <countSuccessfulBuilds>true</countSuccessfulBuilds>
  <countUnstableBuilds>true</countUnstableBuilds>
  <countFailedBuilds>true</countFailedBuilds>
  <countNotBuiltBuilds>true</countNotBuiltBuilds>
  <countAbortedBuilds>true</countAbortedBuilds>
  <fetchTestResults>true</fetchTestResults>
  <processingDisabledBuilds>false</processingDisabledBuilds>
  <appendParamLabel>false</appendParamLabel>
  <appendStatusLabel>false</appendStatusLabel>
  <labeledBuildParameterNames></labeledBuildParameterNames>
  <collectDiskUsage>true</collectDiskUsage>
</org.jenkinsci.plugins.prometheus.config.PrometheusConfiguration>

已排查内容

  • 查阅Jenkins Prometheus插件源码,搜索retention、storage等关键词未找到相关配置项
  • 查看PrometheusConfiguration的JavaDoc文档,未发现数据保留相关设置

解决方案

Jenkins Prometheus插件本身不负责存储指标数据,它仅作为指标暴露端点,让Prometheus服务器定期抓取数据。数据的保留时长是由Prometheus服务器自身的配置决定的,具体调整步骤如下:

  1. 找到Prometheus服务器的主配置文件prometheus.yml
  2. 在配置文件中找到storage.tsdb.retention.time参数(若未存在则添加该配置项),设置目标保留时长:
    • 示例:设置为30天:storage.tsdb.retention.time: 30d
    • 支持的时间单位:s(秒)、m(分钟)、h(小时)、d(天)、w(周)、y(年)
  3. 保存配置文件后,重启Prometheus服务使配置生效

如果是通过容器部署的Prometheus,需确保配置文件正确挂载到容器内,或通过环境变量PROMETHEUS_STORAGE_TSDB_RETENTION_TIME设置保留时长。


内容的提问来源于stack exchange,提问作者vijay v

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.26 13:45:14