<p>I have kube-prometheus-stack running on a kubernetes cluster along with prometheus-blackbox-exporter. I want to monitor multiple http targets. I have tried setting this up with an servicemonitor but when I add a target the target does not get the right labels</p>
<p>The servicemonitor yaml:</p>
<pre><code>apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  annotations:
    meta.helm.sh/release-name: blackbox
    meta.helm.sh/release-namespace: default
  generation: 1
  labels:
    app.kubernetes.io/instance: blackbox
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: prometheus-blackbox-exporter
    app.kubernetes.io/version: 0.20.0
    helm.sh/chart: prometheus-blackbox-exporter-5.7.0
    release: kube-prometheus
  name: blackbox-prometheus-blackbox-exporter
  namespace: default
spec:
  endpoints:
    - interval: 10s
      path: /probe
      port: http
      scheme: http
      params:
        module: 
        - http_2xx
        target:
          - https://google.com
          - https://example.com
      metricRelabelings:
      - sourceLabels: [__address__]
        targetLabel: __param_target
  jobLabel: kube-prometheus
  selector:
    matchLabels:
      app.kubernetes.io/instance: blackbox
      app.kubernetes.io/name: prometheus-blackbox-exporter 
</code></pre>
<p>But in grafana I only get one instance label right:
<a href="https://i.stack.imgur.com/NSQxH.png" rel="nofollow noreferrer">grafana instances</a></p>

jasper sikkema
<p>spec.endpoints  is a <a href="https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api.md#monitoring.coreos.com/v1.ServiceMonitor" rel="nofollow noreferrer">list</a>. In yaml each lists element are defined with a <a href="https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html" rel="nofollow noreferrer">dash</a>.
So you have to modify your service monitor yaml as:</p>
<pre class="lang-yaml prettyprint-override"><code>spec:
  endpoints:
  - interval: 10s
    path: /probe
    port: metrics
    params:
      module:
      - http_2xx
      target:
      - https://www.google.com
    relabelings:
      - sourceLabels: [__param_target]
        targetLabel: target

  - interval: 10s
    path: /probe
    port: metrics
    params:
      module:
      - http_2xx
      target:
      - https://www.example.com
    relabelings:
      - sourceLabels: [__param_target]
        targetLabel: target

</code></pre>
<p>It works
<a href="https://i.stack.imgur.com/JMxzP.png" rel="nofollow noreferrer">like it is shown here</a></p>
