3.2. Specifying how a service is monitored by Cluster Observability Operator
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 /metrics endpoint.
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. The 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 ns1-coo namespace.
Prerequisites
-
You have access to the cluster as a user with the
cluster-admincluster 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-appsample service in thens1-coonamespace.참고The
prometheus-coo-example-appsample service does not support TLS authentication.
Procedure
Create a YAML file named
example-coo-app-service-monitor.yamlthat contains the followingServiceMonitorobject configuration details:apiVersion: monitoring.rhobs/v1 kind: ServiceMonitor metadata: labels: k8s-app: prometheus-coo-example-monitor name: prometheus-coo-example-monitor namespace: ns1-coo spec: endpoints: - interval: 30s port: web scheme: http selector: matchLabels: app: prometheus-coo-example-appThis configuration defines a
ServiceMonitorobject that theMonitoringStackobject will reference to scrape the metrics data exposed by theprometheus-coo-example-appsample service.Apply the configuration to the cluster by running the following command:
$ oc apply -f example-coo-app-service-monitor.yamlVerify that the
ServiceMonitorresource is created by running the following command and observing the output:$ oc -n ns1-coo get servicemonitors.monitoring.rhobsExample output
NAME AGE prometheus-coo-example-monitor 81m