Azure 存储分析指标(经典)Azure Storage Analytics metrics (classic)

Azure 存储使用存储分析解决方案存储一些指标,这些指标包括有关存储服务请求的聚合事务统计信息和容量数据。Azure Storage uses the Storage Analytics solution to store metrics that include aggregated transaction statistics and capacity data about requests to a storage service. 事务在 API 操作级别以及存储服务级别报告。Transactions are reported at the API operation level and at the storage service level. 容量在存储服务级别报告。Capacity is reported at the storage service level. 指标数据可用于:Metrics data can be used to:

  • 分析存储服务使用情况。Analyze storage service usage.
  • 通过针对存储服务发出的请求诊断问题。Diagnose issues with requests made against the storage service.
  • 提高使用服务的应用程序的性能。Improve the performance of applications that use a service.

默认为新存储帐户启用存储分析指标。Storage Analytics metrics are enabled by default for new storage accounts. 可以在 Azure 门户中配置指标。You can configure metrics in the Azure portal. 有关详细信息,请参阅在 Azure 门户中监视存储帐户For more information, see Monitor a storage account in the Azure portal. 还可以通过 REST API 或客户端库以编程方式启用存储分析。You can also enable Storage Analytics programmatically via the REST API or the client library. 使用“获取服务属性”操作为每项服务启用存储分析。Use the Set Service Properties operations to enable Storage Analytics for each service.

备注

存储分析指标可用于 Azure Blob 存储、Azure 队列存储、Azure 表存储以及 Azure 文件。Storage Analytics metrics are available for Azure Blob storage, Azure Queue storage, Azure Table storage, and Azure Files. 存储分析指标现在是经典指标。Storage Analytics metrics are now classic metrics. 建议你使用 Azure Monitor 中的存储指标,而不是存储分析指标。We recommend that you use storage metrics in Azure Monitor instead of Storage Analytics metrics.

事务指标Transaction metrics

对于每个存储服务和请求的 API 操作,将按小时或分钟为间隔记录一组可靠的数据,其中包括入口和出口、可用性、错误和分类请求百分比。A robust set of data is recorded at hourly or minute intervals for each storage service and requested API operation, which includes ingress and egress, availability, errors, and categorized request percentages. 有关事务详细信息的完整列表,请参阅存储分析指标表架构For a complete list of the transaction details, see Storage Analytics metrics table schema.

事务数据在服务级别和 API 操作级别记录。Transaction data is recorded at the service level and the API operation level. 在服务级别,汇总所有请求的 API 操作的统计信息将每小时写入一次表实体,即使未向服务发出请求也是如此。At the service level, statistics that summarize all requested API operations are written to a table entity every hour, even if no requests were made to the service. 在 API 操作级别,仅当在该小时内请求操作时才将统计信息写入实体。At the API operation level, statistics are only written to an entity if the operation was requested within that hour.

例如,如果对 Blob 服务执行 GetBlob 操作,则存储分析指标将记录请求并将其包含在 Blob 服务以及 GetBlob 操作的聚合数据中。For example, if you perform a GetBlob operation on your blob service, Storage Analytics Metrics logs the request and includes it in the aggregated data for the blob service and the GetBlob operation. 如果在一小时内未请求 GetBlob 操作,则不会将实体写入该操作的 $MetricsTransactionsBlob。If no GetBlob operation is requested during the hour, an entity isn't written to $MetricsTransactionsBlob for that operation.

会为用户请求和存储分析本身发出的请求记录事务指标。Transaction metrics are recorded for user requests and requests made by Storage Analytics itself. 例如,存储分析写入日志和表实体的请求会被记录。For example, requests by Storage Analytics to write logs and table entities are recorded.

容量度量值Capacity metrics

备注

目前,容量指标仅适用于 blob 服务。Currently, capacity metrics are available only for the blob service.

