이 콘텐츠는 선택한 언어로 제공되지 않습니다.
Chapter 6. Integrating with OpenShift
You can enable your Quarkus application to use the Micrometer metrics library for runtime and application metrics. Micrometer acts like a facade between your applications and third parties like Prometheus, which is embedded in OpenShift. The integration of Quarkus with OpenShift enables you to expose not only embedded metrics that are automatically enabled, but also custom metrics that are registered as part of your application.
For more information on configuring a variety of metrics, see the Quarkus Micrometer Community Guide.
Prerequisites
- You have access to Getting started with the OpenShift CLI, 4.6 or later
- You have an OpenShift instance
Procedure
Complete the following instructions and use embedded Prometheus in OpenShift to expose metrics from your Quarkus applications:
6.1. Enabling monitoring for user-defined projects in OpenShift 링크 복사링크가 클립보드에 복사되었습니다!
In Red Hat OpenShift Container Platform 4.6 or later, you can enable monitoring for your user-defined projects as well as default platform monitoring.
Prerequisites
- Have access to Getting started with the OpenShift CLI, 4.6 or later
- Have an OpenShift instance
Procedure
-
Go to Enabling monitoring for user-defined projects and follow specific instructions on how to enable user-defined project monitoring. In summary, you will create a ConfigMap in the namespace
openshift-monitoring
cluster-monitoring-config.yaml:
If you are using OpenShift 4.5 or earlier, use:
After you complete the steps to enable monitoring for user-defined projects, OpenShift automatically creates a namespace, openshift-user-workload-monitoring that you will deploy when you begin Deploying your Quarkus application to OpenShift and Creating a service monitor in your OpenShift project.
6.2. Deploying your Quarkus application to OpenShift 링크 복사링크가 클립보드에 복사되었습니다!
After setting up the required infrastructure, you must enable Micrometer with Prometheus.
Prerequisites
- You have access to Getting started with the OpenShift CLI, 4.6 or later
- You have an OpenShift instance
- You have created a ConfigMap in the previous section, Enabling monitoring for user-defined projects in OpenShift
Procedure
Implement a REST API:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add the micrometer registry facade:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow This Micrometer facade creates a counter that will be incremented every time you invoke the services. The registry helps to create custom metrics or use the metrics manually. You could also annotate methods as the following:
@GET @Counted(value = "greeting_counter") public String sayHello() { return "Hello!"; }@GET @Counted(value = "greeting_counter") public String sayHello() { return "Hello!"; }Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the application:
mvn compile quarkus:dev
mvn compile quarkus:devCopy to Clipboard Copied! Toggle word wrap Toggle overflow Call your service:
curl http://localhost:8080/hello
curl http://localhost:8080/helloCopy to Clipboard Copied! Toggle word wrap Toggle overflow The service should return with
Hello!Browse to
http://localhost:8080/q/metrics. You should see thegreeting_counterwith count 1.0 (the one you just completed):HELP greeting_counter_total
# HELP greeting_counter_total #TYPE greeting_counter_total counter greeting_counter_total 1.0Copy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy your Quarkus application into OpenShift by entering the extension
quarkus-openshiftinto yourpom.xml:<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-openshift</artifactId> </dependency><dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-openshift</artifactId> </dependency>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy your application into a newly created project called
my-projectin OpenShift:oc new-project my-project mvn clean package -Dquarkus.kubernetes.deploy=true -Dquarkus.openshift.expose=true -Dquarkus.openshift.labels.app-with-metrics=quarkus-app
oc new-project my-project mvn clean package -Dquarkus.kubernetes.deploy=true -Dquarkus.openshift.expose=true -Dquarkus.openshift.labels.app-with-metrics=quarkus-appCopy to Clipboard Copied! Toggle word wrap Toggle overflow
The app-with-metrics is explained in Creating a service monitor in your OpenShift project.
If you are using an OpenShift with unsecure SSL, you also need to append -Dquarkus.kubernetes-client.trust-certs=true to the Maven command.
6.3. Creating a service monitor in your OpenShift project 링크 복사링크가 클립보드에 복사되었습니다!
Prometheus uses a pull model to get metrics from applications, which means it scrapes or watches endpoints to pull metrics. Although the previous procedure helped to expose your service in your OpenShift instance, you have not configured anything in Prometheus to scrape your service yet. This is why the service monitor is necessary.
A service monitor is a custom resource that you must create in the same project or namespace where your service is running: my-project.
Procedure
Set up your
service-monitor.yaml:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply your service-monitor.yaml:
oc apply -f service-monitor.yaml
oc apply -f service-monitor.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command creates a service monitor named
prometheus-app-monitorthat will select applications with the labelapp-with-metrics: quarkus-app. This label was added during the Deploying your Quarkus application to OpenShift procedure. OpenShift calls the endpoint/metricsfor all the services labeled withapp-with-metrics: quarkus-app.To use your service monitor:
-
Call your greetings service:
curl http://quarkus-micrometer-my-project.ocp.host/hello. This increments yourgreeting_counter_totalcounter. - To see the metrics, browse to the OpenShift Console and select the Developer > Monitoring view.
- Select the Metrics tab.
-
In the Custom Query field, enter
greeting_counter_total.
-
Call your greetings service:
The metrics display in the table below the Custom Query field.