监视 Azure 存储Monitor Azure Storage

如果你有依赖 Azure 资源的关键应用程序和业务流程,则需要监视这些资源的可用性、性能和操作。When you have critical applications and business processes that rely on Azure resources, you want to monitor those resources for their availability, performance, and operation. 本文介绍 Azure 存储生成的监视数据,以及如何使用 Azure Monitor 的各种功能分析这些数据的相关警报。This article describes the monitoring data that's generated by Azure Storage and how you can use the features of Azure Monitor to analyze alerts on this data.

备注

Azure Monitor 中的 Azure 存储日志目前为公共预览版。Azure Storage logs in Azure Monitor is in public preview. 不支持经典存储帐户。Classic storage accounts are not supported.

Monitor 概述Monitor overview

每种存储资源的 Azure 门户“概述”页都包含资源使用情况(例如请求和每小时计费)的简要视图。The Overview page in the Azure portal for each storage resource includes a brief view of the resource usage, such as requests and hourly billing. 这些信息非常有用,但只提供少量监视数据。This information is useful, but only a small amount of the monitoring data is available. 其中的某些数据是自动收集的,并且在创建存储资源后即可用于分析。Some of this data is collected automatically and is available for analysis as soon as you create the storage resource. 你可以使用某些配置启用其他数据收集类型。You can enable additional types of data collection with some configuration.

说明是 Azure Monitor?What is Azure Monitor?

Azure 存储使用 Azure Monitor 来创建监视数据,Azure Monitor 是 Azure 中的一项完整堆栈监视服务。Azure Storage creates monitoring data by using Azure Monitor, which is a full stack monitoring service in Azure. Azure Monitor 提供了一整套用于监视 Azure 资源以及其他云和本地资源的功能。Azure Monitor provides a complete set of features to monitor your Azure resources and resources in other clouds and on-premises.

要详细了解 Azure Monitor,请参阅使用 Azure Monitor 监视 Azure 资源To learn more about Azure Monitor, see Monitoring Azure resources with Azure Monitor. 本文介绍了以下主题:The article describes the following subjects:

  • 说明是 Azure Monitor?What is Azure Monitor?
  • 与监视相关的成本Costs associated with monitoring
  • 监视 Azure 中收集的数据Monitoring data collected in Azure
  • 配置数据收集Configuring data collection
  • Azure 中用于分析监视数据并就其发出警报的标准工具Standard tools in Azure for analyzing and alerting on monitoring data

本文中的以下各部分将介绍从 Azure 存储收集的特定数据。The following sections build on this article by describing the specific data gathered from Azure Storage. 其中的示例演示了如何配置数据收集并通过 Azure 工具分析这些数据。Examples show how to configure data collection and analyze this data with Azure tools.

监视 Azure 存储中的数据Monitor data from Azure Storage

Azure 存储会收集与其他 Azure 资源类型相同的监视数据,如监视 Azure 资源中的数据中所述。Azure Storage collects the same kinds of monitoring data as other Azure resources, which are described in Monitoring data from Azure resources. 如需详细了解 Azure 存储创建的日志和指标,请参阅 Azure 存储监视数据参考For more information on the logs and metrics created by Azure Storage, see Azure Storage monitoring data reference.

Azure Monitor 中的指标和日志仅支持 Azure 资源管理器存储帐户。Metrics and logs in Azure Monitor support only Azure Resource Manager storage accounts. Azure Monitor 不支持经典存储帐户。Azure Monitor doesn't support classic storage accounts. 如果要使用经典存储帐户上的指标或日志,则需要迁移到 Azure 资源管理器存储帐户。If you want to use metrics or logs on a classic storage account, you need to migrate to an Azure Resource Manager storage account. 请参阅迁移到 Azure 资源管理器See Migrate to Azure Resource Manager.

如果需要,可以继续使用经典指标和日志。You can continue using classic metrics and logs if you want to. 实际上,经典指标和日志可与 Azure Monitor 中的指标和日志同时使用。In fact, classic metrics and logs are available in parallel with metrics and logs in Azure Monitor. 在 Azure 存储终止旧指标和日志的服务之前,支持范围保持不变。The support remains in place until Azure Storage ends the service on legacy metrics and logs.

Azure Monitor 中的日志(预览版)Logs in Azure Monitor (preview)

仅在针对服务终结点发出请求时才会创建日志条目。Log entries are created only if there are requests made against the service endpoint. 例如,如果存储帐户的 Blob 终结点中存在活动,而表或队列终结点中没有该活动,则仅创建与 Blob 服务有关的日志。For example, if a storage account has activity in its blob endpoint but not in its table or queue endpoints, only logs that pertain to the blob service are created. Azure 存储日志包含有关成功和失败的存储服务请求的详细信息。Azure Storage logs contain detailed information about successful and failed requests to a storage service. 可以使用该信息监视各个请求和诊断存储服务问题。This information can be used to monitor individual requests and to diagnose issues with a storage service. 将最大程度地记录请求。Requests are logged on a best-effort basis.