每天记录存储帐户的 Blob 服务的容量数据,并写入两个表实体。Capacity data is recorded daily for a storage account's blob service, and two table entities are written. 一个条目提供用户数据的统计信息,另一个条目提供有关存储分析所使用的 $logs Blob 容器的统计信息。One entity provides statistics for user data, and the other provides statistics about the $logs blob container used by Storage Analytics. $MetricsCapacityBlob 表包含以下统计信息:The $MetricsCapacityBlob table includes the following statistics:

  • 容量:存储帐户的 Blob 服务使用的存储量(以字节为单位)。Capacity: The amount of storage used by the storage account's blob service, in bytes.

  • ContainerCount:存储帐户的 Blob 服务中的 blob 容器数。ContainerCount: The number of blob containers in the storage account's blob service.

  • ObjectCount:存储帐户的 Blob 服务中已提交和未提交的块 blob 或页 blob 数量。ObjectCount: The number of committed and uncommitted block or page blobs in the storage account's blob service.

    有关容量指标的详细信息,请参阅存储分析指标表架构For more information about capacity metrics, see Storage Analytics metrics table schema.

如何存储指标How metrics are stored

每个存储服务的所有指标数据都存储在为该服务保留的三个表中。All metrics data for each of the storage services is stored in three tables reserved for that service. 一个表存储事务信息,一个表存储分钟事务信息,还有一个表存储容量信息。One table is for transaction information, one table is for minute transaction information, and another table is for capacity information. 事务和分钟事务信息由请求和响应数据组成。Transaction and minute transaction information consists of request and response data. 容量信息由存储使用情况数据组成。Capacity information consists of storage usage data. 存储帐户的 Blob 服务的小时指标、分钟指标和容量可在按下表所述命名的表中访问。Hour metrics, minute metrics, and capacity for a storage account's blob service is accessed in tables that are named as described in the following table.

指标级别Metrics level 表名Table names 支持的版本Supported for versions
小时指标,主位置Hourly metrics, primary location - $MetricsTransactionsBlob- $MetricsTransactionsBlob
- $MetricsTransactionsTable- $MetricsTransactionsTable
- $MetricsTransactionsQueue- $MetricsTransactionsQueue
仅 2013 年 8 月 15 日之前的版本。Versions prior to August 15, 2013, only. 虽然仍然支持这些名称,但还是建议改用下面列出的表。While these names are still supported, we recommend that you switch to using the tables that follow.
小时指标,主位置Hourly metrics, primary location - $MetricsHourPrimaryTransactionsBlob- $MetricsHourPrimaryTransactionsBlob
- $MetricsHourPrimaryTransactionsTable- $MetricsHourPrimaryTransactionsTable
- $MetricsHourPrimaryTransactionsQueue- $MetricsHourPrimaryTransactionsQueue
- $MetricsHourPrimaryTransactionsFile- $MetricsHourPrimaryTransactionsFile
所有版本。All versions. 仅在 2015 年 4 月 5 日版及更高版本中提供对文件服务指标的支持。Support for file service metrics is available only in version April 5, 2015, and later.
分钟指标,主位置Minute metrics, primary location - $MetricsMinutePrimaryTransactionsBlob- $MetricsMinutePrimaryTransactionsBlob
- $MetricsMinutePrimaryTransactionsTable- $MetricsMinutePrimaryTransactionsTable
- $MetricsMinutePrimaryTransactionsQueue- $MetricsMinutePrimaryTransactionsQueue
- $MetricsMinutePrimaryTransactionsFile- $MetricsMinutePrimaryTransactionsFile
所有版本。All versions. 仅在 2015 年 4 月 5 日版及更高版本中提供对文件服务指标的支持。Support for file service metrics is available only in version April 5, 2015, and later.
小时指标,辅助位置Hourly metrics, secondary location - $MetricsHourSecondaryTransactionsBlob- $MetricsHourSecondaryTransactionsBlob
- $MetricsHourSecondaryTransactionsTable- $MetricsHourSecondaryTransactionsTable
- $MetricsHourSecondaryTransactionsQueue- $MetricsHourSecondaryTransactionsQueue
所有版本。All versions. 必须启用读访问的地域冗余复制。Read-access geo-redundant replication must be enabled.
分钟指标,辅助位置Minute metrics, secondary location - $MetricsMinuteSecondaryTransactionsBlob- $MetricsMinuteSecondaryTransactionsBlob
- $MetricsMinuteSecondaryTransactionsTable- $MetricsMinuteSecondaryTransactionsTable
- $MetricsMinuteSecondaryTransactionsQueue- $MetricsMinuteSecondaryTransactionsQueue
所有版本。All versions. 必须启用读访问的地域冗余复制。Read-access geo-redundant replication must be enabled.
容量(仅限 Blob 服务)Capacity (blob service only) $MetricsCapacityBlob$MetricsCapacityBlob 所有版本。All versions.

