監視 Azure App Service 中的應用程式Monitor apps in Azure App Service

Azure App Service 會在 Azure 入口網站中為 Web 應用程式、行動後端和 API 應用程式提供內建的監視功能。Azure App Service provides built-in monitoring functionality for web apps, mobile back ends, and API apps in the Azure portal.

在 Azure 入口網站中,您可以檢閱應用程式的「配額」和「計量」、檢閱 App Service 方案,並自動根據計量來設定「警示」警示和「規模調整」。In the Azure portal, you can review quotas and metrics for an app, review the App Service plan, and automatically set up alerts and scaling that are based on the metrics.

了解配額Understand quotas

App Service 中裝載的應用程式都必須遵守其可用資源的某些「限制」。Apps that are hosted in App Service are subject to certain limits on the resources they can use. 限制是由與應用程式相關聯的 App Service 方案所定義。The limits are defined by the App Service plan that's associated with the app.

注意

App Service 的免費和共用 (預覽) 主控方案均為基本層,在與其他 App Service 應用程式相同的 Azure 虛擬機器上執行。App Service Free and Shared (preview) hosting plans are base tiers that run on the same Azure virtual machines as other App Service apps. 某些應用程式可能屬於其他客戶。Some apps might belong to other customers. 這些層僅用於開發與測試。These tiers are intended to be used only for development and testing purposes.

如果應用程式裝載於「免費」或「共用」方案中,則應用程式可用資源的限制是由配額所定義。If the app is hosted in a Free or Shared plan, the limits on the resources that the app can use are defined by quotas.

如果應用程式裝載於「基本」、「標準」或「進階」方案中,則其可用資源的限制是由 App Service 方案的大小 (小、中、大) 和執行個體計數 (1、2、3,以此類推) 所設定。If the app is hosted in a Basic, Standard, or Premium plan, the limits on the resources that they can use are set by the size (Small, Medium, Large) and instance count (1, 2, 3, and so on) of the App Service plan.

免費或共用應用程式的配額如下︰Quotas for Free or Shared apps are:

配額Quota 描述Description
CPU (短期)CPU (Short) 此應用程式在 5 分鐘間隔內允許的 CPU 數量。The amount of CPU allowed for this app in a 5-minute interval. 此配額會每 5 分鐘重設一次。This quota resets every five minutes.
CPU (天)CPU (Day) 此應用程式在 1 天內允許的 CPU 總量。The total amount of CPU allowed for this app in a day. 此配額會每隔 24 小時在午夜 (UTC) 重設一次。This quota resets every 24 hours at midnight UTC.
記憶體Memory 此應用程式允許的記憶體總量。The total amount of memory allowed for this app.
頻寬Bandwidth 此應用程式在 1 天內允許的連出頻寬總量。The total amount of outgoing bandwidth allowed for this app in a day. 此配額會每隔 24 小時在午夜 (UTC) 重設一次。This quota resets every 24 hours at midnight UTC.
FilesystemFilesystem 允許的儲存體總量。The total amount of storage allowed.

對於裝載於基本、標準和進階方案上的應用程式,唯一適用的配額是「檔案系統」。The only quota applicable to apps that are hosted in Basic, Standard, and Premium plans is Filesystem.

如需有關不同 App Service SKU 可用特定配額、限制和功能的詳細資訊,請參閱 Azure 訂用帳戶服務限制For more information about the specific quotas, limits, and features available to the various App Service SKUs, see Azure Subscription service limits.

強制配額Quota enforcement

如果應用程式超過 CPU (短期)、CPU (天) 或頻寬配額,則應用程式會停止,直到重設配額為止。If an app exceeds the CPU (short), CPU (Day), or bandwidth quota, the app is stopped until the quota resets. 在此期間,所有連入要求都會導致 HTTP 403 錯誤。During this time, all incoming requests result in an HTTP 403 error.

403 錯誤訊息

