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-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 ns1-coo
namespace.
|
The prometheus-coo-example-app sample service does not support TLS authentication.
|
Procedure
-
Create a YAML file named example-coo-app-service-monitor.yaml
that contains the following serviceMonitor
object 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-app
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-coo-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 servicemonitors.monitoring.rhobs
Example output
NAME AGE
prometheus-coo-example-monitor 81m