Share via


搭配 Azure Spring Apps 企業版方案使用應用程式即時檢視

注意

Azure Spring Apps 是 Azure Spring Cloud 服務的新名稱。 雖然服務有新的名稱,但是您暫時還是會在某些位置看到舊的名稱。我們正在致力更新螢幕擷取畫面、影片和圖表等資產。

本文適用於:❌ 基本/標準✔️企業

本文說明如何使用 VMware Tanzu 的應用程式即時檢視搭配 Azure Spring Apps 企業版方案。

VMware Tanzu 的應用程式即時檢視是輕量型深入解析和疑難解答工具,可協助應用程式開發人員和應用程式操作員查看執行中的應用程式。

應用程式實時檢視僅支援 Spring Boot 應用程式。

必要條件

  • Azure 訂用帳戶。 如果您沒有 Azure 訂用帳戶,請在開始前建立免費帳戶

  • 了解並滿足 Azure Marketplace 中企業方案的需求一節。

  • 具有 Azure Spring Apps 擴充功能的 Azure CLI 。 使用下列命令來移除舊版並安裝最新的擴充功能。 如果您先前已安裝擴充 spring-cloud 功能,請將其卸載,以避免設定和版本不符。

    az extension remove --name spring
    az extension add --name spring
    az extension remove --name spring-cloud
    

啟用應用程式實時檢視

您可以在布建 Azure Spring Apps 企業方案實例時啟用應用程式即時檢視。 如果您已經有已布建的 Azure Spring Apps Enterprise 資源,請參閱 本文現有企業方案實例 中的管理應用程式即時檢視一節。

您可以使用 Azure 入口網站 或 Azure CLI 來啟用應用程式即時檢視。

使用下列步驟,使用 Azure 入口網站 啟用應用程式實時檢視:

  1. 瀏覽至 Azure 入口網站

  2. 在 [ 基本] 索引 標籤上,選取 [定價中的企業層 ]、指定其他輸入欄位,然後選取 [ 下一步]。

  3. 在 [ VMware Tanzu 設定 ] 索引標籤上,選取 [ 啟用應用程式實時檢視]。

    VMware Tanzu 設定索引標籤的螢幕快照,其中已選取 [啟用應用程式實時檢視] 複選框。

  4. 指定其他設定,然後選取 [ 檢閱和建立]。

  5. 請確定 [檢閱和建立] 索引卷標上的 [啟用應用程式實時檢視] 和 [啟用開發人員工具入口網站] 設定為 [是],然後選取 [建立] 以建立企業方案實例。

監視應用程式即時檢視

Azure Spring Apps 會在連接器模式中執行應用程式即時檢視。

元件 描述
應用程式實時檢視伺服器 包含已註冊應用程式清單的中央伺服器元件。 應用程式即時檢視伺服器負責 Proxy 處理要求,以擷取與應用程式相關的執行器資訊。
應用程式即時檢視 連線 負責探索執行中應用程式的元件,並將實例註冊至應用程式即時檢視伺服器,以供觀察。 應用程式即時檢視 連線 or 也負責將執行器查詢 Proxy 至應用程式。

布建 Azure Spring Apps 企業版方案實例之後,您可以取得其執行中狀態和資源耗用量,或管理應用程式實時檢視。

您可以使用 Azure 入口網站 或 Azure CLI 監視應用程式實時檢視。

您可以在開發人員工具頁面的 [概觀] 索引標籤的 Azure 入口網站 [概觀] 索引標籤上,檢視應用程式即時檢視的狀態。

顯示 [開發人員工具] 頁面 [概觀] 索引標籤之 Azure 入口網站 的螢幕快照。

設定開發人員工具以存取應用程式實時檢視

若要存取應用程式即時檢視,您必須設定 Tanzu Dev Tools。 如需詳細資訊,請參閱 在 Azure Spring Apps 企業方案中設定 Tanzu Dev Tools。

使用應用程式即時檢視來監視您的應用程式

應用程式即時檢視可讓您檢視 Spring Boot 應用程式和 Spring Native 應用程式的即時計量。 應用程式實時檢視是以 Spring Boot 執行器的概念為基礎。

使用下列步驟來部署應用程式,並在應用程式即時檢視中監視它:

  1. 將下列相依性新增至應用程式的 pom.xml 檔案。

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
     </dependency>
    
  2. 將下列執行目標新增至 pom.xml 檔案中的 Maven 外掛程式,以公開組建資訊:

    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
        <goals>
            <goal>build-info</goal>
        </goals>
        <configuration>
            <additionalProperties>
            <spring.boot.version>${project.parent.version}</spring.boot.version>
            </additionalProperties>
        </configuration>
        </execution>
    </executions>
    </plugin>
    
  3. 在 application.properties新增下列組態,以啟用執行器端點:

    management.endpoints.web.exposure.include=info,health
    
  4. 使用下列命令在本機建置套件:

    mvn clean package -DskipTests
    
  5. 使用下列命令來部署二進位檔:

    az spring app create \
        --resource-group <resource-group-name> \
        --service <Azure-Spring-Apps-service-instance-name> \
        --name <app-name>
    az spring app deploy \
        --resource-group <resource-group-name> \
        --service <Azure-Spring-Apps-service-instance-name> \
        --name <app-name> \
        --artifact-path <jar-file-in-target-folder>
    
  6. 成功部署應用程式之後,您可以使用開發人員工具入口網站上的應用程式即時檢視儀錶板來監視應用程式。 如需詳細資訊,請參閱 依應用程式即時檢視監視應用程式。

    如果您已啟用 Dev Tools 入口網站並公開公用端點,請使用下列命令來取得開發人員工具入口網站儀錶板 URL。 新增後綴 /app-live-view 以撰寫端點以存取應用程式實時檢視。

    az spring dev-tool show --service <Azure-Spring-Apps-service-instance-name> \
        --resource-group <resource-group-name> \
        --query properties.url \
        --output tsv
    

    您也可以使用 Visual Studio Code 存取應用程式實時檢視(VS Code)。 如需詳細資訊,請參閱 本文的 VS Code 中使用應用程式即時檢視一節。

