您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

如何:在 Azure 应用服务中监视 Web 应用How to: Monitor Apps in Azure App Service

应用服务Azure 门户中提供了内置监视功能。App Service provides built in monitoring functionality in the Azure portal. 在 Azure 门户中,可以查看应用的配额指标以及应用服务计划、设置警报,甚至基于这些指标自动缩放The Azure portal includes the ability to review quotas and metrics for an app as well as the App Service plan, setting up alerts and even scaling automatically based on these metrics.

备注

尽管本文中指的是 Web 应用,但内容同样适用于 API 应用和移动应用。Although this article refers to web apps, it also applies to API apps and mobile apps.

了解配额和度量值Understanding Quotas and Metrics

配额Quotas

对于托管在应用服务中的应用程序,其可用资源受到某些限制Applications hosted in App Service are subject to certain limits on the resources they can use. 限制由与应用关联的应用服务计划定义。The limits are defined by the App Service plan associated with the app.

备注

应用服务免费和共享(预览)托管计划是基本层,与其他应用服务应用在相同的 Azure VM 上运行。App Service Free and Shared (preview) hosting plans are base tiers that run on the same Azure VM as other App Service apps. 某些应用可能属于其他客户。Some apps may belong to other customers. 这些层仅旨在用于开发和测试目的。These tiers are intended to be used only for development and testing purposes.

如果应用程序托管在免费共享计划中,则该应用可用资源的限制由配额定义。If the application is hosted in a Free or Shared plan, then the limits on the resources the app can use are defined by Quotas.

如果应用程序托管在基本标准高级计划中,则该应用可用资源的限制由应用服务计划大小(小、中、大)和实例计数(1、2、3...)设置。If the application is hosted in a Basic, Standard or Premium plan, then the limits on the resources they can use are set by the size (Small, Medium, Large) and instance count (1, 2, 3, ...) of the App Service plan.

免费共享应用的配额如下:Quotas for Free or Shared apps are:

  • CPU(短期)CPU(Short)
    • 5 分钟内允许此应用程序使用的 CPU 量。Amount of CPU allowed for this application in a 5-minute interval. 此配额每五分钟重置。This quota resets every five minutes.
  • CPU(天)CPU(Day)
    • 1 天内允许此应用程序使用的 CPU 总量。Total amount of CPU allowed for this application in a day. 此配额每隔 24 小时在 UTC 午夜时间重置。This quota resets every 24 hours at midnight UTC.
  • 内存Memory
    • 允许此应用程序具有的内存总量。Total amount of memory allowed for this application.
  • 带宽Bandwidth
    • 1 天内允许此应用程序传出的带宽总量。Total amount of outgoing bandwidth allowed for this application in a day. 此配额每隔 24 小时在 UTC 午夜时间重置。This quota resets every 24 hours at midnight UTC.
  • 文件系统Filesystem
    • 允许的存储空间总量。Total amount of storage allowed.

适用于托管在基本标准高级计划中的应用的唯一配额是文件系统The only quota applicable to apps hosted on Basic, Standard, and Premium plans is Filesystem.

有关各种应用服务 SKU 可用的特定配额、限制和功能的详细信息,请参阅:Azure 订阅服务限制More information about the specific quotas, limits, and features available to the different App Service SKUs can be found here: Azure Subscription Service Limits

配额强制执行Quota Enforcement

如果应用程序超过 CPU(短期)CPU(天)带宽配额,则将终止该应用程序,直到配额重置。If an application exceeds the CPU (short), CPU (Day), or bandwidth quota then the application is stopped until the quota resets. 在此期间,所有传入请求都将导致 HTTP 403During this time, all incoming requests result in an HTTP 403.

如果超过应用程序内存配额,则将重启该应用程序。If the application memory quota is exceeded, then the application is restarted.

如果超过文件系统配额,则任何写入操作都会失败,包括写入日志。If the Filesystem quota is exceeded, then any write operation fails, which includes any writes to logs.

可通过升级应用服务计划从应用中增加或删除配额。Quotas can be increased or removed from your app by upgrading your App Service plan.

度量值Metrics

度量值提供有关应用或应用服务计划行为的信息。Metrics provide information about the app, or App Service plan's behavior.