为存储服务终结点启用存储分析时,会自动创建这些表。These tables are automatically created when Storage Analytics is enabled for a storage service endpoint. 这些指标可通过存储帐户的命名空间进行访问,例如:https://<accountname>.table.core.chinacloudapi.cn/Tables("$MetricsTransactionsBlob")They're accessed via the namespace of the storage account, for example, https://<accountname>.table.core.chinacloudapi.cn/Tables("$MetricsTransactionsBlob"). 指标表不会显示在列表操作中,必须直接通过表名称进行访问。The metrics tables don't appear in a listing operation and must be accessed directly via the table name.

使用 Azure 门户启用指标Enable metrics by using the Azure portal

请按照下列步骤在 Azure 门户中启用指标:Follow these steps to enable metrics in the Azure portal:

  1. 转到存储帐户。Go to your storage account.
  2. 在菜单窗格中选择“诊断设置(经典)”。Select Diagnostics settings (classic) in the menu pane.
  3. 确保“状态”设置为“打开”。Ensure that Status is set to On.
  4. 选择要监视的服务指标。Select the metrics for the services you want to monitor.
  5. 指定用来指示保留度量值和日志数据的时间长度的保留期策略。Specify a retention policy to indicate how long to retain metrics and log data.
  6. 选择“保存”。Select Save.

Azure 门户目前不允许你在存储帐户中配置分钟指标。The Azure portal doesn't currently enable you to configure minute metrics in your storage account. 必须使用 PowerShell 或以编程方式启用分钟指标。You must enable minute metrics by using PowerShell or programmatically.

使用 PowerShell 启用存储指标Enable storage metrics by using PowerShell

可以使用本地计算机上的 PowerShell 在存储帐户中配置存储指标,具体方法是:使用 Azure PowerShell cmdlet“Get-AzStorageServiceMetricsProperty” 检索当前设置。You can use PowerShell on your local machine to configure storage metrics in your storage account by using the Azure PowerShell cmdlet Get-AzStorageServiceMetricsProperty to retrieve the current settings. 使用 cmdlet“Set-AzStorageServiceMetricsProperty” 更改当前设置。Use the cmdlet Set-AzStorageServiceMetricsProperty to change the current settings.

控制存储指标的 cmdlet 使用以下参数:The cmdlets that control storage metrics use the following parameters:

  • ServiceType:可能值为 Blob、Queue、Table 和 File。ServiceType: Possible values are Blob, Queue, Table, and File.
  • MetricsType:可能值为 Hour 和 Minute。MetricsType: Possible values are Hour and Minute.
  • MetricsLevel:可能的值包括:MetricsLevel: Possible values are:
    • :禁用监视。None: Turns off monitoring.
    • 服务:收集经过汇总的有关 Blob、队列、表和文件服务的入口和出口、可用性、延迟及成功百分比等指标。Service: Collects metrics such as ingress and egress, availability, latency, and success percentages, which are aggregated for the blob, queue, table, and file services.
    • ServiceAndApi:除服务指标外,在 Azure 存储服务 API 中为每项存储操作收集一组相同的指标。ServiceAndApi: In addition to the service metrics, collects the same set of metrics for each storage operation in the Azure Storage service API.

例如,以下命令在存储帐户中打开 blob 服务的分钟指标,并将保留期设置为五天:For example, the following command switches on minute metrics for the blob service in your storage account with the retention period set to five days:

备注

此命令假定你已使用 Connect-AzAccount -Environment AzureChinaCloud 命令登录 Azure 订阅。This command assumes that you've signed into your Azure subscription by using the Connect-AzAccount -Environment AzureChinaCloud command.

$storageAccount = Get-AzStorageAccount -ResourceGroupName "<resource-group-name>" -AccountName "<storage-account-name>"