在現有的企業方案實例中管理應用程式實時檢視

您可以使用 Azure 入口網站 或 Azure CLI,在現有的 Azure Spring Apps Enterprise 方案實例中啟用應用程式實時檢視。

如果您已啟用開發人員工具入口網站並公開公用端點,請在啟用應用程式即時檢視之後,使用 Ctrl+F5 來停用瀏覽器快取。

使用下列步驟,使用 Azure 入口網站 管理應用程式實時檢視:

  1. 流覽至您的 Azure Spring Apps 服務實例,然後選取 [ 開發人員工具]。

  2. 選取 [ 管理工具]。

    顯示開發人員工具頁面之 Azure 入口網站的螢幕快照。

  3. 選取 [ 啟用應用程式實時檢視] 複選框,然後選取 [ 儲存]。

    Azure 入口網站 的螢幕快照,其中顯示 [開發人員工具] 區段的 [啟用應用程式實時檢視] 複選框。

  4. 然後,您可以在開發人員工具檢視應用程式即時檢視的狀態。

設定自定義的 Spring Boot 執行器

應用程式即時檢視可以透過預設執行器設定自動連線及監視 Spring boot 應用程式。 執行器端點的預設 HTTP 埠與應用程式的 HTTP 埠相同, /actuator 而且所有執行器端點都可透過具有後綴的應用程式預設內容路徑來存取。

如果應用程式自定義埠 (management.server.port=) 或內容路徑 (management.endpoints.web.base-path=/),應用程式即時檢視會停止連線並監視應用程式,並報告應用程式 404。 若要讓應用程式即時檢視繼續監視這類應用程式,請使用下列步驟來設定應用程式部署來自定義執行器端點。

使用下列步驟,使用 Azure 入口網站 來設定部署:

  1. 流覽至您的 Azure Spring Apps 服務實例,然後移至 [應用程式 ] 頁面並選取應用程式。

  2. 在瀏覽窗格中選取 [ 組態 ]。

  3. 在 [ 一般設定 ] 索引標籤上 ,更新 Spring Boot 執行器埠Spring Boot 執行器路徑 值,然後選取 [ 儲存]。

    顯示 [組態] 頁面的 Azure 入口網站 螢幕快照,其中已醒目提示 [儲存] 選項。

注意

您可以在應用程式或部署上設定此設定。 當您設定應用程式時,它實際上會對目前的使用中部署生效,但不會自動影響新的部署。

在 VS Code 中使用應用程式實時檢視

您可以直接在 VS Code 中存取應用程式即時檢視,以在 Azure Spring Apps 企業版方案中監視您的應用程式。

必要條件

檢視應用程式即時檢視儀錶板

使用下列步驟來檢視服務實例的應用程式即時檢視儀表板:

  1. 在 Visual Studio Code 中,開啟 Azure Spring Apps 擴充功能,然後登入您的 Azure 帳戶。

  2. 展開您想要監視的服務實例,然後按下滑鼠右鍵以選取服務實例。

  3. 從功能表中選取 [ 開啟應用程式實時檢視 ],以在預設瀏覽器中開啟 [應用程式實時檢視] 儀表板。

    VS Code 延伸模組的螢幕快照,其中顯示服務實例的 [開啟應用程式實時檢視] 選項。

檢視應用程式的 [應用程式實時檢視] 頁面

使用下列步驟來檢視應用程式的 [應用程式實時檢視] 頁面:

  1. 在 Visual Studio Code 中,開啟 Azure Spring Apps 擴充功能,然後登入您的 Azure 帳戶。

  2. 展開服務實例和您想要監視的應用程式。 以滑鼠右鍵按一下應用程式。

  3. 從功能表中選取 [ 開啟應用程式實時檢視 ],以在預設瀏覽器中開啟應用程式的 [應用程式即時檢視] 頁面。

    VS Code 延伸模組的螢幕快照,其中顯示應用程式的 [開啟應用程式實時檢視] 選項。

針對應用程式即時檢視問題進行疑難解答

如果您嘗試針對服務實例或未啟用應用程式即時檢視或公開公用端點的應用程式開啟應用程式即時檢視,您會看到錯誤訊息。

顯示未啟用應用程式即時檢視和無法存取公用端點的錯誤訊息螢幕快照。

若要啟用應用程式即時檢視並公開公用端點,請使用 Azure 入口網站 或 Azure CLI。 如需詳細資訊,請參閱 本文現有企業方案實例 中的管理應用程式實時檢視一節。

下一步