【问题标题】:How to build a dashboard in Grafana that displays Jenkins jobs status?如何在 Grafana 中构建显示 Jenkins 作业状态的仪表板?
【发布时间】:2020-01-07 09:03:13
【问题描述】:

想要设置一个显示 jenkins 工作的仪表板,我尝试直接将 grafana 与 jenkins 集成,但没有成功。

我尝试直接将 grafana 与 jenkins 集成,但没有成功。从 grafana 复制共享仪表板并使用 groovy 脚本将其添加到 jenkins post build,但 grafana 仪表板中没有显示任何内容。

在后期构建操作中添加了 groovy 脚本

import hudson.model.*

//get current build
def build = Thread.currentThread().executable

// grafana url for aggregate dashboard - replace time stamp with %s
        def perfResult = "https://grafana.optum.com/d/Yqv7hnOWk/jenkins-test?orgId=1&from=%s&to=%s"
// get build start and end time
        def start = build.getStartTimeInMillis();
        def end = start + build.getExecutor().getElapsedTime();

// replace time
        perfResult = String.format(perfResult, start, end);

//build the string to be added as description.
        def link = "<a href='%s'>%s</a><br/>";
        def sb = new StringBuilder();
        sb.append(String.format(link, perfResult, "Grafana Performance Result"));

// set build description
        build.setDescription(sb.toString());

我希望仪表板显示 jenkins 作业结果,但它没有显示任何内容。

【问题讨论】:

    标签: jenkins grafana dashboard


    【解决方案1】:

    我曾使用 Prometheus/Grafana 在 POC 仪表板中工作,这就是我所做的:

    • 一个 python 导出器,它调用 API,然后以 Prometheus 格式公开它们
    • prometheus 服务器从 python 导出器轮询数据
    • 连接到 prometheus 服务器并显示数据的 grafana 服务器。

    当时(1 年和 1/2 年前)我遇到了问题,因为 Prometheus 一直向我显示最后的数据 5 分钟,所以如果我删除了 3 天前的构建,它将不会显示。由于这是一个简单的 POC,时间非常有限,因此我无法进一步调查。

    【讨论】:

    • 我正在寻找有关配置的更多详细信息。还是谢谢
    • Grafana 的问题在于它只显示来自源的数据。我刚刚检查了 Grafana Datasources 网页,它无法直接连接到 Jenkins。因此,您需要将这些指标存储在其他地方,然后从 grafana 读取它
    【解决方案2】:

    很简单,在 jenkins 中安装 prometheus 导出器插件。让 prometheus 与您的 grafana 实例在同一主机上运行。将数据源设置为指向您的詹金斯普罗米修斯端点...享受

    【讨论】:

    • 至少在我进行测试时,Prometheus 插件会导出关于服务器的数据,而不是关于构建的数据。这就是我采用构建解决方案的原因
    猜你喜欢
    • 2012-12-07
    • 2021-10-20
    • 2022-06-18
    • 2019-08-28
    • 2021-06-11
    • 2022-08-10
    • 1970-01-01
    • 2020-02-11
    • 2021-07-11
    相关资源
    最近更新 更多