This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.2.5. Setting up metrics collection
To use the metrics exposed by your service, you must configure OpenShift Monitoring to scrape metrics from the /metrics
endpoint. You can do this by using a ServiceMonitor
custom resource definition (CRD) that specifies how to monitor a service or a PodMonitor
CRD that specifies how to monitor a pod. The former requires a Service
object, while the latter does not, which allows Prometheus to directly scrape metrics from the metrics endpoint exposed by a pod.
This procedure shows how to create a ServiceMonitor
resource for the service.
Prerequisites
-
Log in as a cluster administrator or a user with the
monitoring-edit
role.
Procedure
-
Create a YAML file for the
ServiceMonitor
resource configuration. In this example, the file is calledexample-app-service-monitor.yaml
. Fill the file with the configuration for creating the
ServiceMonitor
resource:Copy to Clipboard Copied! Toggle word wrap Toggle overflow This configuration makes OpenShift Monitoring scrape the metrics exposed by the sample service deployed in "Deploying a sample service", which includes the single
version
metric.Apply the configuration file to the cluster:
oc apply -f example-app-service-monitor.yaml
$ oc apply -f example-app-service-monitor.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow It will take some time to deploy the
ServiceMonitor
resource.You can check that the
ServiceMonitor
resource is running:oc -n ns1 get servicemonitor
$ oc -n ns1 get servicemonitor
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME AGE prometheus-example-monitor 81m
NAME AGE prometheus-example-monitor 81m
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Additional resources
See the Prometheus Operator API documentation for more information on ServiceMonitor
and PodMonitor
resources.