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

Azure 存储分析指标(经典)Azure Storage analytics metrics (Classic)

存储分析可存储一些度量值,这些度量值包括有关存储服务请求的聚合事务统计信息和容量数据。Storage Analytics can store metrics that include aggregated transaction statistics and capacity data about requests to a storage service. 在 API 操作级别以及存储服务级别报告事务,并在存储服务级别报告容量。Transactions are reported at both the API operation level as well as at the storage service level, and 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, and to improve the performance of applications that use a service.

默认为新存储帐户启用存储分析指标。Storage Analytics metrics are enabled by default for new storage accounts. 可以在Azure 门户中配置度量值;有关详细信息,请参阅在 Azure 门户中监视存储帐户You can configure metrics in the Azure portal; for details, 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.

备注

存储分析指标可用于 Blob、队列、表和文件服务。Storage Analytics metrics are available for the Blob, Queue, Table, and File services. 存储分析度量值现在是经典指标。Storage Analytics metrics are now Classic metrics. Microsoft 建议在 Azure Monitor 中使用存储度量值,而不是存储分析指标。Microsoft recommends using 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, including ingress/egress, availability, errors, and categorized request percentages. 可以在存储分析指标表架构主题中查看事务详细信息的完整列表。You can see a complete list of the transaction details in the Storage Analytics Metrics Table Schema topic.

在两个级别记录事务数据 – 服务级别和 API 操作级别。Transaction data is recorded at two levels – the service level and the API operation level. 在服务级别,汇总所有请求的 API 操作的统计信息将每小时写入一次表实体,即使未向服务发出请求也是如此。At the service level, statistics summarizing 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 will log the request and include it in the aggregated data for both the Blob service as well as the GetBlob operation. 但是,如果在一小时内未请求GetBlob操作,则不会将实体写入该操作的 $MetricsTransactionsBlobHowever, if no GetBlob operation is requested during the hour, an entity will not be written to the $MetricsTransactionsBlob for that operation.

为用户请求和存储分析本身发出的请求记录事务度量值。Transaction metrics are recorded for both 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 only available 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:

  • Capacity:存储帐户的 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 数量。ObjectCount: The number of committed and uncommitted block or page blobs in the storage account’s Blob service.

    有关容量指标的详细信息,请参阅存储分析指标表架构For more information about the 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 for transaction information, one table for minute transaction information, and another table for capacity information. 事务和分钟事务信息由请求和响应数据组成,而容量信息由存储使用情况数据组成。Transaction and minute transaction information consists of request and response data, and capacity information consists of storage usage data. 存储帐户的 Blob 服务的小时度量值、分钟度量值和容量可在按下表所述命名的表中访问。Hour metrics, minute metrics, and capacity for a storage account’s Blob service is can be 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-08-15 之前的版本。Versions prior to 2013-08-15 only. 虽然仍然支持这些名称,但还是建议改为使用下面列出的表。While these names are still supported, it’s recommended that you switch to using the tables listed below.
每小时度量值,主位置Hourly metrics, primary location -$MetricsHourPrimaryTransactionsBlob- $MetricsHourPrimaryTransactionsBlob
-$MetricsHourPrimaryTransactionsTable- $MetricsHourPrimaryTransactionsTable
-$MetricsHourPrimaryTransactionsQueue- $MetricsHourPrimaryTransactionsQueue
-$MetricsHourPrimaryTransactionsFile- $MetricsHourPrimaryTransactionsFile
所有版本。All versions. 仅在版本2015-04-05 及更高版本中提供对文件服务指标的支持。Support for File service metrics is available only in version 2015-04-05 and later.
分钟度量值,主位置Minute metrics, primary location -$MetricsMinutePrimaryTransactionsBlob- $MetricsMinutePrimaryTransactionsBlob
-$MetricsMinutePrimaryTransactionsTable- $MetricsMinutePrimaryTransactionsTable
-$MetricsMinutePrimaryTransactionsQueue- $MetricsMinutePrimaryTransactionsQueue
-$MetricsMinutePrimaryTransactionsFile- $MetricsMinutePrimaryTransactionsFile
所有版本。All versions. 仅在版本2015-04-05 及更高版本中提供对文件服务指标的支持。Support for File service metrics is available only in version 2015-04-05 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.windows.net/Tables("$MetricsTransactionsBlob")They are accessed via the namespace of the storage account, for example: https://<accountname>.table.core.windows.net/Tables("$MetricsTransactionsBlob"). 度量值表不会显示在列表操作中,必须直接通过表名进行访问。The metrics tables do not appear in a listing operation, and must be accessed directly via the table name.

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

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

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

