이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 3. Monitoring Camel Spring Boot integrations
This chapter explains how to monitor integrations on Red Hat build of Camel Spring Boot at runtime. You can use the Prometheus Operator that is already deployed as part of OpenShift Monitoring to monitor your own applications.
3.1. Enabling user workload monitoring in OpenShift 링크 복사링크가 클립보드에 복사되었습니다!
You can enable the monitoring for user-defined projects by setting the enableUserWorkload: true field in the cluster monitoring ConfigMap object.
In OpenShift Container Platform 4.13 you must remove any custom Prometheus instances before enabling monitoring for user-defined projects.
Prerequisites
You must have access to the cluster as a user with the cluster-admin cluster role access to enable monitoring for user-defined projects in OpenShift Container Platform. Cluster administrators can then optionally grant users permission to configure the components that are responsible for monitoring user-defined projects.
- You have cluster admin access to the OpenShift cluster.
- You have installed the OpenShift CLI (oc).
-
You have created the
cluster-monitoring-configConfigMap object. -
Optional: You have created and configured the
user-workload-monitoring-configConfigMap object in theopenshift-user-workload-monitoringproject. You can add configuration options to this ConfigMap object for the components that monitor user-defined projects.
Every time you save configuration changes to the user-workload-monitoring-config ConfigMap object, the pods in the openshift-user-workload-monitoring project are redeployed. It can sometimes take a while for these components to redeploy. You can create and configure the ConfigMap object before you first enable monitoring for user-defined projects, to prevent having to redeploy the pods often.
Procedure
Login to OpenShift with administrator permissions.
oc login --user system:admin --token=my-token --server=https://my-cluster.example.com:6443
oc login --user system:admin --token=my-token --server=https://my-cluster.example.com:6443Copy to Clipboard Copied! Toggle word wrap Toggle overflow Edit the
cluster-monitoring-configConfigMap object.oc -n openshift-monitoring edit configmap cluster-monitoring-config
$ oc -n openshift-monitoring edit configmap cluster-monitoring-configCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add
enableUserWorkload: truein the data/config.yaml section.Copy to Clipboard Copied! Toggle word wrap Toggle overflow When it is set to true, the
enableUserWorkloadparameter enables monitoring for user-defined projects in a cluster.Save the file to apply the changes. The monitoring for the user-defined projects is then enabled automatically.
NoteWhen the changes are saved to the
cluster-monitoring-configConfigMap object, the pods and other resources in theopenshift-monitoringproject might be redeployed. The running monitoring processes in that project might also be restarted.Verify that the
prometheus-operator,prometheus-user-workloadandthanos-ruler-user-workloadpods are running in theopenshift-user-workload-monitoringproject.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
3.2. Deploying a Camel Spring Boot application 링크 복사링크가 클립보드에 복사되었습니다!
After you enable the monitoring for your project, you can deploy and monitor the Camel Spring Boot application. This section uses the monitoring-micrometrics-grafana-prometheus example listed in the Camel Spring Boot Examples.
Procedure
Add the openshift-maven-plugin to the
pom.xmlfile of themonitoring-micrometrics-grafana-prometheusexample. In thepom.xml, add an openshift profile to allow deployment to openshift through the openshift-maven-plugin.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the Prometheus support. In order to add the Prometheus support to your Camel Spring Boot application, expose the Prometheus statistics on an actuator endpoint.
Edit your
src/main/resources/application.propertiesfile. If you have amanagement.endpoints.web.exposure.includeentry, add prometheus, metrics, and health. If you do not have amanagement.endpoints.web.exposure.includeentry, please add one.expose actuator endpoint via HTTP management.endpoints.web.exposure.include=mappings,metrics,health,shutdown,jolokia,prometheus
# expose actuator endpoint via HTTP management.endpoints.web.exposure.include=mappings,metrics,health,shutdown,jolokia,prometheusCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Add the following to the
<dependencies/>section of your pom.xml to add some starter support to your application.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the following to the
Application.javaof your Camel Spring Boot application.Copy to Clipboard Copied! Toggle word wrap Toggle overflow The updated
Application.javais shown below.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy the application to OpenShift.
mvn -Popenshift oc:deploy
mvn -Popenshift oc:deployCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify if your application is deployed.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the Service Monitor for this application so that Openshift’s prometheus instance can start scraping from the / actuator/prometheus endpoint.
Create the following YAML manifest for a Service monitor. In this example, the file is named as
servicemonitor.yaml.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add a Service Monitor for this application.
oc apply -f servicemonitor.yml servicemonitor.monitoring.coreos.com/csb-demo-monitor "myapp" created
oc apply -f servicemonitor.yml servicemonitor.monitoring.coreos.com/csb-demo-monitor "myapp" createdCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verify that the service monitor was successfully deployed.
oc get servicemonitor NAME AGE csb-demo-monitor 9m17s
oc get servicemonitor NAME AGE csb-demo-monitor 9m17sCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
Verify that you can see the service monitor in the list of scrape targets. In the Administrator view, navigate to Observe
Targets. You can find csb-demo-monitorwithin the list of scrape targets. -
Wait about ten minutes after deploying the servicemonitor. Then navigate to the Observe
Metrics in the Developer view. Select Custom query in the drop-down menu and type camelto view the Camel metrics that are exposed through the /actuator/prometheus endpoint.
Red Hat does not offer support for installing and configuring Prometheus and Grafana on non-OCP environments.