Enabling JMX for Jetty

Prior to adding a new JMX test, you need to enable the JMX support for the JRE of the target server. To enable JMX for pulling out metrics from Jetty server, the following needs to be done:

  1. Once the Jetty server is started, you need to check whether the JMX module is enabled or not. To verify this, you need to check whether the <<JETTY_BASE>>/start.d folder contains the following JMX files in the command line:

    • jmx.ini

    • jmx-remote.ini

  2. If the above mentioned JMX files are not available, then append the following lines to the command line as shown below:

    <<JETTY_BASE>>/start.d/jmx.ini

    <<JETTY_BASE>>/start.d/jmx-remote.ini

    You can also enable JMX either by adding JMX modules or JMX system properties in the command line as discussed in following sections below:

Enabling JMX by adding JMX modules

  1. To enable JMX using JMX modules, you need to append two modules in the command line when starting the Jetty server as shown below:

    java -jar %JETTY_HOME%/start.jar --add-module=jmx

    java -jar %JETTY_HOME%/start.jar --add-module=jmx -remote

    Note:

    This is required only once when starting the server.

  2. Once the Jetty server is started using the above command, check the console log or jetty server log as shown below. You will be able to view JMX service URL in the log which represents that JMX is enabled.

    D:\base_environment\app_servers\jetty\jetty-distribution-9.4.49.v20220914\demo-base>java -jar %JETTY_HOME%\start.jar

    2023-11-02 14.34:37.632:INFO::main: Logging initialized @168ms to otg.eclipse.jetty.util.log.StdErrLog

    2023-11-02 14:34:38.193:WARN::main: demo test-realm is deployed. DO NOT USE IN PRODUCTION!

    2023-11-02 14:34:38.199:INFO:oejs.Server:main: jetty-9.4.49.v20220914; built: 2022-09-14T01:07:36.601Z; git: 4231a3b2e4cb8548a412a789936d640a97b1aa0a; jvm 17.0.8+7

    2023-11-02 14:34:38.260:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:///D:/base_environment/app_servers/jetty/jetty-distribution-9.4.49.v20220914/demo-base/webapps/] at interval 1

    2023-11-02 14:34:41.011:INFO:oejj.ConnectorServer:main: JMX URL: service:jmx:rmi://localhost:1099/jndi/rmi://localhost:1099/jmxrmi

    2023-11-02 14:34:41.273:INFO:oeja.AnnotationConfiguration:main: Scanning elapsed time=49ms

    2023-11-02 14:34:41.548:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0

    2023-11-02 14:34:41.549:INFO:oejs.session:main: No SessionScavenger set, using defaults

    2023-11-02 14:34:41.550:INFO:oejs.session:main: node0 Scavenging every 600000ms

Enabling JMX by adding JMX system properties

To enable JMX using JMX system properties, add the JMX system properties in the command line when starting the Jetty Server as shown below.

D:\base_environment\app_servers\jetty\jetty-distribution-9.4.49.v20220914\demo-base>java

-Dcom.sun.management.jmxremote

-Dcom.sun.management.port-12457

-Dcom.sun.management.jmxremote.ssl=false

-Dcom.sun.management.jmxremote.authenticate=false -jar %JETTY_HOME%/start.jar