Configuring metrics collection for cert-manager Operator for Red Hat OpenShift operands by using a ServiceMonitor

You can configure metrics collection for the cert-manager Operator for Red Hat OpenShift operands by creating a ServiceMonitor custom resource (CR).

The cert-manager Operator for Red Hat OpenShift operands expose metrics by default on port 9402 at the /metrics service endpoint. The ServiceMonitor CR enables Prometheus Operator to collect custom metrics.

Prerequisites
  • You have access to the cluster as a user with the cluster-admin role.

  • You have installed the cert-manager Operator for Red Hat OpenShift.

  • You have enabled the user workload monitoring.

Procedure
  1. Create the ServiceMonitor CR:

    1. Create the YAML file that defines the ServiceMonitor CR:

      Example servicemonitor-cert-manager.yaml file
      apiVersion: monitoring.coreos.com/v1
      kind: ServiceMonitor
      metadata:
        labels:
          app: cert-manager
          app.kubernetes.io/instance: cert-manager
          app.kubernetes.io/name: cert-manager
        name: cert-manager
        namespace: cert-manager
      spec:
        endpoints:
          - honorLabels: false
            interval: 60s
            path: /metrics
            scrapeTimeout: 30s
            targetPort: 9402
        selector:
          matchExpressions:
            - key: app.kubernetes.io/name
              operator: In
              values:
                - cainjector
                - cert-manager
                - webhook
            - key: app.kubernetes.io/instance
              operator: In
              values:
                - cert-manager
            - key: app.kubernetes.io/component
              operator: In
              values:
                - cainjector
                - controller
                - webhook
    2. Create the ServiceMonitor CR by running the following command:

      $ oc apply -f servicemonitor-cert-manager.yaml

      After the ServiceMonitor CR is created, the user workload Prometheus instance begins metrics collection from the cert-manager Operator for Red Hat OpenShift operands. The collected metrics are labeled with job="cert-manager",job="cert-manager-cainjector", and job="cert-manager-webhook".

Verification
  1. In the Red Hat OpenShift Container Platform web console, navigate to ObserveTargets.

  2. In the Label filter field, enter the following labels to filter the metrics targets for each operand:

    $ service=cert-manager
    $ service=cert-manager-webhook
    $ service=cert-manager-cainjector
  3. Confirm that the Status column shows Up for the cert-manager, cert-manager-webhook, and cert-manager-cainjector entries.