Set-AzStorageServiceMetricsProperty -MetricsType Minute -ServiceType Blob -MetricsLevel ServiceAndApi  -RetentionDays 5 -Context $storageAccount.Context
  • <resource-group-name> 占位符值替换为资源组的名称。Replace the <resource-group-name> placeholder value with the name of your resource group.
  • <storage-account-name> 占位符值替换为存储帐户的名称。Replace the <storage-account-name> placeholder value with the name of your storage account.

以下命令在默认存储帐户中为 Blob 服务检索当前的小时度量值级别和保留天数:The following command retrieves the current hourly metrics level and retention days for the blob service in your default storage account:

Get-AzStorageServiceMetricsProperty -MetricsType Hour -ServiceType Blob -Context $storagecontext.Context

若要了解如何配置 Azure PowerShell cmdlet 来使用 Azure 订阅并了解如何选择要使用的默认存储帐户,请参阅:安装和配置 Azure PowerShellFor information about how to configure the Azure PowerShell cmdlets to work with your Azure subscription and how to select the default storage account to use, see Install and configure Azure PowerShell.

以编程方式启用存储指标Enable storage metrics programmatically

除了使用 Azure 门户或 Azure PowerShell cmdlet 控制存储指标,你还可以使用 Azure 存储 API 之一。In addition to using the Azure portal or the Azure PowerShell cmdlets to control storage metrics, you can also use one of the Azure Storage APIs. 例如,如果你使用 .NET 语言,则可以使用 Azure 存储客户端库。For example, if you use a .NET language you can use the Azure Storage client library.

CloudBlobClient、CloudQueueClient、CloudTableClient 和 CloudFileClient 类都使用 SetServiceProperties 和 SetServicePropertiesAsync 等方法,这些方法采用 ServiceProperties 对象作为参数。The classes CloudBlobClient, CloudQueueClient, CloudTableClient, and CloudFileClient all have methods such as SetServiceProperties and SetServicePropertiesAsync that take a ServiceProperties object as a parameter. 你可以使用 ServiceProperties 对象配置存储指标。You can use the ServiceProperties object to configure storage metrics. 例如,下面的 C# 代码片段说明如何更改小时队列指标的指标级别和保留天数:For example, the following C# snippet shows how to change the metrics level and retention days for the hourly queue metrics:

var storageAccount = CloudStorageAccount.Parse(connStr);  
var queueClient = storageAccount.CreateCloudQueueClient();  
var serviceProperties = queueClient.GetServiceProperties();  

serviceProperties.HourMetrics.MetricsLevel = MetricsLevel.Service;  
serviceProperties.HourMetrics.RetentionDays = 10;  

queueClient.SetServiceProperties(serviceProperties);  

有关使用 .NET 语言配置存储指标的详细信息,请参阅用于 .NET 的 Azure 存储客户端库For more information about using a .NET language to configure storage metrics, see Azure Storage client libraries for .NET.

有关使用 REST API 配置存储指标的一般信息,请参阅启用和配置存储分析For general information about configuring storage metrics by using the REST API, see Enabling and configuring Storage Analytics.

查看存储指标View storage metrics

在将存储分析指标配置为监视存储帐户后,存储分析将使用存储帐户在一组已知表中记录指标。After you configure Storage Analytics metrics to monitor your storage account, Storage Analytics records the metrics in a set of well-known tables in your storage account. 可以将图表配置为每小时查看 Azure 门户中的指标:You can configure charts to view hourly metrics in the Azure portal:

  1. Azure 门户中转到自己的存储帐户。Go to your storage account in the Azure portal.
  2. 在要查看其指标的服务的“菜单”窗格中,选择“指标(经典)”。Select Metrics (classic) in the menu pane for the service whose metrics you want to view.
  3. 选择要配置的图表。Select the chart you want to configure.
  4. 在“编辑图表”窗格中,选择“时间范围”、“图表类型”,以及想要在图表中显示的指标。On the Edit Chart pane, select the Time range, the Chart type, and the metrics you want displayed in the chart.

在 Azure 门户的存储帐户菜单窗格的“监视(经典)”部分中,你可以配置警报规则In the Monitoring (classic) section of your storage account's menu pane in the Azure portal, you can configure Alert rules. 例如,你可以发送电子邮件警报,以在特定指标达到某值时通知你。For example, you can send email alerts to notify you when a specific metric reaches a certain value.

