监视媒体服务诊断日志Monitor Media Services diagnostic logs

媒体服务徽标 v3media services logo v3


备注

Google Widevine 内容保护服务目前在 Azure 中国区域不可用。Google Widevine content protection services are currently unavailable in the Azure China regions.

可以通过 Azure Monitor 监视指标和诊断日志,以便了解应用程序的执行情况。Azure Monitor enables you to monitor metrics and diagnostic logs that help you understand how your applications are performing. 有关此功能的详细说明以及使用 Azure 媒体服务指标和诊断日志的原因,请参阅监视媒体服务指标和诊断日志For detailed description of this feature and to see why you would want to use Azure Media Services metrics and diagnostics logs, see Monitor Media Services metrics and diagnostic logs.

本文介绍如何将数据路由到存储帐户并查看数据。This article shows you how to route data to the storage account and then view the data.

必备条件Prerequisites

使用门户将数据路由到存储帐户Route data to the storage account using the portal

  1. 通过 https://portal.azure.cn 登录到 Azure 门户。Log in to the Azure portal at https://portal.azure.cn.

  2. 导航到其中的媒体服务帐户,然后单击“监视”下的“诊断设置”。 Navigate to your Media Services account in and click Diagnostic Settings under Monitor. 在此处查看订阅中所有资源的列表,这些资源通过 Azure Monitor 生成监视数据。Here you see a list of all resources in your subscription that produce monitoring data through Azure Monitor.

    诊断设置部分

  3. 单击“添加诊断设置” 。Click Add diagnostic setting.

    资源诊断设置是描述应从特定资源中路由哪个监视数据以及此监视数据应传输到何处的一种定义 。A resource diagnostic setting is a definition of what monitoring data should be routed from a particular resource and where that monitoring data should go.

  4. 在显示的部分中,提供设置的“名称”,并勾选“存档到存储帐户”框 。In the section that appears, give your setting a name and check the box for Archive to a storage account.

    选择要向其发送日志的存储帐户,然后按“确定”。 Select the storage account to which you want to send logs and press OK.

  5. 勾选“日志”和“指标”下的所有框 。Check all the boxes under Log and Metric. 可能仅有下述选项之一,这具体取决于资源类型。Depending on the resource type, you may only have one of these options. 这些复选框可控制向所选目标(本例中为存储帐户)发送此资源类型可用的哪些日志和指标数据类别。These checkboxes control what categories of log and metric data available for that resource type are sent to the destination you've selected, in this case, a storage account.

    诊断设置部分

  6. 将“保留期(天)”滑块移至 30 。Set the Retention (days) slider to 30. 此滑块设置监视数据要在存储帐户中保留的天数。This slider sets a number of days to retain the monitoring data in the storage account. Azure Monitor 会自动删除早于所述天数的数据。Azure Monitor automatically deletes data older than the number of days specified. 如果保留期为 0 天,则无限期存储数据。A retention of zero days stores the data indefinitely.

  7. 单击“保存” 。Click Save.

现在,资源的监视数据将流入到存储帐户。Monitoring data from your resource is now flowing into the storage account.

使用 Azure CLI 将数据路由到存储帐户Route data to the storage account using the Azure CLI

若要允许在存储帐户中存储诊断日志,请运行以下 az monitor diagnostic-settings Azure CLI 命令:To enable storage of diagnostic logs in a Storage Account, you would run the following az monitor diagnostic-settings Azure CLI command:

az monitor diagnostic-settings create --name <diagnostic name> \
    --storage-account <name or ID of storage account> \
    --resource <target resource object ID> \
    --resource-group <storage account resource group> \
    --logs '[
    {
        "category": <category name>,
        "enabled": true,
        "retentionPolicy": {
            "days": <# days to retain>,
            "enabled": true
        }
    }]'

例如:For example:

az monitor diagnostic-settings create --name amsv3diagnostic \
    --storage-account storageaccountforams  \
    --resource "/subscriptions/00000000-0000-0000-0000-0000000000/resourceGroups/amsResourceGroup/providers/Microsoft.Media/mediaservices/amsaccount" \
    --resource-group "amsResourceGroup" \
    --logs '[{"category": "KeyDeliveryRequests",  "enabled": true, "retentionPolicy": {"days": 3, "enabled": true }}]'

使用门户查看存储帐户中的数据View data in the storage account using the portal

如果已执行前述步骤,则数据已开始流向存储帐户。If you have followed the preceding steps, data has begun flowing to your storage account.

可能最多需等待 5 分钟,事件即会在存储帐户中显示。You may need to wait up to five minutes before the event appears in the storage account.

  1. 在门户中,导航到左侧导航栏上的“存储帐户”部分 。In the portal, navigate to the Storage Accounts section by finding it on the left-hand navigation bar.
  2. 找到并单击上一部分中创建的存储帐户。Identify the storage account you created in the preceding section and click on it.
  3. 单击“Blob”,然后单击标记为 insights-logs-keydeliveryrequests 的容器。Click on Blobs, then on the container labeled insights-logs-keydeliveryrequests. 这是包含日志的容器。This is the container that has your logs in it. 监视数据依次按资源 ID、日期和时间细分存入容器。Monitoring data is broken out into containers by resource ID, then by date and time.
  4. 通过单击容器中的资源 ID、日期和时间,导航到 PT1H.json 文件。Navigate to the PT1H.json file by clicking into the containers for resource ID, date, and time. 单击 PT1H.json 文件,再单击“下载” 。Click on the PT1H.json file and click Download.

现可查看存储帐户中存储的 JSON 事件。You can now view the JSON event that was stored in the storage account.

PT1H.json 的示例Examples of PT1H.json

清除密钥传送日志Clear key delivery log

{
  "time": "2019-05-21T00:07:33.2820450Z",
  "resourceId": "/SUBSCRIPTIONS/00000000-0000-0000-0000-0000000000000/RESOURCEGROUPS/amsResourceGroup/PROVIDERS/MICROSOFT.MEDIA/MEDIASERVICES/AMSACCOUNT",
  "operationName": "MICROSOFT.MEDIA/MEDIASERVICES/CONTENTKEYS/READ",
  "operationVersion": "1.0",
  "category": "KeyDeliveryRequests",
  "resultType": "Succeeded",
  "resultSignature": "OK",
  "durationMs": 253,
  "identity": {
    "authorization": {
      "issuer": "myIssuer",
      "audience": "myAudience"
    },
    "claims": {
      "urn:microsoft:azure:mediaservices:contentkeyidentifier": "e4276e1d-c012-40b1-80d0-ac15808b9277",
      "nbf": "1558396914",
      "exp": "1558400814",
      "iss": "myIssuer",
      "aud": "myAudience"
    }
  },
  "level": "Informational",
  "location": "chinaeast2",
  "properties": {
    "requestId": "fb5c2b3a-bffa-4434-9c6f-73d689649add",
    "keyType": "Clear",
    "keyId": "e4276e1d-c012-40b1-80d0-ac15808b9277",
    "policyName": "SharedContentKeyPolicyUsedByAllAssets",
    "tokenType": "JWT",
    "statusMessage": "OK"
  }
}

另请参阅See also

后续步骤Next steps

监视指标Monitor metrics