如果超出應用程式的記憶體配額,則應用程式會重新啟動。If the app Memory quota is exceeded, the app is restarted.

如果超過檔案系統配額時,任何寫入作業都將會失敗。If the Filesystem quota is exceeded, any write operation fails. 寫入作業失敗包括記錄的任何寫入。Write operation failures include any writes to logs.

升級您的 App Service 方案,即可在應用程式中增加或移除配額。You can increase or remove quotas from your app by upgrading your App Service plan.

了解計量Understand metrics

計量提供有關應用程式或 App Service 方案行為的資訊。Metrics provide information about the app or the App Service plan's behavior.

若為應用程式,可用的計量如下︰For an app, the available metrics are:

度量Metric 描述Description
平均回應時間Average Response Time 應用程式處理要求所花費的平均時間 (以毫秒為單位)。The average time taken for the app to serve requests, in milliseconds.
平均記憶體工作集Average memory working set 應用程式使用的平均記憶體數量 (以 MiB 為單位)。The average amount of memory used by the app, in megabytes (MiB).
連線Connections 存在於沙箱 (w3wp.exe 及其子處理序) 中的已繫結通訊端數目。The number of bound sockets existing in the sandbox (w3wp.exe and its child processes). 建立已繫結通訊端時,會透過呼叫 bind()/connect() API 來建立,然後保留直到使用 CloseHandle()/closesocket() 來關閉上述通訊端為止。A bound socket is created by calling bind()/connect() APIs and remains until said socket is closed with CloseHandle()/closesocket().
CPU 時間CPU Time 應用程式所耗用的 CPU 數量 (以秒為單位)。The amount of CPU consumed by the app, in seconds. 如需此計量的詳細資訊,請參閱 CPU 時間與 CPU 百分比For more information about this metric, see CPU time vs CPU percentage.
目前的組件Current Assemblies 在此應用程式的所有 AppDomain 載入的目前組件數目。The current number of Assemblies loaded across all AppDomains in this application.
資料輸入Data In 應用程式所耗用的連入頻寬量 (MiB)。The amount of incoming bandwidth consumed by the app, in MiB.
資料輸出Data Out 應用程式所耗用的連出頻寬量 (MiB)。The amount of outgoing bandwidth consumed by the app, in MiB.
Gen 0 記憶體回收Gen 0 Garbage Collections 自應用程式處理序啟動後,對層代 0 物件進行記憶體回收的次數。The number of times the generation 0 objects are garbage collected since the start of the app process. 較高層代的 GC 包含所有較低層代的 GC。Higher generation GCs include all lower generation GCs.
Gen 1 記憶體回收Gen 1 Garbage Collections 自應用程式處理序啟動後,對層代 1 物件進行記憶體回收的次數。The number of times the generation 1 objects are garbage collected since the start of the app process. 較高層代的 GC 包含所有較低層代的 GC。Higher generation GCs include all lower generation GCs.
Gen 2 記憶體回收Gen 2 Garbage Collections 自應用程式處理序啟動後,對層代 2 物件進行記憶體回收的次數。The number of times the generation 2 objects are garbage collected since the start of the app process.
控制代碼計數Handle Count 應用程式處理序目前開啟的控制代碼總數。The total number of handles currently open by the app process.
Http 2xxHttp 2xx 導致 HTTP 狀態碼 >= 200 但 < 300 的要求計數。The count of requests resulting in an HTTP status code ≥ 200 but < 300.
Http 3xxHttp 3xx 導致 HTTP 狀態碼 >= 300 但 < 400 的要求計數。The count of requests resulting in an HTTP status code ≥ 300 but < 400.
Http 401Http 401 導致 HTTP 401 狀態碼的要求計數。The count of requests resulting in HTTP 401 status code.
Http 403Http 403 導致 HTTP 403 狀態碼的要求計數。The count of requests resulting in HTTP 403 status code.
Http 404Http 404 導致 HTTP 404 狀態碼的要求計數。The count of requests resulting in HTTP 404 status code.
Http 406Http 406 導致 HTTP 406 狀態碼的要求計數。The count of requests resulting in HTTP 406 status code.
Http 4xxHttp 4xx 導致 HTTP 狀態碼 >= 400 但 < 500 的要求計數。The count of requests resulting in an HTTP status code ≥ 400 but < 500.
Http 伺服器錯誤Http Server Errors 導致 HTTP 狀態碼 >= 500 但 < 600 的要求計數。The count of requests resulting in an HTTP status code ≥ 500 but < 600.
每秒的 IO 其他位元組數IO Other Bytes Per Second 應用程式處理序對不涉及資料的 I/O 作業 (例如控制作業) 發出位元組的速率。The rate at which the app process is issuing bytes to I/O operations that do not involve data, such as control operations.
每秒的 IO 其他作業數IO Other Operations Per Second 應用程式處理序發出既非讀取也非寫入作業之 I/O 作業的速率。The rate at which the app process is issuing I/O operations that are neither read nor write operations.
每秒 IO 讀取位元組數IO Read Bytes Per Second 應用程式處理序從 I/O 作業讀取位元組的速率。The rate at which the app process is reading bytes from I/O operations.
每秒 IO 讀取作業數IO Read Operations Per Second 應用程式處理序發出讀取 I/O 作業的速率。The rate at which the app process is issuing read I/O operations.
每秒 IO 寫入位元組數IO Write Bytes Per Second 應用程式處理序將位元組寫入至 I/O 作業的速率。The rate at which the app process is writing bytes to I/O operations.
每秒 IO 寫入作業數IO Write Operations Per Second 應用程式處理序發出寫入 I/O 作業的速率。The rate at which the app process is issuing write I/O operations.
記憶體工作集Memory working set 應用程式目前使用的記憶體數量 (MiB)。The current amount of memory used by the app, in MiB.
私用位元組Private Bytes 「私用位元組」是應用程式處理序已配置但無法與其他處理序共用的目前記憶體大小 (以位元組為單位)。Private Bytes is the current size, in bytes, of memory that the app process has allocated that cannot be shared with other processes.
要求Requests 要求總數 (不論其導致的 HTTP 狀態碼為何)。The total number of requests regardless of their resulting HTTP status code.
應用程式佇列中的要求數Requests In Application Queue 應用程式要求佇列中的要求數目。The number of requests in the application request queue.
執行緒計數Thread Count 應用程式處理序中目前作用中的執行緒數目。The number of threads currently active in the app process.
應用程式網域數總計Total App Domains 在此應用程式中載入的目前 AppDomain 數目。The current number of AppDomains loaded in this application.
已卸載的應用程式網域總計Total App Domains Unloaded 自應用程式啟動後,已卸載的 AppDomain 總數。The total number of AppDomains unloaded since the start of the application.