对于应用程序,可用度量值为:For an Application, the available metrics are:

  • 平均响应时间Average Response Time
    • 应用处理请求的平均时间(以毫秒为单位)。The average time taken for the app to serve requests in ms.
  • 平均内存工作集Average memory working set
    • 应用使用的平均内存量(以 MiB 为单位)。The average amount of memory in MiBs used by the app.
  • CPU 时间CPU Time
  • 数据输入Data In
    • 应用使用的传入带宽量(以 MiB 为单位)。The amount of incoming bandwidth consumed by the app in MiBs.
  • 数据输出Data Out
    • 应用使用的传出带宽量(以 MiB 为单位)。The amount of outgoing bandwidth consumed by the app in MiBs.
  • Http 2xxHttp 2xx
    • 导致 HTTP 状态代码的请求计数大于等于 200,但小于 300。Count of requests resulting in an HTTP status code >= 200 but < 300.
  • Http 3xxHttp 3xx
    • 导致 HTTP 状态代码的请求计数大于等于 300,但小于 400。Count of requests resulting in an HTTP status code >= 300 but < 400.
  • Http 401Http 401
    • 导致 HTTP 401 状态代码的请求计数。Count of requests resulting in HTTP 401 status code.
  • Http 403Http 403
    • 导致 HTTP 403 状态代码的请求计数。Count of requests resulting in HTTP 403 status code.
  • Http 404Http 404
    • 导致 HTTP 404 状态代码的请求计数。Count of requests resulting in HTTP 404 status code.
  • Http 406Http 406
    • 导致 HTTP 406 状态代码的请求计数。Count of requests resulting in HTTP 406 status code.
  • Http 4xxHttp 4xx
    • 导致 HTTP 状态代码的请求计数大于等于 400,但小于 500。Count of requests resulting in an HTTP status code >= 400 but < 500.
  • Http 服务器错误Http Server Errors
    • 导致 HTTP 状态代码的请求计数大于等于 500,但小于 600。Count of requests resulting in an HTTP status code >= 500 but < 600.
  • 内存工作集Memory working set
    • 应用当前使用的内存量(以 MiB 为单位)。Current amount of memory used by the app in MiBs.
  • 请求Requests
    • 请求总数(不考虑是否导致 HTTP 状态代码)。Total number of requests regardless of their resulting HTTP status code.

对于应用服务计划,可用度量值为:For an App Service plan, the available metrics are:

备注

应用服务计划指标仅适用于基本标准高级层中的计划。App Service plan metrics are only available for plans in Basic, Standard, and Premium tiers.

  • 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 application 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 and CPU percentage

CPU 时间对托管在免费共享计划中的应用很有用,因为这些应用的其中一个配额由应用所用的 CPU 时间定义。CPU Time is useful for apps hosted in Free or Shared plans since one of their quotas is defined in CPU minutes used by the app.

CPU 百分比适用于托管在基本标准高级计划中的应用,因为它们可横向缩放。CPU 百分比是所有实例中总用量的良好指标。CPU percentage is useful for apps hosted in basic, standard, and premium plans since they can be scaled out. CPU percentage is a good indication of the overall usage across all instances.

度量值粒度和保留策略Metrics Granularity and Retention Policy

应用程序和应用服务计划的度量值由具有下列粒度和保留策略的服务进行记录和聚合:Metrics for an application 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 门户中查看影响应用程序的各种配额指标You can review the status of the different quotas and metrics affecting an application in the Azure portal.

可以在“设置”>配额 下找到 配额 Quotas can be found under Settings>Quotas. 在 UX 中可以查看:(1) 配额名称、(2) 配额重置时间间隔、(3) 配额当前限制和 (4) 当前值。The UX allows you to review: (1) the quotas name, (2) its reset interval, (3) its current limit, and (4) current value.

可以直接从资源页访问 指标 Metrics can be accessed directly from the resource page. 还可以通过以下操作自定义图表:(1) 单击图表,并选择 (2)“编辑图表”。You can also customize the chart by: (1) click on it, and select (2) edit chart. 可在此处更改要显示的 (3) 时间范围、(4) 图表类型和 (5) 度量值From here you can change the (3) time range, (4) chart type, and (5) metrics to display.

可以在此处了解有关度量值的详细信息:监视服务度量值You can learn more about metrics here: Monitor service metrics.

警报和自动缩放Alerts and Autoscale

可将应用或应用服务计划的指标挂接到警报。Metrics for an App or App Service plan can be hooked up to alerts. 有关详细信息,请参阅接收警报通知To learn more about it, see Receive alert notifications.

托管在基本、标准或高级应用服务计划中的应用服务应用支持自动缩放App Service apps hosted in basic, standard, or premium App Service plans support autoscale. 使用自动缩放可以配置监视应用服务计划指标的规则。Autoscale allows you to configure rules that monitor the App Service plan metrics. 规则可以增加或减少实例计数,并根据需要提供更多的资源。Rules can increase or decrease the instance count providing additional resources as needed. 规则还有助于避免应用程序过度预配,从而节省资金。Rules can also help you save money when the application is over-provisioned. 可以在此处了解有关自动缩放的详细信息:如何缩放以及 Azure 监视器自动缩放的最佳做法You can learn more about auto scale here: How to Scale and here Best practices for Azure Monitor autoscaling

备注

如果要在注册 Azure 帐户之前开始使用 Azure 应用服务,请转到试用应用服务,可以在应用服务中立即创建一个生存期较短的入门 Web 应用。If you want to get started with Azure App Service before signing up for an Azure account, go to Try App Service, where you can immediately create a short-lived starter web app in App Service. 不需要使用信用卡,也不需要做出承诺。No credit cards required; no commitments.