You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Enabling metrics and monitoring for `cert-manager`
1
+
## Monitoring cert-manager Metrics with OpenShift Monitoring
2
2
3
-
Cert-Manager exposes controller metrics in the format expected by [Prometheus Operator](https://github.com/prometheus-operator/prometheus-operator).
3
+
cert-manager exposes metrics in the format expected by [Prometheus Operator](https://github.com/prometheus-operator/prometheus-operator) for all three of its core components: controller, cainjector, and webhook.
4
4
5
-
ServiceMonitor resource needs to be created to scrape metrics from cert-manager operand, make sure Prometheus Operator is configured with required selectors.
5
+
You can configure OpenShift Monitoring to collect metrics from cert-manager operands by enabling the built-in user workload monitoring stack. This allows you to monitor user-defined projects in addition to the default platform monitoring.
6
6
7
-
`.spec.serviceMonitorNamespaceSelector` and `.spec.serviceMonitorSelector` fields of prometheus resource should contain corresponding `matchLabels: openshift.io/cluster-monitoring:true`. To verify it, we can run the following commands.
7
+
### Enable User Workload Monitoring
8
8
9
-
```sh
10
-
kubectl -n monitoring get prometheus k8s --template='{{.spec.serviceMonitorNamespaceSelector}}{{"\n"}}{{.spec.serviceMonitorSelector}}{{"\n"}}'
Please follow the steps below to `enable the monitoring foruser-defined projects`in Openshift:
9
+
Cluster administrators can enable monitoring for user-defined projects by setting the `enableUserWorkload: true` field in the cluster monitoring ConfigMap object. For more details, Please look at the detailed documentation to [Configuring user workload monitoring](https://docs.redhat.com/en/documentation/openshift_container_platform/4.18/html/monitoring/configuring-user-workload-monitoring).
27
10
28
-
Cluster administrators can enable monitoring foruser-defined projects by setting the `enableUserWorkload: true` fieldin the cluster monitoring ConfigMap object.
29
-
30
-
1. Edit the cluster-monitoring-config ConfigMap object:
2. Add `enableUserWorkload: true` under data/config.yaml:
11
+
1. Create or edit the ConfigMap `cluster-monitoring-config` in namespace `openshift-monitoring`.
35
12
36
13
```
14
+
$ oc apply -f - <<EOF
37
15
apiVersion: v1
38
16
kind: ConfigMap
39
17
metadata:
@@ -42,59 +20,151 @@ metadata:
42
20
data:
43
21
config.yaml: |
44
22
enableUserWorkload: true
23
+
EOF
45
24
```
46
25
47
-
3. Check that the prometheus-operator, prometheus-user-workload and thanos-ruler-user-workload pods are running in the openshift-user-workload-monitoring project. It might take a short whilefor the pods to start:
26
+
2. Wait and check that the monitoring components for user workloads are up and running in the `openshift-user-workload-monitoring` namespace.
48
27
49
-
`$ oc -n openshift-user-workload-monitoring get pod`
When set to true, the enableUserWorkload parameter enables monitoring foruser-defined projectsin a cluster.
61
37
62
-
For more details, Please look at the detailed documentation to [enable the monitoring foruser-defined projectsin Openshift](https://docs.openshift.com/container-platform/4.11/monitoring/enabling-monitoring-for-user-defined-projects.html):
38
+
You should see pods like `prometheus-operator`, `prometheus-user-workload`, and `thanos-ruler-user-workload` in a Running status.
63
39
64
-
4. Apply the Service Monitor in your openshift cluster.
40
+
### Configure Metric Scraping for cert-manager
41
+
42
+
cert-manager operands (controller, webhook, and cainjector) expose Prometheus metrics on port 9402 by default via the `/metrics` service endpoint. To collect metrics from these services, you need to define how Prometheus should scrape their metrics endpoints. This is typically done using a ServiceMonitor or PodMonitor custom resource. The following example uses the ServiceMonitor for demonstration.
43
+
44
+
1. Check the cert-manager services in the `cert-manager` namespace.
2. Apply a YAML manifest for the ServiceMonitor to look for services matching the specified labels within the `cert-manager` namespace and scrape metrics from their `/metrics` path on port 9402.
55
+
56
+
```
57
+
$ oc apply -f - <<EOF
68
58
apiVersion: monitoring.coreos.com/v1
69
59
kind: ServiceMonitor
70
60
metadata:
71
61
labels:
72
62
app: cert-manager
73
-
app.kubernetes.io/component: controller
74
63
app.kubernetes.io/instance: cert-manager
75
64
app.kubernetes.io/name: cert-manager
76
65
name: cert-manager
77
66
namespace: cert-manager
78
67
spec:
79
68
endpoints:
80
-
- interval: 30s
81
-
port: tcp-prometheus-servicemonitor
82
-
scheme: http
69
+
- honorLabels: false
70
+
interval: 60s
71
+
path: /metrics
72
+
scrapeTimeout: 30s
73
+
targetPort: 9402
83
74
selector:
84
-
matchLabels:
85
-
app.kubernetes.io/component: controller
86
-
app.kubernetes.io/instance: cert-manager
87
-
app.kubernetes.io/name: cert-manager
75
+
matchExpressions:
76
+
- key: app.kubernetes.io/name
77
+
operator: In
78
+
values:
79
+
- cainjector
80
+
- cert-manager
81
+
- webhook
82
+
- key: app.kubernetes.io/instance
83
+
operator: In
84
+
values:
85
+
- cert-manager
86
+
- key: app.kubernetes.io/component
87
+
operator: In
88
+
values:
89
+
- cainjector
90
+
- controller
91
+
- webhook
92
+
EOF
93
+
```
94
+
95
+
Once the ServiceMonitor is in place and user workload monitoring is enabled, the Prometheus instance for user workloads will start collecting metrics from the cert-manager operands. The scraped metrics will be labeled with `job="cert-manager"`, `job="cert-manager-cainjector"`, or `job="cert-manager-webhook"` respectively.
96
+
97
+
You can select and view these Prometheus Targets via the OpenShift web console, by navigating to the "Observe" -> "Targets" page.
98
+
99
+
### Query Metrics
100
+
101
+
As a cluster administrator or as a user with view permissions for all projects, You can access these metrics using the command line or via the OpenShift web console. For more details, Please look at the detailed documentation to [Accessing metrics](https://docs.redhat.com/en/documentation/openshift_container_platform/4.18/html/monitoring/accessing-metrics).
102
+
103
+
1. Retrieve a bearer token. You can use the following command to get a token for a specific service account.
The 'Service Monitor' will be collecting the metrics through the cert-manager `service` and will be using the port name of the service as its endpoints port.
92
-
Following [Template](https://github.com/cert-manager/cert-manager/blob/master/deploy/charts/cert-manager/templates/servicemonitor.yaml) can be used for the helm configurations.
108
+
Alternatively, if you have cluster-admin access or view permissions for all projects, you might be able to use `$(oc whoami -t)` to get your own user token.
93
109
94
-
### Quering Metrics
110
+
2. Get the OpenShift API route for Thanos Querier.
95
111
96
-
As a cluster administrator or as a user with view permissions forall projects, you can access metrics for all default OpenShift Container Platform and user-defined projectsin the Metrics UI by using the endpoints of the `cert-manager service`.
112
+
```
113
+
$ URL=$(oc get route thanos-querier -n openshift-monitoring -o=jsonpath='{.status.ingress[0].host}')
114
+
```
97
115
98
-
`$ oc describe service cert-manager -n cert-manager`
116
+
3. Query the metrics using `curl`, authenticating with the bearer token. The query uses the `/api/v1/query endpoint`. The output will be in JSON format, using `| jq` for pretty JSON formatting.
To query cert-manager controller metrics, select`Observe → Metrics`and filter the metrics of the cert-manager controller with `{instance="<Endpoints>"}` or `{endpoint="tcp-prometheus-servicemonitor"}`.
170
+
In OpenShift web console, you can also view these metrics by navigating to the "Observe" -> "Metrics" page, and filter the metrics of each operands with `{job="<JobLabel>"}`, `{instance="<Endpoints>"}` or other advanced query expressions.
0 commit comments