如果要为长期存储下载指标或在本地分析这些指标,则需要使用工具或编写一些代码来读取表。If you want to download the metrics for long-term storage or to analyze them locally, you must use a tool or write some code to read the tables. 必须下载分析用的分钟指标。You must download the minute metrics for analysis. 如果在存储帐户中列出所有表,则这些表不会显示,但可以按名称直接访问。The tables don't appear if you list all the tables in your storage account, but you can access them directly by name. 很多存储浏览工具可识别这些表,并可用于直接查看这些表。Many storage-browsing tools are aware of these tables and enable you to view them directly. 有关可用工具的列表,请参阅 Azure 存储客户端工具For a list of available tools, see Azure Storage client tools.

指标Metrics 表名Table names 备注Notes
小时指标Hourly metrics $MetricsHourPrimaryTransactionsBlob$MetricsHourPrimaryTransactionsBlob

$MetricsHourPrimaryTransactionsTable$MetricsHourPrimaryTransactionsTable

$MetricsHourPrimaryTransactionsQueue$MetricsHourPrimaryTransactionsQueue

$MetricsHourPrimaryTransactionsFile$MetricsHourPrimaryTransactionsFile
在 2013 年 8 月 15 日之前的版本中,这些表称为:In versions prior to August 15, 2013, these tables were known as:

$MetricsTransactionsBlob$MetricsTransactionsBlob

$MetricsTransactionsTable$MetricsTransactionsTable

$MetricsTransactionsQueue$MetricsTransactionsQueue

从 2015 年 4 月 5 日的版本开始,可以使用文件服务指标。Metrics for the file service are available beginning with version April 5, 2015.
分钟度量值Minute metrics $MetricsMinutePrimaryTransactionsBlob$MetricsMinutePrimaryTransactionsBlob

$MetricsMinutePrimaryTransactionsTable$MetricsMinutePrimaryTransactionsTable

$MetricsMinutePrimaryTransactionsQueue$MetricsMinutePrimaryTransactionsQueue

$MetricsMinutePrimaryTransactionsFile$MetricsMinutePrimaryTransactionsFile
只能通过 PowerShell 或以编程方式启用。Can only be enabled by using PowerShell or programmatically.

从 2015 年 4 月 5 日的版本开始,可以使用文件服务指标。Metrics for the file service are available beginning with version April 5, 2015.
容量Capacity $MetricsCapacityBlob$MetricsCapacityBlob 仅限 Blob 服务。Blob service only.

有关这些表的完整架构详细信息,请参阅存储分析指标表架构For full details of the schemas for these tables, see Storage Analytics metrics table schema. 以下示例行仅显示一部分可用列,但也说明了存储指标在采用相应方式保存这些指标时展现的一些重要功能:The following sample rows show only a subset of the columns available, but they illustrate some important features of the way storage metrics saves these metrics:

PartitionKeyPartitionKey RowKeyRowKey TimestampTimestamp TotalRequestsTotalRequests TotalBillableRequestsTotalBillableRequests TotalIngressTotalIngress TotalEgressTotalEgress 可用性Availability AverageE2ELatencyAverageE2ELatency AverageServerLatencyAverageServerLatency PercentSuccessPercentSuccess
20140522T110020140522T1100 user;Alluser;All 2014-05-22T11:01:16.7650250Z2014-05-22T11:01:16.7650250Z 77 77 40034003 4680146801 100100 104.4286104.4286 6.8571436.857143 100100
20140522T110020140522T1100 user;QueryEntitiesuser;QueryEntities 2014-05-22T11:01:16.7640250Z2014-05-22T11:01:16.7640250Z 55 55 26942694 4595145951 100100 143.8143.8 7.87.8 100100
20140522T110020140522T1100 user;QueryEntityuser;QueryEntity 2014-05-22T11:01:16.7650250Z2014-05-22T11:01:16.7650250Z 11 11 538538 633633 100100 33 33 100100
20140522T110020140522T1100 user;UpdateEntityuser;UpdateEntity 2014-05-22T11:01:16.7650250Z2014-05-22T11:01:16.7650250Z 11 11 771771 217217 100100 99 66 100100

