监视 Azure 应用服务中的应用Monitor apps in Azure App Service

应用服务针对 Azure 门户中的 Web 应用、移动后端和 API 应用提供内置监视功能。App Service provides built in monitoring functionality for web apps, mobile back ends, and API apps in the Azure Portal.

在 Azure 门户中,可以查看应用的配额和指标,查看应用服务计划,以及自动设置基于指标的警报和缩放。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

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

Note

应用服务免费和共享(预览)托管计划是基本层,与其他应用服务应用在相同的 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 app is hosted in a Free or Shared plan, the limits on the resources that the app can use are defined by quotas.

如果应用托管在“基本”、“标准”或“高级”计划中,则该应用可用资源的限制由应用服务计划的大小(小、中、大)和实例计数(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:

QuotaQuota 说明Description
CPU(短期)CPU (Short) 5 分钟间隔内允许此应用使用的 CPU 量。The amount of CPU allowed for this app in a 5-minute interval. 此配额每五分钟重置。This quota resets every five minutes.
CPU(天)CPU (Day) 一天内允许此应用使用的 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 一天内允许此应用使用的传出带宽总量。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.

有关各种应用服务 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.

可通过升级应用服务计划在应用中提高或删除配额。You can increase or remove quotas from your app by upgrading your App Service plan.

了解指标Understand metrics

指标提供有关应用或应用服务计划行为的信息。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.
第 0 代垃圾回收Gen 0 Garbage Collections 自应用进程启动以来对第 0 代对象进行垃圾回收的次数。The number of times the generation 0 objects are garbage collected since the start of the app process. 较高代系的垃圾回收包括所有较低代系的垃圾回收。Higher generation GCs include all lower generation GCs.
第 1 代垃圾回收Gen 1 Garbage Collections 自应用进程启动以来对第 1 代对象进行垃圾回收的次数。The number of times the generation 1 objects are garbage collected since the start of the app process. 较高代系的垃圾回收包括所有较低代系的垃圾回收。Higher generation GCs include all lower generation GCs.
第 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.

应用服务计划的可用指标包括:For an App Service plan, the available metrics are:

Note

应用服务计划指标仅适用于“基本”、“标准”和“高级”层中的计划。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

应用和应用服务计划的指标由具有下列粒度和保留策略的服务进行记录和聚合: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

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

托管在“基本”、“标准”或“高级”应用服务计划中的应用服务应用支持自动缩放。App Service apps hosted in Basic, Standard, or Premium App Service plans support autoscale. 使用自动缩放可以配置用于监视应用服务计划指标的规则。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 Monitor 自动缩放的最佳做法For more information about autoscale, see How to scale and Best practices for Azure Monitor autoscaling.