监视云存储应用程序并排查其问题Monitor and troubleshoot a cloud storage application

本教程是一个系列的第 4 部分,也是该系列的最后一部分。This tutorial is part four and the final part of a series. 本教程介绍如何监视云存储应用程序并排查其问题。You learn how to monitor and troubleshoot a cloud storage application.

该系列的第 4 部分中介绍了如何:In part four of the series, you learn how to:

  • 启用日志记录和指标Turn on logging and metrics
  • 启用授权错误警报Enable alerts for authorization errors
  • 使用错误的 SAS 令牌运行测试流量Run test traffic with incorrect SAS tokens
  • 下载和分析日志Download and analyze logs

Azure 存储分析为存储帐户提供日志记录和指标数据。Azure storage analytics provides logging and metric data for a storage account. 此数据提供对存储帐户运行状况的见解。This data provides insights into the health of your storage account. 若要从 Azure 存储分析收集数据,可以配置日志记录、指标和警报。To collect data from Azure storage analytics, you can configure logging, metrics and alerts. 此过程包括启用日志记录、配置指标和启用警报。This process involves turning on logging, configuring metrics, and enabling alerts.

可从 Azure 门户中的“诊断”选项卡启用日志记录和指标。Logging and metrics from storage accounts are enabled from the Diagnostics tab in the Azure portal. 存储日志记录可用于记录存储帐户中成功和失败请求的相关详细信息。Storage logging enables you to record details for both successful and failed requests in your storage account. 使用这些日志,可以查看针对 Azure 表、队列和 Blob 的读取、写入和删除操作的详细信息。These logs enable you to see details of read, write, and delete operations against your Azure tables, queues, and blobs. 它们还可用于查看失败请求的原因,如超时、限制和授权错误。They also enable you to see the reasons for failed requests such as timeouts, throttling, and authorization errors.

登录到 Azure 门户Log in to the Azure portal

登录到 Azure 门户Log in to the Azure portal

启用日志记录和指标Turn on logging and metrics

在左侧菜单中,依次选择“资源组”、“myResourceGroup”,然后在资源列表中选择存储帐户。From the left menu, select Resource Groups, select myResourceGroup, and then select your storage account in the resource list.

在“诊断设置(经典)”下,将“状态”设置为“开”。Under Diagnostics settings (classic) set Status to On. 确保“Blob 属性”下的所有选项均已启用。Ensure all of the options under Blob properties are enabled.

完成后,单击“保存”When complete, click Save

“诊断”窗格

启用警报Enable alerts

警报可提供一种方法,根据违反阈值的指标向管理员发送电子邮件或触发 Webhook。Alerts provide a way to email administrators or trigger a webhook based on a metric breaching a threshold. 此示例启用 SASClientOtherError 指标的警报。In this example, you enable an alert for the SASClientOtherError metric.

在“监视”部分下,选择“警报(经典)”。Under the Monitoring section, select Alerts (classic).

选择“添加指标警报(经典)”并通过填写必需的信息完成“添加规则”窗体。Select Add metric alert (classic) and complete the Add rule form by filling in the required information. 从“指标”下拉列表中,选择 SASClientOtherErrorFrom the Metric dropdown, select SASClientOtherError. 若要允许警报在出现第一个错误时触发,请从“条件”下拉列表中选择“大于或等于”。To allow your alert to trigger upon the first error, from the Condition dropdown select Greater than or equal to.

“诊断”窗格

模拟错误Simulate an error

要模拟一个有效的警报,可尝试从存储帐户中请求不存在的 blob。To simulate a valid alert, you can attempt to request a non-existent blob from your storage account. 下面的命令需要一个存储容器名称。The following command requires a storage container name. 对于此示例,可以使用现有容器的名称,也可以创建一个新容器。You can either use the name of an existing container or create a new one for the purposes of this example.

将占位符替换为实际值(确保将 <INCORRECT_BLOB_NAME> 设置为一个不存在的值)并运行该命令。Replace the placeholders with real values (make sure <INCORRECT_BLOB_NAME> is set to a value that does not exist) and run the command.

$sasToken=(az storage blob generate-sas \
    --account-name <STORAGE_ACCOUNT_NAME> \
    --account-key <STORAGE_ACCOUNT_KEY> \
    --container-name <CONTAINER_NAME> \
    --name <INCORRECT_BLOB_NAME> \
    --permissions r \
    --expiry `date --date="next day" +%Y-%m-%d`)

curl https://<STORAGE_ACCOUNT_NAME>.blob.core.chinacloudapi.cn/<CONTAINER_NAME>/<INCORRECT_BLOB_NAME>?$sasToken

下图的示例警报基于上述示例运行的模拟故障。The following image is an example alert that is based off the simulated failure ran with the preceding example.

示例警报

下载和查看日志Download and view logs

存储日志将数据存储在存储帐户下名为 $logs 的 blob 容器内的一组 blob 中。Storage logs store data in a set of blobs in a blob container named $logs in your storage account. 如果列出帐户中的所有 blob 容器,则不会显示该容器,但如果直接访问它,则可查看其内容。This container does not show up if you list all the blob containers in your account but you can see its contents if you access it directly.

后续步骤Next steps

在该系列的第 4 部分也是最后一部分中,可了解如何监视存储帐户并排查其问题,例如,如何:In part four and the final part of the series, you learned how to monitor and troubleshoot your storage account, such as how to:

  • 启用日志记录和指标Turn on logging and metrics
  • 启用授权错误警报Enable alerts for authorization errors
  • 使用错误的 SAS 令牌运行测试流量Run test traffic with incorrect SAS tokens
  • 下载和分析日志Download and analyze logs

请访问以下链接,查看预先生成的存储示例。Follow this link to see pre-built storage samples.