若為 App Service 方案,可用的計量如下︰For an App Service plan, the available metrics are:

注意

App Service 方案計量只適用於基本、標準和進階層中的方案。App Service plan metrics are available only for plans in Basic, Standard, and Premium tiers.

度量Metric 描述Description
CPU 百分比CPU Percentage 方案的所有執行個體使用的平均 CPU。The average CPU used across all instances of the plan.
記憶體百分比Memory Percentage 方案的所有執行個體使用的平均記憶體。The average memory used across all instances of the plan.
資料輸入Data In 方案的所有執行個體使用的平均連入頻寬。The average incoming bandwidth used across all instances of the plan.
資料輸出Data Out 方案的所有執行個體使用的平均連出頻寬。The average outgoing bandwidth used across all instances of the plan.
磁碟佇列長度Disk Queue Length 儲存體上已排入佇列的平均讀取和寫入要求數目。The average number of both read and write requests that were queued on storage. 磁碟佇列長度很大表示應用程式可能因為過度的磁碟 I/O 而變慢。A high disk queue length is an indication of an app that might be slowing down due to excessive disk I/O.
Http 佇列長度Http Queue Length 必須在履行前排入佇列的平均 HTTP 要求數目。The average number of HTTP requests that had to sit on the queue before being fulfilled. HTTP 佇列長度很大或不斷增加是方案負載過重的徵兆。A high or increasing HTTP Queue length is a symptom of a plan under heavy load.

