简体   繁体   English

使用 prometheus 抓取 jenkins 指标

[英]Scrape jenkins metrics with prometheus

I'm new to Prometheus, so I'm not sure what I'm doing wrong but these are my service and service monitor definitions.我是 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

But my Jenkins doesn't appear under the targets list on the Prometheus UI.但是我的 Jenkins 没有出现在 Prometheus UI 的目标列表下。 It appears under Service Discovery which makes me believe that the Operator is correctly picking it up through the release: prometheus label.它出现在Service Discovery下,这让我相信运营商通过以下release: prometheus label。

I have installed the prometheus plugin on jenkins and I'm able to view metrics when I curl https://<JENKINS_URL>/prometheus/我已经在 jenkins 上安装了prometheus plugin ,并且当我 curl https://<JENKINS_URL>/prometheus/时,我能够查看指标

What I'm trying to figure out is why Jenkins doesn't appear under the targets list.我想弄清楚为什么 Jenkins 没有出现在targets列表下。

Is there any proper documentation on how to go about this or can anyone who has successfully implemented this share any pointers?是否有任何关于如何 go 的适当文档,或者任何成功实施此操作的人都可以分享任何指针?

There is no better docs than reading the code itself.没有比阅读代码本身更好的文档了。

You need pay attention to this line in the custom resource definition of ServiceMonitor .您需要注意ServiceMonitor 的自定义资源定义中的这一行

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

Basically, you created a serviceMonitor to a service port named "8080".基本上,您为名为“8080”的服务端口创建了一个 serviceMonitor。

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

But you defined an unnamed service whose port number is 8080.但是您定义了一个端口号为 8080 的未命名服务。

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

Do you see the mismatch now?你现在看到不匹配了吗?

You need either use targetPort: 8080 and targetPort only in serviceMonitor,您需要仅在 serviceMonitor 中使用 targetPort: 8080 和 targetPort,

or, even better, use port: "web" in serviceMonitor, and at the same time, name your service "web".或者,更好的是,在 serviceMonitor 中使用 port:“web”,同时将您的服务命名为“web”。

ServiceMonitor:服务监控:

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

Service:服务:

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

You need to add annotations to your pod:)您需要在 pod 中添加注释:)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM