Search code examples
jenkinskubernetesprometheus-operator

How to scrape Jenkins metrics using Prometheus Operator


I'm using Kube-prometheus with Prometheus-Operator to monitor my K8s cluster. I've deployed Jenkins on my cluster and want to start to get metrics here using ServiceMonitor.

I've installed the Prometheus plugin which exposes the metrics using /prometheus or by /metrics/API_KEY/metrics, this works fine if I create a new static job. However, if I want to use ServiceMonitor, it does not work.

apiVersion: monitoring.coreos.com/v1                                                                                                                                                                        
kind: ServiceMonitor
metadata:
  labels:
    k8s-app: jenkins
  name: jenkins
  namespace: monitoring
spec:
  endpoints:
  - interval: 30s 
    port: http
    path: /metrics/y1H6G16T-DhqpHdW9XwHWnP9FWAXMMfy4XnXVnyoIOEV3-gPJZKN284OFUcVkPxL/metrics
  selector:
    matchLabels:
      jenkins: main

Solution

  • I don't know about ServiceMonitor, but I monitor my Jenkins instance without any problem, using annotations on Jenkins' service :

    prometheus.io/scrape: "true"
    prometheus.io/port: "8080"
    prometheus.io/path: "/prometheus"