CPU 時間與 CPU 百分比CPU time vs CPU percentage

有兩個計量可反映 CPU 使用量:There are two metrics that reflect CPU usage:

CPU 時間:很適合用於免費或共用方案中裝載的應用程式,因為其中有一個配額是以應用程式使用的 CPU 分鐘數來定義。CPU Time: Useful for apps hosted in Free or Shared plans, because one of their quotas is defined in CPU minutes used by the app.

CPU 百分比:很適合用於基本、標準和進階方案中裝載的應用程式,因為這些方案能夠相應放大。CPU 百分比可清楚指出所有執行個體的整體使用量。CPU percentage: Useful for apps hosted in Basic, Standard, and Premium plans, because they can be scaled out. CPU percentage is a good indication of the overall usage across all instances.

計量資料細微性和保留原則Metrics granularity and retention policy

服務會記錄和彙總應用程式和 App Service 方案的計量,其資料細微性和保留原則如下︰Metrics for an app and app service plan are logged and aggregated by the service, with the following granularities and retention policies:

  • 分鐘資料細微性計量會保留 30 小時。Minute granularity metrics are retained for 30 hours.
  • 小時資料細微性計量會保留 30 天。Hour granularity metrics are retained for 30 days.
  • 資料細微性度量會保留 30 天。Day granularity metrics are retained for 30 days.

在 Azure 入口網站中監視配額和計量Monitoring quotas and metrics in the Azure portal

若要檢閱影響應用程式的各種配額和計量狀態,請前往 Azure 入口網站To review the status of the various quotas and metrics that affect an app, go to the Azure portal.

Azure 入口網站中的配額圖表

若要尋找配額,請選取 [設定] > [配額]。To find quotas, select Settings > Quotas. 在圖表上,您可以檢閱:On the chart, you can review:

  1. 配額名稱。The quota name.
  2. 重設間隔。Its reset interval.
  3. 目前限制。Its current limit.
  4. 目前的值。Its current value.

Azure 入口網站中的計量圖表您可以直接從資源頁面存取計量。Metric chart in the Azure portal You can access metrics directly from the Resource page. 自訂圖表:To customize the chart:

  1. 選取圖表。Select the chart.
  2. 選取 [編輯圖表]。Select Edit chart.
  3. 編輯 [時間範圍]。Edit the Time Range.
  4. 編輯 [圖表類型]。Edit the Chart type.
  5. 編輯您想要顯示的計量。Edit the metrics you want to display.

若要進一步了解計量,請參閱監視服務計量To learn more about metrics, see Monitor service metrics.

警示和自動調整Alerts and autoscale

應用程式或 App Service 方案的計量可以連接到警示。Metrics for an app or an App Service plan can be hooked up to alerts. 如需詳細資訊,請參閱接收警示通知For more information, see Receive alert notifications.

基本、標準或進階 App Service 方案中裝載的 App Service 應用程式支援自動調整。App Service apps hosted in Basic, Standard, or Premium App Service plans support autoscale. 自動調整可讓您設定用以監視 App Service 方案計量的規則。With autoscale, you can configure rules that monitor the App Service plan metrics. 這些規則可以增加或減少執行個體計數,並視需要提供其他資源。Rules can increase or decrease the instance count, which can provide additional resources as needed. 當應用程式過度佈建時,這些規則也可協助您節省成本。Rules can also help you save money when the app is over-provisioned.

如需詳細資訊,請參閱如何調整Azure 監視器自動調整的最佳做法For more information about autoscale, see How to scale and Best practices for Azure Monitor autoscaling.