在这个分钟指标数据示例中,分区键按分钟使用时间。In this example of minute metrics data, the partition key uses the time at minute resolution. 行键用于标识行中所存储信息的类型。The row key identifies the type of information that's stored in the row. 行键由访问类型和请求类型组成:The information is composed of the access type and the request type:

  • 访问类型是 user 或 system,其中 user 是指用户对存储服务发出的所有请求,而 system 是指存储分析发出的请求。The access type is either user or system, where user refers to all user requests to the storage service and system refers to requests made by Storage Analytics.
  • 请求类型是 all(在这种情况下是摘要行)或可识别特定 API,如 QueryEntity 或 UpdateEntity。The request type is either all, in which case it's a summary line, or it identifies the specific API such as QueryEntity or UpdateEntity.

此示例数据显示一分钟的所有记录(从上午 11:00 开始),因此,QueryEntities 请求数加 QueryEntity 请求数再加 UpdateEntity 请求数的和为 7。This sample data shows all the records for a single minute (starting at 11:00AM), so the number of QueryEntities requests plus the number of QueryEntity requests plus the number of UpdateEntity requests adds up to seven. 这是显示在 user:All 行上的总数。This total is shown in the user:All row. 同样,通过计算 ((143.8 * 5) + 3 + 9)/7,可以在 user:All 行得到平均端到端延迟为 104.4286。Similarly, you can derive the average end-to-end latency 104.4286 on the user:All row by calculating ((143.8 * 5) + 3 + 9)/7.

度量警报Metrics alerts

考虑在 Azure 门户中设置警报,以在存储服务行为发生重要更改时自动通知你。Consider setting up alerts in the Azure portal so you'll be automatically notified of important changes in the behavior of your storage services. 如果使用存储资源管理器工具下载这种采用分隔格式的指标数据,则可以使用 Microsoft Excel 分析数据。If you use a storage explorer tool to download this metrics data in a delimited format, you can use Microsoft Excel to analyze the data. 有关可用存储资源管理器工具的列表,请参阅 Azure 存储客户端工具For a list of available Storage Explorer tools, see Azure Storage client tools. 可以在“警报(经典)”窗格中(可在存储帐户菜单窗格中的“监视(经典)”下进行访问)配置警报。You can configure alerts in the Alert (classic) pane, which is accessible under Monitoring (classic) in the storage account menu pane.

重要

在存储事件与记录对应每小时或分钟指标数据的时间之间可能存在延迟。There might be a delay between a storage event and when the corresponding hourly or minute metrics data is recorded. 对于分钟指标,可能会一次写入几分钟的数据。In the case of minute metrics, several minutes of data might be written at once. 此问题可能会导致将前面几分钟的事务聚合到当前分钟的事务中。This issue can lead to transactions from earlier minutes being aggregated into the transaction for the current minute. 发生此问题时,警报服务可能没有已配置警报间隔内的所有可用指标数据,这可能会导致意外触发警报。When this issue happens, the alert service might not have all available metrics data for the configured alert interval, which might lead to alerts firing unexpectedly.

以编程方式访问指标数据Access metrics data programmatically

以下列表显示示例 C# 代码,该代码用于访问分钟范围的分钟指标,并在控制台窗口中显示结果。The following listing shows sample C# code that accesses the minute metrics for a range of minutes and displays the results in a console window. 代码示例使用 Azure 存储客户端库版本 4.x 或更高版本,其中包括 CloudAnalyticsClient 类,用于简化访问存储中的指标表的过程。The code sample uses the Azure Storage client library version 4.x or later, which includes the CloudAnalyticsClient class that simplifies accessing the metrics tables in storage.

备注

适用于 .NET 的 Azure Blob 存储客户端库 v12 中不包含 CloudAnalyticsClient 类。The CloudAnalyticsClient class is not included in the Azure Blob storage client library v12 for .NET. 存储分析指标(也称为经典指标)将于 2023 年 8 月 31 日停用。On August 31, 2023 Storage Analytics metrics, also referred to as classic metrics will be retired. 有关详细信息,请查看官方公告For more information, see the official announcement. 如果使用经典指标,建议你在该日期之前转换为 Azure Monitor 中的指标。If you use classic metrics, we recommend that you transition to metrics in Azure Monitor prior to that date.