记录经过身份验证的请求Log authenticated requests

将记录以下类型的经过身份验证的请求:The following types of authenticated requests are logged:

  • 成功的请求Successful requests
  • 失败的请求,包括超时、限制、网络、授权和其他错误Failed requests, including timeout, throttling, network, authorization, and other errors
  • 使用共享访问签名 (SAS) 或 OAuth 的请求,包括失败和成功的请求Requests that use a shared access signature (SAS) or OAuth, including failed and successful requests
  • 对分析数据($logs 容器中的经典日志数据和 $metric 表中的类指标数据)的请求 Requests to analytics data (classic log data in the $logs container and class metric data in the $metric tables)

不会记录存储服务本身发出的请求,如创建或删除日志。Requests made by the storage service itself, such as log creation or deletion, aren't logged. 若要查看所记录数据的完整列表,请参阅存储记录的操作和状态消息存储日志格式For a full list of the logged data, see Storage logged operations and status messages and Storage log format.

记录匿名请求Log anonymous requests

记录以下类型的匿名请求:The following types of anonymous requests are logged:

  • 成功的请求Successful requests
  • 服务器错误Server errors
  • 客户端和服务器的超时错误Time-out errors for both client and server
  • 失败的 GET 请求,错误代码为 304(未修改)Failed GET requests with the error code 304 (Not Modified)

不会记录所有其他失败的匿名请求。All other failed anonymous requests aren't logged. 若要查看所记录数据的完整列表,请参阅存储记录的操作和状态消息存储日志格式For a full list of the logged data, see Storage logged operations and status messages and Storage log format.

配置Configuration

系统会自动收集平台指标和活动日志,但你需要创建诊断设置来收集资源日志,或将其转发到 Azure Monitor 之外。Platform metrics and the Activity log are collected automatically, but you must create a diagnostic setting to collect resource logs or forward them outside of Azure Monitor. 要了解使用 Azure 门户、Azure CLI 或 PowerShell 创建诊断设置的过程,请参阅创建诊断设置以收集 Azure 中的平台日志和指标For the process to create a diagnostic setting by using the Azure portal, the Azure CLI, or PowerShell, see Create diagnostic setting to collect platform logs and metrics in Azure.

创建诊断设置时,请选择要为其启用日志的存储类型,如 blob、队列、表或文件。When you create a diagnostic setting, choose the type of storage that you want to enable logs for, such as a blob, queue, table, or file. Data Lake Storage Gen2 不会显示为存储类型。Data Lake Storage Gen2 doesn't appear as a storage type. 这是因为 Data Lake Storage Gen2 是适用于 Blob 存储的一组功能。That's because Data Lake Storage Gen2 is a set of capabilities available to Blob storage.

如果在 Azure 门户中创建诊断设置,则可以从列表中选择资源。If you create the diagnostic setting in the Azure portal, you can select the resource from a list. 如果使用 PowerShell 或 Azure CLI,则需要使用存储类型的资源 ID。If you use PowerShell or the Azure CLI, you need to use the resource ID of the storage type. 通过打开存储帐户的“属性”页,可在 Azure 门户中找到资源 ID。You can find the resource ID in the Azure portal by opening the Properties page of your storage account.

此外,还必须指定要为其收集日志的操作的类别。You also have to specify the categories of operations for which you want to collect logs. 此表列出了 Azure 存储的类别。The categories for Azure Storage are listed in this table.

CategoryCategory 说明Description
StorageReadStorageRead 读取 blob 上的操作。Read operations on blobs.
StorageWriteStorageWrite 在 blob 上写入操作。Write operations on blobs.
StorageDeleteStorageDelete 对 blob 的删除操作。Delete operations on blobs.

分析指标数据Analyze metric data

你可以使用指标资源管理器通过其他 Azure 服务中的指标分析 Azure 存储的指标。You can analyze metrics for Azure Storage with metrics from other Azure services by using Metrics Explorer. 从 Azure Monitor 菜单中选择“指标”,可打开指标资源管理器 。Open Metrics Explorer by choosing Metrics from the Azure Monitor menu. 有关使用此工具的详细信息,请参阅 Azure 指标资源管理器入门For details on using this tool, see Getting started with Azure Metrics Explorer.

以下示例演示了如何查看帐户级别的事务。This example shows how to view Transactions at the account level.

在 Azure 门户中访问指标的屏幕截图

对于支持维度的指标,可使用所需的维度值筛选指标。For metrics that support dimensions, you can filter the metric with the desired dimension value. 以下示例演示了如何通过选择“API 名称”维度的值,在特定操作上查看帐户级别的“事务” 。This example shows how to view Transactions at the account level on a specific operation by selecting values for the API Name dimension.

