<p>I'm new to Prometheus, so I'm not sure what I'm doing wrong but these are my service and service monitor definitions.</p>
<pre><code>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
</code></pre>
<pre><code>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: &quot;8080&quot;
  jobLabel: app.kubernetes.io/instance
  selector:
    matchLabels:
      app.kubernetes.io/component: jenkins
      app.kubernetes.io/instance: jenkins
</code></pre>
<p>But my Jenkins doesn't appear under the targets list on the Prometheus UI.
It appears under <code>Service Discovery</code> which makes me believe that the Operator is correctly picking it up through the <code>release: prometheus</code> label.</p>
<p>I have installed the <code>prometheus plugin</code> on jenkins and I'm able to view metrics when I curl <code>https://&lt;JENKINS_URL&gt;/prometheus/</code></p>
<p>What I'm trying to figure out is why Jenkins doesn't appear under the <code>targets</code> list.</p>
<p>Is there any proper documentation on how to go about this or can anyone who has successfully implemented this share any pointers?</p>

<p>There is no better docs than reading the code itself.</p>
<p>You need pay attention to <a href="https://github.com/prometheus-operator/kube-prometheus/blob/master/manifests/setup/prometheus-operator-0servicemonitorCustomResourceDefinition.yaml#L140" rel="nofollow noreferrer">this line in the custom resource definition of ServiceMonitor</a>.</p>
<pre class="lang-yaml prettyprint-override"><code>port:
  description: Name of the service port this endpoint refers to.
               Mutually exclusive with targetPort.
  type: string
</code></pre>
<p>Basically, you created a serviceMonitor to a service port named &quot;8080&quot;.</p>
<pre class="lang-yaml prettyprint-override"><code>endpoints:
  - interval: 10s
    path: /prometheus/
    port: &quot;8080&quot;
</code></pre>
<p>But you defined an unnamed service whose port number is 8080.</p>
<pre class="lang-yaml prettyprint-override"><code>spec:
  type: ClusterIP
  ports:
    - port: 8080
      targetPort: 8080
</code></pre>
<p>Do you see the mismatch now?</p>
<p>You need
either use targetPort: 8080 and targetPort only in serviceMonitor,</p>
<p>or, even better, use port: &quot;web&quot; in serviceMonitor, and at the same time, name your service &quot;web&quot;.</p>
<p>ServiceMonitor:</p>
<pre class="lang-yaml prettyprint-override"><code>endpoints:
  - interval: 10s
    path: /prometheus/
    port: &quot;web&quot;
</code></pre>
<p>Service:</p>
<pre class="lang-yaml prettyprint-override"><code>spec:
  type: ClusterIP
  ports:
    - name: &quot;web&quot;
      port: 8080
      targetPort: 8080
</code></pre>
