【问题标题】:Scrape jenkins metrics with prometheus使用 prometheus 抓取 jenkins 指标
【发布时间】:2021-02-22 10:42:18
【问题描述】:

我是 Prometheus 的新手,所以我不确定自己做错了什么,但这些是我的服务和服务监视器定义。

apiVersion: v1
kind: Service
metadata:
  name: jenkins
  annotations:
    prometheus.io/scrape: 'true'
    prometheus.io/port: '8080'
    prometheus.io/path: '/prometheus'
  labels:
    app.kubernetes.io/instance: jenkins
    app.kubernetes.io/component: jenkins
spec:
  type: ClusterIP
  ports:
    - port: 8080
      targetPort: 8080
  selector:
    app: jenkins
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: jenkins
  labels:
    app.kubernetes.io/instance: jenkins
    app.kubernetes.io/component: jenkins
    release: prometheus
spec:
  endpoints:
  - interval: 10s
    path: /prometheus/
    port: "8080"
  jobLabel: app.kubernetes.io/instance
  selector:
    matchLabels:
      app.kubernetes.io/component: jenkins
      app.kubernetes.io/instance: jenkins

但我的 Jenkins 没有出现在 Prometheus UI 的目标列表下。 它出现在Service Discovery 下,这让我相信运营商通过release: prometheus 标签正确地提取了它。

我已经在 jenkins 上安装了 prometheus plugin,并且当我 curl https://<JENKINS_URL>/prometheus/ 时可以查看指标

我想弄清楚为什么 Jenkins 没有出现在 targets 列表下。

是否有任何适当的文档说明如何执行此操作,或者成功实施此操作的任何人都可以分享任何指针吗?

【问题讨论】:

    标签: jenkins kubernetes prometheus kubernetes-helm prometheus-operator


    【解决方案1】:

    没有比阅读代码本身更好的文档了。

    您需要关注this line in the custom resource definition of ServiceMonitor

    port:
      description: Name of the service port this endpoint refers to.
                   Mutually exclusive with targetPort.
      type: string
    

    基本上,您为名为“8080”的服务端口创建了一个 serviceMonitor。

    endpoints:
      - interval: 10s
        path: /prometheus/
        port: "8080"
    

    但是你定义了一个未命名的服务,其端口号是 8080。

    spec:
      type: ClusterIP
      ports:
        - port: 8080
          targetPort: 8080
    

    你现在看到不匹配了吗?

    你需要 要么在 serviceMonitor 中使用 targetPort: 8080 和 targetPort,

    或者,更好的是,在 serviceMonitor 中使用 port:“web”,同时将您的服务命名为“web”。

    服务监控:

    endpoints:
      - interval: 10s
        path: /prometheus/
        port: "web"
    

    服务:

    spec:
      type: ClusterIP
      ports:
        - name: "web"
          port: 8080
          targetPort: 8080
    

    【讨论】:

      【解决方案2】:

      你需要给你的 pod 添加注解:)

          annotations:
            prometheus.io/path: /prometheus
            prometheus.io/port: '8080'
            prometheus.io/scrape: 'true'
      

      【讨论】:

      • 嗨弗洛里安,我已经添加了这个,但我无法让它工作。我将用我的实际定义更新问题,以便更清楚。
      猜你喜欢
      • 2021-01-13
      • 1970-01-01
      • 2021-04-30
      • 1970-01-01
      • 2019-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      相关资源
      最近更新 更多