|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * security/zer_trust_workload_identity_manager/zero-trust-manager-monitoring.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="zero-trust-manager-enable-metrics-agent_{context}"] |
| 7 | += Configuring metrics collection for SPIRE agent by using a Service Monitor |
| 8 | + |
| 9 | +The SPIRE Agent operand exposes metrics by default on port `9402` at the `/metrics` endpoint. You can configure metrics collection for the SPIRE Agent by creating a `ServiceMonitor` custom resource (CR), which enables Prometheus Operator to collect custom metrics. |
| 10 | + |
| 11 | +.Prerequisites |
| 12 | + |
| 13 | +* You have access to the cluster as a user with the `cluster-admin` cluster role. |
| 14 | +* You have installed the {zero-trust-full}. |
| 15 | +* You have deployed the SPIRE Agent operand in the cluster. |
| 16 | +* You have enabled the user workload monitoring. |
| 17 | +
|
| 18 | +.Procedure |
| 19 | + |
| 20 | +. Create the `ServiceMonitor` CR: |
| 21 | + |
| 22 | +.. Create the YAML file that defines `ServiceMonitor` CR: |
| 23 | ++ |
| 24 | +.Example `servicemonitor-spire-agent.yaml` file |
| 25 | +[source,yaml] |
| 26 | +---- |
| 27 | +apiVersion: monitoring.coreos.com/v1 |
| 28 | +kind: ServiceMonitor |
| 29 | +metadata: |
| 30 | + labels: |
| 31 | + app.kubernetes.io/name: agent |
| 32 | + app.kubernetes.io/instance: spire |
| 33 | + name: spire-agent-metrics |
| 34 | + namespace: zero-trust-workload-identity-manager |
| 35 | +spec: |
| 36 | + endpoints: |
| 37 | + - port: metrics |
| 38 | + interval: 30s |
| 39 | + path: /metrics |
| 40 | + selector: |
| 41 | + matchLabels: |
| 42 | + app.kubernetes.io/name: agent |
| 43 | + app.kubernetes.io/instance: spire |
| 44 | + namespaceSelector: |
| 45 | + matchNames: |
| 46 | + - zero-trust-workload-identity-manager |
| 47 | +---- |
| 48 | + |
| 49 | +.. Create the `ServiceMonitor` CR by running the following command: |
| 50 | ++ |
| 51 | +[source,terminal] |
| 52 | +---- |
| 53 | +$ oc create -f servicemonitor-spire-agent.yaml |
| 54 | +---- |
| 55 | ++ |
| 56 | +After the `ServiceMonitor` CR is created, the user workload Prometheus instance begins metrics collection from the SPIRE Agent. The collected metrics are labeled with `job="spire-agent"`. |
| 57 | + |
| 58 | +.Verification |
| 59 | + |
| 60 | +. In the {product-title} web console, navigate to *Observe* → *Targets*. |
| 61 | + |
| 62 | + |
| 63 | +. In the *Label* filter field, enter the following label to filter the metrics targets: |
| 64 | ++ |
| 65 | +[source,terminal] |
| 66 | +---- |
| 67 | +$ service=spire-agent |
| 68 | +---- |
| 69 | + |
| 70 | +. Confirm that the *Status* column shows `Up` for the `spire-agent-metrics` entry. |
0 commit comments