// Module included in the following assemblies:
//
// * backup_and_restore/application_backup_and_restore/troubleshooting/oadp-monitoring.adoc

:_mod-docs-content-type: PROCEDURE
[id="oadp-creating-service-monitor_{context}"]
= Creating OADP service monitor

[role="_abstract"]
Create a `ServiceMonitor` resource to scrape Velero metrics from the {oadp-short} service endpoint. This helps you collect metrics for monitoring backup and restore operations in the {product-title} monitoring stack.

{oadp-short} provides an `openshift-adp-velero-metrics-svc` service. The user workload monitoring service monitor must use the `openshift-adp-velero-metrics-svc` service.

.Procedure

. Ensure that the `openshift-adp-velero-metrics-svc` service exists. It should contain `app.kubernetes.io/name=velero` label, which is used as selector for the `ServiceMonitor` object.
+
[source,terminal]
----
$ oc get svc -n openshift-adp -l app.kubernetes.io/name=velero
----
+
.Example output
[source,terminal]
----
NAME                               TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
openshift-adp-velero-metrics-svc   ClusterIP   172.30.38.244   <none>        8085/TCP   1h
----

. Create a `ServiceMonitor` YAML file that matches the existing service label, and save the file as `3_create_oadp_service_monitor.yaml`. The service monitor is created in the `openshift-adp` namespace which has the `openshift-adp-velero-metrics-svc` service.
+
[source,yaml]
+
----
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  labels:
    app: oadp-service-monitor
  name: oadp-service-monitor
  namespace: openshift-adp
spec:
  endpoints:
  - interval: 30s
    path: /metrics
    targetPort: 8085
    scheme: http
  selector:
    matchLabels:
      app.kubernetes.io/name: "velero"
----

. Apply the `3_create_oadp_service_monitor.yaml` file:
+
[source,terminal]
----
$ oc apply -f 3_create_oadp_service_monitor.yaml
----
+
.Example output
[source,terminal]
----
servicemonitor.monitoring.coreos.com/oadp-service-monitor created
----

.Verification

* Confirm that the new service monitor is in an *Up* state by using the *Administrator* perspective of the {product-title} web console. Wait a few minutes for the service monitor to reach the *Up* state.
.. Navigate to the *Observe* -> *Targets* page.
.. Ensure the *Filter* is unselected or that the *User* source is selected and type `openshift-adp` in the `Text` search field.
.. Verify that the status for the *Status* for the service monitor is *Up*.
+
.OADP metrics targets

image::oadp-metrics-targets.png[OADP metrics targets]
