|
| 1 | +--- |
| 2 | +title: Monitor Java applications running in any environment - Azure Monitor Application Insights |
| 3 | +description: Application performance monitoring for Java applications running on any environment with Java standalone agent without instrumenting the app. Distributed tracing and application map. |
| 4 | +ms.topic: conceptual |
| 5 | +ms.date: 04/16/2020 |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +# Configuring JVM args Java standalone agent for Azure Monitor Application Insights |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +## Azure environments |
| 14 | + |
| 15 | +Configure [App Services](https://docs.microsoft.com/azure/app-service/configure-language-java#set-java-runtime-options). |
| 16 | + |
| 17 | +## Spring Boot |
| 18 | + |
| 19 | +Add the JVM arg `-javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar` somewhere before `-jar <myapp.jar>`, for example: |
| 20 | + |
| 21 | +``` |
| 22 | +java -javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar -jar <myapp.jar> |
| 23 | +``` |
| 24 | + |
| 25 | +> [!NOTE] |
| 26 | +> Args placed after `-jar <myapp.jar>` are passed to the app as program args. |
| 27 | +
|
| 28 | + |
| 29 | +## Tomcat 8 (Linux) |
| 30 | + |
| 31 | +### Tomcat installed via `apt-get` or `yum` |
| 32 | + |
| 33 | +If you installed Tomcat via `apt-get` or `yum`, then you should have a file `/etc/tomcat8/tomcat8.conf`. Add this line to the end of that file: |
| 34 | + |
| 35 | +``` |
| 36 | +JAVA_OPTS="$JAVA_OPTS -javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar" |
| 37 | +``` |
| 38 | + |
| 39 | +### Tomcat installed via download and unzip |
| 40 | + |
| 41 | +If you installed Tomcat via download and unzip from [https://tomcat.apache.org](https://tomcat.apache.org), then you should have a file `<tomcat>/bin/catalina.sh`. Create a new file in the same directory named `<tomcat>/bin/setenv.sh` with the following content: |
| 42 | + |
| 43 | +``` |
| 44 | +CATALINA_OPTS="$CATALINA_OPTS -javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar" |
| 45 | +``` |
| 46 | + |
| 47 | +If the file `<tomcat>/bin/setenv.sh` already exists, then modify that file and add `-javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar` to `CATALINA_OPTS`. |
| 48 | + |
| 49 | + |
| 50 | +## Tomcat 8 (Windows) |
| 51 | + |
| 52 | +### Running Tomcat from the command line |
| 53 | + |
| 54 | +Locate the file `<tomcat>/bin/catalina.bat`. Create a new file in the same directory named `<tomcat>/bin/setenv.bat` with the following content: |
| 55 | + |
| 56 | +``` |
| 57 | +set CATALINA_OPTS=%CATALINA_OPTS% -javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar |
| 58 | +``` |
| 59 | + |
| 60 | +Quotes are not necessary, but if you want to include them, the proper placement is: |
| 61 | + |
| 62 | +``` |
| 63 | +set "CATALINA_OPTS=%CATALINA_OPTS% -javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar" |
| 64 | +``` |
| 65 | + |
| 66 | +If the file `<tomcat>/bin/setenv.bat` already exists, just modify that file and add `-javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar` to `CATALINA_OPTS`. |
| 67 | + |
| 68 | +### Running Tomcat as a Windows service |
| 69 | + |
| 70 | +Locate the file `<tomcat>/bin/tomcat8w.exe`. Run that executable and add `-javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar` to the `Java Options` under the `Java` tab. |
| 71 | + |
| 72 | + |
| 73 | +## JBoss EAP 7 |
| 74 | + |
| 75 | +### Standalone server |
| 76 | + |
| 77 | +Add `-javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar` to the existing `JAVA_OPTS` environment variable in the file `JBOSS_HOME/bin/standalone.conf` (Linux) or `JBOSS_HOME/bin/standalone.conf.bat` (Windows): |
| 78 | + |
| 79 | +```java ... |
| 80 | + JAVA_OPTS="<b>-javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar</b> -Xms1303m -Xmx1303m ..." |
| 81 | + ... |
| 82 | +``` |
| 83 | + |
| 84 | +### Domain server |
| 85 | + |
| 86 | +Add `-javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar` to the existing `jvm-options` in `JBOSS_HOME/domain/configuration/host.xml`: |
| 87 | + |
| 88 | +```xml |
| 89 | +... |
| 90 | +<jvms> |
| 91 | + <jvm name="default"> |
| 92 | + <heap size="64m" max-size="256m"/> |
| 93 | + <jvm-options> |
| 94 | + <option value="-server"/> |
| 95 | + <!--Add Java agent jar file here--> |
| 96 | + <option value="-javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar"/> |
| 97 | + <option value="-XX:MetaspaceSize=96m"/> |
| 98 | + <option value="-XX:MaxMetaspaceSize=256m"/> |
| 99 | + </jvm-options> |
| 100 | + </jvm> |
| 101 | +</jvms> |
| 102 | +... |
| 103 | +``` |
| 104 | + |
| 105 | +If you are running multiple managed servers on a single host, you will need to add `applicationinsights.agent.id` to the `system-properties` for each `server`: |
| 106 | + |
| 107 | +```xml |
| 108 | +... |
| 109 | +<servers> |
| 110 | + <server name="server-one" group="main-server-group"> |
| 111 | + <!--Edit system properties for server-one--> |
| 112 | + <system-properties> |
| 113 | + <property name="applicationinsights.agent.id" value="..."/> |
| 114 | + </system-properties> |
| 115 | + </server> |
| 116 | + <server name="server-two" group="main-server-group"> |
| 117 | + <socket-bindings port-offset="150"/> |
| 118 | + <!--Edit system properties for server-two--> |
| 119 | + <system-properties> |
| 120 | + <property name="applicationinsights.agent.id" value="..."/> |
| 121 | + </system-properties> |
| 122 | + </server> |
| 123 | +</servers> |
| 124 | +... |
| 125 | +``` |
| 126 | + |
| 127 | +The specified `applicationinsights.agent.id` value must be unique. It is used to create a subdirectory under the applicationinsights directory, as each JVM process needs its own local applicationinsights config and local applicationinsights log file. Also, if reporting to the central collector, the `applicationinsights.properties` file is shared by the multiple managed servers, and so the specified `applicationinsights.agent.id` is needed to override the `agent.id` setting in that shared file. `applicationinsights.agent.rollup.id` can be similarly specified in the server's `system-properties` if you need to override the `agent.rollup.id` setting per managed server. |
| 128 | + |
| 129 | + |
| 130 | +## Jetty 9 |
| 131 | + |
| 132 | +Add these lines to `start.ini` |
| 133 | + |
| 134 | +``` |
| 135 | +--exec |
| 136 | +-javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar |
| 137 | +``` |
| 138 | + |
| 139 | + |
| 140 | +## Payara 5 |
| 141 | + |
| 142 | +Add `-javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar` to the existing `jvm-options` in `glassfish/domains/domain1/config/domain.xml`: |
| 143 | + |
| 144 | +```xml |
| 145 | +... |
| 146 | +<java-config ...> |
| 147 | + <!--Edit the JVM options here--> |
| 148 | + <jvm-options> |
| 149 | + -javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar> |
| 150 | + </jvm-options> |
| 151 | + ... |
| 152 | +</java-config> |
| 153 | +... |
| 154 | +``` |
| 155 | + |
| 156 | +## WebSphere 8 |
| 157 | + |
| 158 | +Open Management Console |
| 159 | +go to **servers > WebSphere application servers > Application servers**, choose the appropriate application servers and click on: |
| 160 | + |
| 161 | +``` |
| 162 | +Java and Process Management > Process definition > Java Virtual Machine |
| 163 | +``` |
| 164 | +In "Generic JVM arguments" add the following: |
| 165 | +``` |
| 166 | +-javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar |
| 167 | +``` |
| 168 | +After that, save and restart the application server. |
| 169 | + |
| 170 | + |
| 171 | +## OpenLiberty 18 |
| 172 | + |
| 173 | +Create a new file `jvm.options` in the server directory (for example `<openliberty>/usr/servers/defaultServer`), and add this line: |
| 174 | +``` |
| 175 | +-javaagent:path/to/applicationinsights-agent-3.0.0-PREVIEW.jar |
| 176 | +``` |
0 commit comments