在 Azure 门户中访问包含维度的指标的屏幕截图

有关 Azure 存储支持的维度的完整列表,请参阅指标维度For a complete list of the dimensions that Azure Storage supports, see Metrics dimensions.

Azure 存储的所有指标都位于以下命名空间中:All metrics for Azure Storage are located in these namespaces:

  • Microsoft.Storage/storageAccountsMicrosoft.Storage/storageAccounts
  • Microsoft.Storage/storageAccounts/blobServicesMicrosoft.Storage/storageAccounts/blobServices
  • Microsoft.Storage/storageAccounts/fileServicesMicrosoft.Storage/storageAccounts/fileServices
  • Microsoft.Storage/storageAccounts/queueServicesMicrosoft.Storage/storageAccounts/queueServices
  • Microsoft.Storage/storageAccounts/tableServicesMicrosoft.Storage/storageAccounts/tableServices

有关所有 Azure Monitor 支持指标(包括 Azure Storage)的列表,请参阅 Azure Monitor 支持的指标For a list of all Azure Monitor support metrics, which includes Azure Storage, see Azure Monitor supported metrics.

访问指标Access metrics

提示

若要查看 Azure CLI 或 .NET 示例,请选择此处列出的相应选项卡。To view Azure CLI or .NET examples, choose the corresponding tabs listed here.

列出指标定义List the metric definition

你可以列出存储帐户或单个存储服务(如 blob、文件、表或队列服务)的指标定义。You can list the metric definition of your storage account or the individual storage service, such as the blob, file, table, or queue service. 请使用 Get-AzMetricDefinition cmdlet。Use the Get-AzMetricDefinition cmdlet.

在此示例中,将 <resource-ID> 占位符替换为整个存储帐户的资源 ID 或单个存储服务(如 blob、文件、表或队列服务)的资源 ID。In this example, replace the <resource-ID> placeholder with the resource ID of the entire storage account or the resource ID of an individual storage service, such as the blob, file, table, or queue service. 你可以在 Azure 门户中存储帐户的“属性”页上找到这些资源 ID。You can find these resource IDs on the Properties pages of your storage account in the Azure portal.

   $resourceId = "<resource-ID>"
   Get-AzMetricDefinition -ResourceId $resourceId

读取指标值Read metric values

你可以读取存储帐户或单个存储服务(如 blob、文件、表或队列服务)的帐户级指标值。You can read account-level metric values of your storage account or the individual storage service, such as the blob, file, table, or queue service. 使用 Get-AzMetric cmdlet。Use the Get-AzMetric cmdlet.

   $resourceId = "<resource-ID>"
   Get-AzMetric -ResourceId $resourceId -MetricNames "UsedCapacity" -TimeGrain 01:00:00

分析日志数据Analyze log data

你可以将资源日志作为存储帐户中的 blob 以及事件数据进行访问,也可以通过 Log Analytics 查询访问资源日志。You can access resource logs either as a blob in a storage account, as event data, or through Log Analytic queries.

要详细了解这些日志中显示的字段的参考,请参阅 Azure 存储监视数据参考For a detailed reference of the fields that appear in these logs, see Azure Storage monitoring data reference.

备注

Azure Monitor 中的 Azure 存储日志目前为公共预览版。Azure Storage logs in Azure Monitor is in public preview. 不支持经典存储帐户。Classic storage accounts are not supported.

访问存储帐户中的日志Access logs in a storage account

日志显示为存储到目标存储帐户中的容器的 blob。Logs appear as blobs stored to a container in the target storage account. 数据作为按行分隔的 JSON 有效负载进行收集并存储在单个 blob 中。Data is collected and stored inside a single blob as a line-delimited JSON payload. Blob 的名称遵循以下命名约定:The name of the blob follows this naming convention:

https://<destination-storage-account>.blob.core.chinacloudapi.cn/insights-logs-<storage-operation>/resourceId=/subscriptions/<subscription-ID>/resourceGroups/<resource-group-name>/providers/Microsoft.Storage/storageAccounts/<source-storage-account>/blobServices/default/y=<year>/m=<month>/d=<day>/h=<hour>/m=<minute>/PT1H.json

下面是一个示例:Here's an example:

https://mylogstorageaccount.blob.core.chinacloudapi.cn/insights-logs-storagewrite/resourceId=/subscriptions/
208841be-a4v3-4234-9450-08b90c09f4/resourceGroups/myresourcegroup/providers/Microsoft.Storage/storageAccounts/mystorageaccount/blobServices/default/y=2019/m=07/d=30/h=23/m=12/PT1H.json

访问事件中心内的日志Access logs in an event hub

