開始使用 (補充)

在下列各節中,瞭解如何取得特定技術環境的Java自動結構。

Azure App Service

如需詳細資訊,請參閱 Azure App Service 和 Java 的應用程式監視

Azure Functions

如需詳細資訊,請參閱使用 Azure 監視器的 Application Insights 監視 Azure Functions

Azure Spring Apps

如需詳細資訊,請參閱在 Azure Spring Apps 中使用 Application Insights Java 內含式代理程式

容器

注意

使用 Spring Boot 原生映像應用程式時,請使用 Spring Boot 原生映像 Java 應用程式專案中的 Azure 監視器 OpenTelemetry Distro / Application Insights,而不是 Application Insights Java 代理程式。

Docker 進入點

如果您使用 exec 形式,請在參數清單中的 "-jar" 參數前面新增參數 -javaagent:"path/to/applicationinsights-agent-3.5.2.jar",例如:

ENTRYPOINT ["java", "-javaagent:path/to/applicationinsights-agent-3.5.2.jar", "-jar", "<myapp.jar>"]

如果您使用殼層表單,請在之前-jar的地方新增 Java 虛擬機 (JVM) arg-javaagent:"path/to/applicationinsights-agent-3.5.2.jar",例如:

ENTRYPOINT java -javaagent:"path/to/applicationinsights-agent-3.5.2.jar" -jar <myapp.jar>

Docker 檔案

Dockerfile 範例:

FROM ...