Azure 门户目前不允许在存储帐户中配置分钟指标;必须通过 PowerShell 或编程方式启用分钟指标。The Azure portal does not currently enable you to configure minute metrics in your storage account; you must enable minute metrics using PowerShell or programmatically.

使用 PowerShell 启用存储度量值Enable Storage metrics using PowerShell

你可以使用本地计算机上的 PowerShell 在存储帐户中配置存储度量值,方法是使用 Azure PowerShell cmdlet AzStorageServiceMetricsProperty检索当前设置,并使用 cmdlet 设置-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, and the cmdlet Set-AzStorageServiceMetricsProperty to change the current settings.

控制存储度量值的 cmdlet 使用以下参数:The cmdlets that control Storage Metrics use the following parameters:

  • ServiceType,可能的值为Blob队列文件ServiceType, possible value are Blob, Queue, Table, and File.
  • MetricsType,可能的值为HourMinuteMetricsType, possible values are Hour and Minute.
  • MetricsLevel,可能的值为:MetricsLevel, possible values are:
  • :关闭监视。None: Turns off monitoring.
  • 服务:收集用于聚合 blob、队列、表和文件服务的入口/出口、可用性、延迟和成功百分比等指标。Service: Collects metrics such as ingress/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.

例如,以下命令在保留期设置为5天的情况下,在存储帐户中为 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 命令登录到 Azure 订阅。This command assumes that you've signed into your Azure subscription by using the Connect-AzAccount 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: How to 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 语言,则可以使用存储客户端库。For example, if you are using a .NET language you can use the Storage Client Library.

CloudBlobClientCloudQueueClientCloudTableClientCloudFileClient都具有一些方法,如都使用 setservicepropertiessetservicepropertiesasync 等方法,它们采用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 的存储客户端库For more information about using a .NET language to configure Storage Metrics, see Storage Client Library for .NET.

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

查看存储度量值Viewing 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 门户中的存储帐户。Navigate to your storage account in the Azure portal.
  2. 在要查看其指标的服务的 "菜单" 边栏选项卡中,选择 "指标(经典) "。Select Metrics (classic) in the Menu blade for the service whose metrics you want to view.
  3. 单击要配置的图表。Click the chart you want to configure.
  4. 在“编辑图表”边栏选项卡中,选择“时间范围”、“图表类型”,以及想要在图表中显示的指标。In the Edit Chart blade, select the Time Range, Chart type, and the metrics you want displayed in the chart.

在存储帐户的菜单边栏选项卡的 "监视(经典) " 部分 Azure 门户中,您可以配置警报规则,如发送电子邮件警报,以便在特定指标达到特定值时通知您。In the Monitoring (classic) section of your Storage account's menu blade in the Azure portal, you can configure Alert rules, such as sending 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 do not appear if you list all the tables in your storage account, but you can access them directly by name. 许多存储浏览工具都可以识别这些表,并允许你直接查看它们(有关可用工具的列表,请参阅Azure 存储客户端工具)。Many storage-browsing tools are aware of these tables and enable you to view them directly (see Azure Storage Client Tools for a list of available tools).

指标Metrics 表名称Table names 说明Notes
每小时度量值Hourly metrics $MetricsHourPrimaryTransactionsBlob$MetricsHourPrimaryTransactionsBlob

$MetricsHourPrimaryTransactionsTable$MetricsHourPrimaryTransactionsTable

$MetricsHourPrimaryTransactionsQueue$MetricsHourPrimaryTransactionsQueue

$MetricsHourPrimaryTransactionsFile$MetricsHourPrimaryTransactionsFile
在2013-08-15 之前的版本中,这些表被称为:In versions prior to 2013-08-15, these tables were known as:

$MetricsTransactionsBlob$MetricsTransactionsBlob

$MetricsTransactionsTable$MetricsTransactionsTable

$MetricsTransactionsQueue$MetricsTransactionsQueue

从版本2015-04-05 开始,可以使用文件服务的指标。Metrics for the File service are available beginning with version 2015-04-05.
分钟度量值Minute metrics $MetricsMinutePrimaryTransactionsBlob$MetricsMinutePrimaryTransactionsBlob

$MetricsMinutePrimaryTransactionsTable$MetricsMinutePrimaryTransactionsTable

$MetricsMinutePrimaryTransactionsQueue$MetricsMinutePrimaryTransactionsQueue

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

