To use the metrics exposed by the sample service you created in the "Deploying a sample service for Cluster Observability Operator" section, you must configure monitoring components to scrape metrics from the
You can create this configuration by using a
ServiceMonitor object that specifies how the service is to be monitored, or a
PodMonitor object that specifies how a pod is to be monitored.
ServiceMonitor object requires a
Service object. The
PodMonitor object does not, which enables the
MonitoringStack object to scrape metrics directly from the metrics endpoint exposed by a pod.
This procedure shows how to create a
ServiceMonitor object for a sample service named
prometheus-coo-example-app in the
You have access to the cluster as a user with the
cluster-admin cluster role or as a user with administrative permissions for the namespace.
You have installed the Cluster Observability Operator.
You have deployed the
prometheus-coo-example-app sample service in the
prometheus-coo-example-app sample service does not support TLS authentication.
Create a YAML file named
example-coo-app-service-monitor.yaml that contains the following
ServiceMonitor object configuration details:
- interval: 30s
This configuration defines a
ServiceMonitor object that the
MonitoringStack object will reference to scrape the metrics data exposed by the
prometheus-coo-example-app sample service.
Apply the configuration to the cluster by running the following command:
$ oc apply -f example-app-service-monitor.yaml
Verify that the
ServiceMonitor resource is created by running the following command and observing the output:
$ oc -n ns1-coo get servicemonitor