COPY target/*.jar app.jar

COPY agent/applicationinsights-agent-3.5.2.jar applicationinsights-agent-3.5.2.jar 

COPY agent/applicationinsights.json applicationinsights.json

ENV APPLICATIONINSIGHTS_CONNECTION_STRING="CONNECTION-STRING"
        
ENTRYPOINT["java", "-javaagent:applicationinsights-agent-3.5.2.jar", "-jar", "app.jar"]

在此範例中,您會從agent資料夾複製 applicationinsights-agent-3.5.2.jarapplicationinsights.json 檔案(您可以選擇電腦的任何資料夾)。 這兩個檔案必須位於 Docker 容器中的相同資料夾中。

合作夥伴容器映像

如果您使用無法修改的合作夥伴容器映像,請從外部將Application Insights Java代理程式 jar 掛接至容器。 設定容器 JAVA_TOOL_OPTIONS=-javaagent:/path/to/applicationinsights-agent.jar 的環境變數。

Spring Boot

如需詳細資訊,請參閱將 Azure 監視器 Application Insights 與 Spring Boot 搭配使用

Java 應用程式伺服器

如需設定 Application Insights Java 代理程式的相關資訊,請參閱啟用適用於 Java 的 Azure 監視器 OpenTelemetry。 下列各節提供在不同應用程式伺服器上設定 -javaagent:... JVM arg 時可能有幫助的詳細數據。

Tomcat 8 (Linux)

透過 apt-get 或 yum 安裝的 Tomcat

如果您是透過 apt-getyum 安裝 Tomcat 的,應該會有檔案 /etc/tomcat8/tomcat8.conf。 在該檔案的結尾新增以下這一行:

JAVA_OPTS="$JAVA_OPTS -javaagent:path/to/applicationinsights-agent-3.5.2.jar"

透過下載和解壓縮安裝的 Tomcat

如果您透過下載和解壓縮從 https://tomcat.apache.org 安裝 Tomcat,應該會有檔案 <tomcat>/bin/catalina.sh。 在相同的目錄中建立名為 <tomcat>/bin/setenv.sh、且含有下列內容的新檔案:

CATALINA_OPTS="$CATALINA_OPTS -javaagent:path/to/applicationinsights-agent-3.5.2.jar"

如果檔案 <tomcat>/bin/setenv.sh 已存在,請直接修改該檔案,並將 -javaagent:path/to/applicationinsights-agent-3.5.2.jar 新增至 CATALINA_OPTS

Tomcat 8 (Windows)

從命令列執行 Tomcat

找出 <tomcat>/bin/catalina.bat 檔案。 在相同的目錄中建立名為 <tomcat>/bin/setenv.bat、且含有下列內容的新檔案:

set CATALINA_OPTS=%CATALINA_OPTS% -javaagent:path/to/applicationinsights-agent-3.5.2.jar

不需要引號,但如果您想要包含引號,其適當的位置如下:

set "CATALINA_OPTS=%CATALINA_OPTS% -javaagent:path/to/applicationinsights-agent-3.5.2.jar"

如果檔案 <tomcat>/bin/setenv.bat 已存在,請直接修改該檔案,並將 -javaagent:path/to/applicationinsights-agent-3.5.2.jar 新增至 CATALINA_OPTS

以 Windows 服務的形式執行 Tomcat

找出 <tomcat>/bin/tomcat8w.exe 檔案。 執行該可執行檔,並將 -javaagent:path/to/applicationinsights-agent-3.5.2.jar 新增至 Java 索引標籤底下的 Java Options

JBoss 企業應用程式平臺 7

在 Red Hat JBoss Enterprise Application Platform (EAP) 7 中,您可以設定獨立伺服器或網域伺服器。

獨立伺服器

-javaagent:path/to/applicationinsights-agent-3.5.2.jar 新增至檔案 JBOSS_HOME/bin/standalone.conf (Linux) 或 JBOSS_HOME/bin/standalone.conf.bat (Windows) 中的現有 JAVA_OPTS 環境變數:

    JAVA_OPTS="-javaagent:path/to/applicationinsights-agent-3.5.2.jar -Xms1303m -Xmx1303m ..."
    ...

網域伺服器

-javaagent:path/to/applicationinsights-agent-3.5.2.jar 新增至 JBOSS_HOME/domain/configuration/host.xml 中的現有 jvm-options

...
<jvms>
    <jvm name="default">
        <heap size="64m" max-size="256m"/>
        <jvm-options>
            <option value="-server"/>
            <!--Add Java agent jar file here-->
            <option value="-javaagent:path/to/applicationinsights-agent-3.5.2.jar"/>
            <option value="-XX:MetaspaceSize=96m"/>
            <option value="-XX:MaxMetaspaceSize=256m"/>
        </jvm-options>
    </jvm>
</jvms>
...

如果您在單一主機上執行多個受管理伺服器,則必須針對每個 server將 新增applicationinsights.agent.idsystem-properties

...
<servers>
    <server name="server-one" group="main-server-group">
        <!--Edit system properties for server-one-->
        <system-properties> 
            <property name="applicationinsights.agent.id" value="..."/>
        </system-properties>
    </server>
    <server name="server-two" group="main-server-group">
        <socket-bindings port-offset="150"/>
        <!--Edit system properties for server-two-->
        <system-properties>
            <property name="applicationinsights.agent.id" value="..."/> 
        </system-properties>
    </server>
</servers>
...

指定的 applicationinsights.agent.id 值必須是唯一的。 您可以使用 值,在 Application Insights 目錄下建立子目錄。 每個 JVM 程式都需要本身的本地 Application Insights 設定和本地 Application Insights 記錄檔。 此外,如果向中央收集器報告,多個受管理伺服器會共用 applicationinsights.properties 檔案,因此需要指定的 applicationinsights.agent.id 來覆寫 agent.id 該共用檔案中的設定。 如果您需要覆寫個別受控伺服器的 agent.rollup.id 設定,可以在伺服器的 system-properties 中以類似方式指定 applicationinsights.agent.rollup.id

Jetty 9

將這幾行新增至 start.ini

--exec
-javaagent:path/to/applicationinsights-agent-3.5.2.jar

Payara 5

-javaagent:path/to/applicationinsights-agent-3.5.2.jar 新增至 glassfish/domains/domain1/config/domain.xml 中的現有 jvm-options

...
<java-config ...>
    <!--Edit the JVM options here-->
    <jvm-options>
        -javaagent:path/to/applicationinsights-agent-3.5.2.jar>
    </jvm-options>
        ...
</java-config>
...

WebSphere 8

  1. 開啟管理主控台。

  2. 移至 [伺服器]>[WebSphere 應用程式伺服器]>[應用程式伺服器]。 選擇適當的應用程式伺服器,然後選取 [Java 和進程管理>進程定義>Java 虛擬機]。

  3. 在 中 Generic JVM arguments,新增下列 JVM 自變數。

    -javaagent:path/to/applicationinsights-agent-3.5.2.jar
    
  4. 儲存並重新啟動應用程式伺服器。

OpenLiberty 18

在伺服器目錄 (例如 <openliberty>/usr/servers/defaultServer) 中建立新的檔案 jvm.options,並新增這一行:

-javaagent:path/to/applicationinsights-agent-3.5.2.jar

其他

請參閱您的應用程式伺服器文件,以了解如何新增 JVM 引數。