此内容没有您所选择的语言版本。
Chapter 5. Monitoring your application
This section contains information about monitoring your Eclipse Vert.x–based application running on OpenShift.
5.1.1. Accessing JVM metrics using Jolokia on OpenShift 复制链接链接已复制到粘贴板!
Jolokia is a built-in lightweight solution for accessing JMX (Java Management Extension) metrics over HTTP on OpenShift. Jolokia allows you to access CPU, storage, and memory usage data collected by JMX over an HTTP bridge. Jolokia uses a REST interface and JSON-formatted message payloads. It is suitable for monitoring cloud applications thanks to its comparably high speed and low resource requirements.
For Java-based applications, the OpenShift Web console provides the integrated hawt.io console that collects and displays all relevant metrics output by the JVM running your application.
Prerequistes
-
the
occlient authenticated - a Java-based application container running in a project on OpenShift
- latest JDK 1.8.0 image
Procedure
List the deployment configurations of the pods inside your project and select the one that corresponds to your application.
oc get dc
oc get dcCopy to Clipboard Copied! Toggle word wrap Toggle overflow NAME REVISION DESIRED CURRENT TRIGGERED BY MY_APP_NAME 2 1 1 config,image(my-app:6) ...
NAME REVISION DESIRED CURRENT TRIGGERED BY MY_APP_NAME 2 1 1 config,image(my-app:6) ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Open the YAML deployment template of the pod running your application for editing.
oc edit dc/MY_APP_NAME
oc edit dc/MY_APP_NAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow Add the following entry to the
portssection of the template and save your changes:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Redeploy the pod running your application.
oc rollout latest dc/MY_APP_NAME
oc rollout latest dc/MY_APP_NAMECopy to Clipboard Copied! Toggle word wrap Toggle overflow The pod is redeployed with the updated deployment configuration and exposes the port
8778.- Log into the OpenShift Web console.
- In the sidebar, navigate to Applications > Pods, and click on the name of the pod running your application.
- In the pod details screen, click Open Java Console to access the hawt.io console.
Additional resources
Prometheus connects to a monitored application to collect data; the application does not send metrics to a server.
Prerequisites
- Prometheus server running on your cluster
Procedure
Include the
vertx-micrometerandvertx-webdependencies in thepom.xmlfile of your application:pom.xml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Starting with version 3.5.4, exposing metrics for Prometheus requires that you configure the Eclipse Vert.x options in a custom
Launcherclass.In your custom
Launcherclass, override thebeforeStartingVertxandafterStartingVertxmethods to configure the metrics engine, for example:Example CustomLauncher.java file
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a custom
Verticleclass and override thestartmethod to collect metrics. For example, measure the execution time using theTimerclass:Example CustomVertxApp.java file
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set the
<vertx.verticle>and<vertx.launcher>properties in thepom.xmlfile of your application to point to your custom classes:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Launch your application:
mvn vertx:run
$ mvn vertx:runCopy to Clipboard Copied! Toggle word wrap Toggle overflow Invoke the traced endpoint several times:
curl http://localhost:8080/
$ curl http://localhost:8080/ HelloCopy to Clipboard Copied! Toggle word wrap Toggle overflow Wait at least 15 seconds for collection to occur, and see the metrics in Prometheus UI:
-
Open the Prometheus UI at http://localhost:9090/ and type
hellointo the Expression box. -
From the suggestions, select for example
application:hello_countand click Execute. - In the table that is displayed, you can see how many times the resource method was invoked.
-
Alternatively, select
application:hello_time_mean_secondsto see the mean time of all the invocations.
Note that all metrics you created are prefixed with
application:. There are other metrics, automatically exposed by Eclipse Vert.x as the Eclipse MicroProfile Metrics specification requires. Those metrics are prefixed withbase:andvendor:and expose information about the JVM in which the application runs.-
Open the Prometheus UI at http://localhost:9090/ and type
Additional resources
- For additional information about using Micrometer metrics with Eclipse Vert.x, see Eclipse Vert.x} Micrometer Metrics.