private static void PrintMinuteMetrics(CloudAnalyticsClient analyticsClient, DateTimeOffset startDateTime, DateTimeOffset endDateTime)  
{  
 // Convert the dates to the format used in the PartitionKey.  
 var start = startDateTime.ToUniversalTime().ToString("yyyyMMdd'T'HHmm");  
 var end = endDateTime.ToUniversalTime().ToString("yyyyMMdd'T'HHmm");  

 var services = Enum.GetValues(typeof(StorageService));  
 foreach (StorageService service in services)  
 {  
     Console.WriteLine("Minute Metrics for Service {0} from {1} to {2} UTC", service, start, end);  
     var metricsQuery = analyticsClient.CreateMinuteMetricsQuery(service, StorageLocation.Primary);  
     var t = analyticsClient.GetMinuteMetricsTable(service);  
     var opContext = new OperationContext();  
     var query =  
             from entity in metricsQuery  
             // Note, you can't filter using the entity properties Time, AccessType, or TransactionType  
             // because they are calculated fields in the MetricsEntity class.  
             // The PartitionKey identifies the DataTime of the metrics.  
             where entity.PartitionKey.CompareTo(start) >= 0 && entity.PartitionKey.CompareTo(end) <= 0   
             select entity;  

     // Filter on "user" transactions after fetching the metrics from Azure Table storage.  
     // (StartsWith is not supported using LINQ with Azure Table storage.)  
     var results = query.ToList().Where(m => m.RowKey.StartsWith("user"));  
     var resultString = results.Aggregate(new StringBuilder(), (builder, metrics) => builder.AppendLine(MetricsString(metrics, opContext))).ToString();  
     Console.WriteLine(resultString);  
 }  
}  

private static string MetricsString(MetricsEntity entity, OperationContext opContext)  
{  
 var entityProperties = entity.WriteEntity(opContext);  
 var entityString =  
         string.Format("Time: {0}, ", entity.Time) +  
         string.Format("AccessType: {0}, ", entity.AccessType) +  
         string.Format("TransactionType: {0}, ", entity.TransactionType) +  
         string.Join(",", entityProperties.Select(e => new KeyValuePair<string, string>(e.Key.ToString(), e.Value.PropertyAsObject.ToString())));  
 return entityString;  
}  

对存储指标计费Billing on storage metrics

为度量值创建表实体的写入请求,按适用于所有 Azure 存储操作的标准费率收费。Write requests to create table entities for metrics are charged at the standard rates applicable to all Azure Storage operations.

客户端针对指标数据的读取和删除请求也按标准费率收费。Read and delete requests of metrics data by a client are also billable at standard rates. 如果已配置数据保留策略,则当 Azure 存储删除旧的指标数据时,不用付费。If you configured a data retention policy, you aren't charged when Azure Storage deletes old metrics data. 但是,如果删除分析数据,则会针对删除操作向帐户收费。If you delete analytics data, your account is charged for the delete operations.

指标表使用的容量也要付费。The capacity used by the metrics tables is also billable. 使用以下信息估算用于存储指标数据的容量:Use the following information to estimate the amount of capacity used for storing metrics data:

  • 如果某个服务每小时都会利用每个服务的每个 API,则在启用服务级别和 API 级别摘要的情况下,每小时约有 148KB 的数据存储在指标事务表中。If each hour a service utilizes every API in every service, approximately 148 KB of data is stored every hour in the metrics transaction tables if you enabled a service-level and API-level summary.
  • 如果某个服务每小时都会利用服务的每个 API,则在仅启用服务级别摘要的情况下,每小时约有 12KB 的数据存储在指标事务表中。If within each hour a service utilizes every API in the service, approximately 12 KB of data is stored every hour in the metrics transaction tables if you enabled only a service-level summary.
  • Blob 的容量表每天添加两行(如果你已为日志选择加入)。The capacity table for blobs has two rows added each day provided you opted in for logs. 这表示,此表的大小每天最多以约 300 字节的幅度增加。This scenario implies that every day the size of this table increases by up to approximately 300 bytes.

后续步骤Next steps