发送到事件中心的日志并没有存储为文件,但你可以验证事件中心是否收到了日志信息。Logs sent to an event hub aren't stored as a file, but you can verify that the event hub received the log information. 在 Azure 门户中,请转到事件中心,然后验证“传入消息”计数是否大于零。In the Azure portal, go to your event hub and verify that the incoming messages count is greater than zero.

审核日志

你可以使用安全信息和事件管理以及监视工具来访问和读取发送到事件中心的日志数据。You can access and read log data that's sent to your event hub by using security information and event management and monitoring tools. 有关详细信息,请参阅可对发送到事件中心的监视数据执行什么操作?For more information, see What can I do with the monitoring data being sent to my event hub?.

访问 Log Analytics 工作区中的日志Access logs in a Log Analytics workspace

你可以使用 Azure Monitor 日志查询来访问发送到 Log Analytics 工作区的日志。You can access logs sent to a Log Analytics workspace by using Azure Monitor log queries.

有关详细信息,请参阅 Azure Monitor 中的 Log Analytics 入门For more information, see Get started with Log Analytics in Azure Monitor.

数据存储在这些表中。Data is stored in these tables.

Table 说明Description
StorageBlobLogsStorageBlobLogs 描述 blob 存储中的活动的日志。Logs that describe activity in blob storage.
StorageFileLogsStorageFileLogs 描述文件共享中的活动的日志。Logs that describe activity in file shares.
StorageQueueLogsStorageQueueLogs 描述队列中的活动的日志。Logs that describe activity in queues.
StorageTableLogsStorageTableLogs 描述表中的活动的日志。Logs that describe activity in tables.

Data Lake Storage Gen2 的日志不会出现在专用表中。Logs for Data Lake Storage Gen2 do not appear in a dedicated table. 这是因为 Data Lake Storage Gen2 不是服务。That's because Data Lake Storage Gen2 is not service. 它是可以在 Blob 存储帐户上启用的一组功能。It's a set of capabilities that you can enable on a Blob storage account. 如果启用了这些功能,日志将继续出现在 StorageBlobLogs 表中。If you've enabled those capabilities, logs will continue to appear in the StorageBlobLogs table.

Azure Monitor 中的 Azure 存储日志分析查询Azure Storage Log Analytics queries in Azure Monitor

你可在“日志搜索”栏中输入下面这些查询,以帮助监视 Azure 存储帐户。Here are some queries that you can enter in the Log search bar to help you monitor your Azure Storage accounts. 这些查询使用新语言These queries work with the new language.

使用以下查询可帮助你监视 Azure 存储帐户:Use these queries to help you monitor your Azure Storage accounts:

  • 列出最近三天内 10 个最常见的错误。To list the 10 most common errors over the last three days.

    StorageBlobLogs
    | where TimeGenerated > ago(3d) and StatusText !contains "Success"
    | summarize count() by StatusText
    | top 10 by count_ desc
    
  • 列出最近三天内导致大部分错误的前 10 个操作。To list the top 10 operations that caused the most errors over the last three days.

    StorageBlobLogs
    | where TimeGenerated > ago(3d) and StatusText !contains "Success"
    | summarize count() by OperationName
    | top 10 by count_ desc
    
  • 列出最近三天内端到端延迟最长的前 10 个操作。To list the top 10 operations with the longest end-to-end latency over the last three days.

    StorageBlobLogs
    | where TimeGenerated > ago(3d)
    | top 10 by DurationMs desc
    | project TimeGenerated, OperationName, DurationMs, ServerLatencyMs, ClientLatencyMs = DurationMs - ServerLatencyMs
    
  • 列出最近三天内导致服务器端限制错误的所有操作。To list all operations that caused server-side throttling errors over the last three days.

    StorageBlobLogs
    | where TimeGenerated > ago(3d) and StatusText contains "ServerBusy"
    | project TimeGenerated, OperationName, StatusCode, StatusText
    
  • 列出最近三天内使用匿名访问的所有请求。To list all requests with anonymous access over the last three days.

    StorageBlobLogs
    | where TimeGenerated > ago(3d) and AuthenticationType == "Anonymous"
    | project TimeGenerated, OperationName, AuthenticationType, Uri
    
  • 创建最近三天内使用的操作的饼图。To create a pie chart of operations used over the last three days.

    StorageBlobLogs
    | where TimeGenerated > ago(3d)
    | summarize count() by OperationName
    | sort by count_ desc 
    | render piechart
    

常见问题FAQ

Azure 存储是否支持托管磁盘或非托管磁盘的指标?Does Azure Storage support metrics for Managed Disks or Unmanaged Disks?

否。No. Azure 计算支持磁盘上的指标。Azure Compute supports the metrics on disks. 有关详细信息,请参阅 托管和非托管磁盘的每个磁盘指标For more information, see Per disk metrics for Managed and Unmanaged Disks.

后续步骤Next steps