从版本2015-04-05 开始,可以使用文件服务的指标。Metrics for the File service are available beginning with version 2015-04-05.
CapacityCapacity $MetricsCapacityBlob$MetricsCapacityBlob 仅限 Blob 服务。Blob service only.

有关这些表的完整架构详细信息,请参阅 Storage Analytics Metrics Table Schema(存储分析度量值表架构)。You can find full details of the schemas for these tables at Storage Analytics Metrics Table Schema. 以下示例行仅显示一部分可用列,但也说明了存储度量值在采用相应方式保存这些度量值时展现的一些重要功能:The sample rows below show only a subset of the columns available, but 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.7650250 Z2014-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.7640250 Z2014-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.7650250 Z2014-05-22T11:01:16.7650250Z 1 1 538538 633633 100100 33 33 100100
20140522T110020140522T1100 user;UpdateEntityuser;UpdateEntity 2014-05-22T11:01: 16.7650250 Z2014-05-22T11:01:16.7650250Z 1 1 771771 217217 100100 99 66 100100

在这个分钟度量值数据示例中,分区键按分钟使用时间。In this example minute metrics data, the partition key uses the time at minute resolution. 行键可识别行中存储的信息的类型,其中包含两条信息,即访问类型和请求类型:The row key identifies the type of information that is stored in the row and this is composed of two pieces of information, the access type, and the request type:

  • 访问类型是usersystem,其中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.

  • 请求类型为 "所有",在这种情况下是摘要行,或标识特定 API,如QueryEntityUpdateEntityThe request type is either all in which case it is a summary line, or it identifies the specific API such as QueryEntity or UpdateEntity.

上面的示例数据显示一分钟(从11: 00 (开始)中的所有记录,因此QueryEntities请求数加上QueryEntity请求数加上UpdateEntity请求数,最多可添加7个,这是用户总数:全部行。The sample data above 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 add up to seven, which is the total shown on the user:All row. 同样,可以通过计算((143.8 * 5) + 3 + 9)/7 得出用户的平均端到端延迟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 门户中设置警报,以便自动通知你的存储服务行为的重要更改。You should consider setting up alerts in the Azure portal so you will 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 存储客户端工具See Azure Storage Client Tools for a list of available storage explorer tools. 可以在 "警报(经典) " 边栏选项卡中配置警报,可在 "存储帐户" 菜单边栏选项卡中的 "监视(经典) " 下访问You can configure alerts in the Alert (classic) blade, accessible under Monitoring (classic) in the Storage account menu blade.

重要

在存储事件与记录对应每小时或分钟度量数据的时间之间可能存在延迟。There may 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 may be written at once. 这可能会导致将前面几分钟的事务聚合到当前分钟的事务中。This can lead to transactions from earlier minutes being aggregated into the transaction for the current minute. 发生此情况时,警报服务可能没有已配置警报间隔内的所有可用度量数据,这可能会导致意外触发警报。When this happens, the alert service may not have all available metrics data for the configured alert interval, which may lead to alerts firing unexpectedly.

以编程方式访问度量值数据Accessing 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.

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 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 have configured a data retention policy, you are not charged when Azure Storage deletes old metrics data. 但是,如果删除分析数据,则会针对删除操作向帐户收费。However, if you delete analytics data, your account is charged for the delete operations.

度量值表使用的容量也会计费。The capacity used by the metrics tables is also billable. 你可以使用以下内容来估算用于存储度量值数据的容量:You can use the following to estimate the amount of capacity used for storing metrics data:

  • 如果服务每个服务使用每个服务中的每个 API,则每小时会将大约有148KB 的数据存储在指标事务表中,前提是启用了服务和 API 级摘要。If each hour a service utilizes every API in every service, then approximately 148KB of data is stored every hour in the metrics transaction tables if you have enabled both service- and API-level summary.
  • 如果在每个小时内,服务会利用服务中的每个 API,那么,如果你只启用了服务级别的摘要,则大约每小时会将大约有12KB 的数据存储在指标事务表中。If within each hour, a service utilizes every API in the service, then approximately 12KB of data is stored every hour in the metrics transaction tables if you have enabled just service-level summary.
  • Blob 的容量表每天添加两行,前提是已为日志选择加入。The capacity table for blobs has two rows added each day, provided you have opted-in for logs. 这意味着,此表的大小每天最多增加大约300个字节。This implies that every day, the size of this table increases by up to approximately 300 bytes.

后续步骤Next steps