监视和日志记录Monitoring and logging

在本文中,你将了解如何从 IoT Edge 模块上的实时视频分析接收事件,以进行远程监视。In this article, you will learn about how you can receive events from the Live Video Analytics on IoT Edge module for remote monitoring.

你还将了解如何控制模块生成的日志。You will also learn about how you can control the logs that the module generates.

事件的分类Taxonomy of events

IoT Edge 上的实时视频分析根据以下分类发出事件或遥测数据。Live Video Analytics on IoT Edge emits events, or telemetry data according to the following taxonomy.

IoT Edge 上的实时视频分析遥测架构

  • 可操作:事件是用户执行的操作的一部分,或者是在执行媒体图期间生成的。Operational: events that are generated as part of actions taken by a user, or during the execution of a media graph.

    • 数量:应较低(每分钟几次,甚至更低的速率)。Volume: expected to be low (a few times a minute, or even lower rate).

    • 示例:Examples:

      开始记录(如下),停止记录Recording started (below), recording stopped

      {
        "body": {
          "outputType": "assetName",
          "outputLocation": "sampleAssetFromEVR-LVAEdge-20200512T233309Z"
        },
        "applicationProperties": {
          "topic": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/<my-resource-group>/providers/microsoft.media/mediaservices/<ams-account-name>",
          "subject": "/graphInstances/Sample-Graph-2/sinks/assetSink",
          "eventType": "Microsoft.Media.Graph.Operational.RecordingStarted",
          "eventTime": "2020-05-12T23:33:10.392Z",
          "dataVersion": "1.0"
        }
      }
      
  • 诊断:有助于诊断问题和/或性能问题的事件。Diagnostics: events that help to diagnose problems and/or issues with performance.

    • 数量:可能很高(每分钟几次)。Volume: can be high (several times a minute).

    • 示例:Examples:

      RTSP SDP 信息(如下),或传入视频源中的间隔。RTSP SDP information (below), or gaps in the incoming video feed.

      {
        "body": {
          "sdp": "SDP:\nv=0\r\no=- 1589326384077235 1 IN IP4 XXX.XX.XX.XXX\r\ns=Matroska video+audio+(optional)subtitles, streamed by the LIVE555 Media Server\r\ni=media/lots_015.mkv\r\nt=0 0\r\na=tool:LIVE555 Streaming Media v2020.04.12\r\na=type:broadcast\r\na=control:*\r\na=range:npt=0-73.000\r\na=x-qt-text-nam:Matroska video+audio+(optional)subtitles, streamed by the LIVE555 Media Server\r\na=x-qt-text-inf:media/lots_015.mkv\r\nm=video 0 RTP/AVP 96\r\nc=IN IP4 0.0.0.0\r\nb=AS:500\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 packetization-mode=1;profile-level-id=640028;sprop-parameter-sets=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\r\na=control:track1\r\n"
        },
        "applicationProperties": {
          "topic": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/<my-resource-group>/providers/microsoft.media/mediaservices/<ams-account-name>",
          "subject": "/graphInstances/Sample-Graph-2/sources/rtspSource",
          "eventType": "Microsoft.Media.Graph.Diagnostics.MediaSessionEstablished",
          "eventTime": "2020-05-12T23:33:04.077Z",
          "dataVersion": "1.0"
        }
      }
      
  • 分析:视频分析过程中生成的事件。Analytics: events that are generated as part of video analysis.

    • 数量:可能很高(每分钟几次或频率更高)。Volume: can be high (several times a minute or more often).

    • 示例:Examples:

      检测到的动作(如下所示),推理结果。Motion detected (below), Inference result.

    {
       "body": {
         "timestamp": 143039375044290,
         "inferences": [
           {
             "type": "motion",
             "motion": {
               "box": {
                 "l": 0.48954,
                 "t": 0.140741,
                 "w": 0.075,
                 "h": 0.058824
               }
             }
           }
         ]
       },
       "applicationProperties": {
         "topic": "/subscriptions/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/resourceGroups/<my-resource-group>/providers/microsoft.media/mediaservices/<ams-account-name>",
         "subject": "/graphInstances/Sample-Graph-2/processors/md",
         "eventType": "Microsoft.Media.Graph.Analytics.Inference",
         "eventTime": "2020-05-12T23:33:09.381Z",
         "dataVersion": "1.0"
       }
    }
    

模块发出的事件将发送到 IoT Edge 中心,然后可以从那里将其路由到其他目标。The events emitted by the module are sent to the IoT Edge Hub, and from there it can be routed to other destinations.

分析事件中的时间戳Timestamps in analytic events

如上所述,作为视频分析的一部分生成的事件具有与其相关联的时间戳。As indicated above, events generated as part of video analysis have a timestamp associated with them. 如果将实时视频录制作为图形拓扑的一部分,则此时间戳有助于你定位录制的视频中发生特定事件的位置。If you recorded the live video as part of your graph topology, then this timestamp helps you locate where in the recorded video that particular event occured. 以下是关于如何将分析事件中的时间戳映射到录制到 Azure 媒体服务资产中的视频时间戳的指导原则。Following are the guidelines on how to map the timestamp in an analytic event to the timeline of the video recorded into an Azure Media Service asset.

首先,提取 eventTime 值。First, extract the eventTime value. 时间范围筛选器中使用此值检索录制的适当部分。Use this value in a time range filter to retrieve a suitable portion of the recording. 例如,你可能希望提取在 eventTime 之前 30 秒开始和在其之后 30 秒结束的视频。For example, you may want to fetch video that starts 30 seconds before eventTime and ends 30 seconds afterwards. 在上面的示例中,如果 eventTime 为 2020-05-12T23:33:09.381Z,那么 +/- 30s 窗口的 HLS 清单的请求将如下所示:With the above example, where eventTime is 2020-05-12T23:33:09.381Z, a request for a HLS manifest for the +/- 30s window would look like the following:

https://{hostname-here}/{locatorGUID}/content.ism/manifest(format=m3u8-aapl,startTime=2020-05-12T23:32:39Z,endTime=2020-05-12T23:33:39Z).m3u8

上面的 URL 将返回一个所谓的主播放列表,其中包含媒体播放列表的 URL。The URL above would return a so-called master playlist, containing URLs for media playlists. 媒体播放列表将包含如下所示的条目:The media playlist would contain entries like the following:

...
#EXTINF:3.103011,no-desc
Fragments(video=143039375031270,format=m3u8-aapl)
...

在上面的条目中,条目报告有一个从时间戳值 143039375031270 开始的视频片段。In the above, the entry reports that a video fragment is available that starts at a timestamp value of 143039375031270. 分析事件中的 timestamp 值使用与媒体播放列表相同的时间刻度,可用于标识相关的视频片段,并查找正确的帧。The timestamp value in the analytic event uses the same timescale as the media playlist, and can be used to identify the relevant video fragment, and seek to the correct frame.

有关详细信息,可以阅读 HLS 中有关准确查找帧的众多文章之一。For more information, you can read one of the many articles on frame accurate seeking in HLS.

控制事件Controlling events

你可以使用模块孪生 JSON 架构中所述的以下模块孪生属性,控制由 IoT Edge 模块上的实时视频分析发布的操作和诊断事件。You can use the following module twin properties, as documented in module twin JSON schema, to control the operational and diagnostic events that are published by the Live Video Analytics on IoT Edge module.

diagnosticsEventsOutputName - 包括并提供此属性的(任何)值,以便从模块中获取诊断事件。diagnosticsEventsOutputName – include and provide (any) value for this property, in order to get diagnostic events from the module. 忽略它或将它留空可阻止模块发布诊断事件。Omit it, or leave it empty to stop the module from publishing diagnostic events.

operationalEventsOutputName - 包括并提供此属性的(任何)值,以便从模块中获取操作事件。operationalEventsOutputName – include and provide (any) value for this property, in order to get operational events from the module. 忽略它或将它留空可阻止模块发布操作事件。Omit it, or leave it empty to stop the module from publishing operational events.

分析事件由动作检测处理器或 HTTP 扩展处理器等节点生成,并且 IoT 中心接收器用于将它们发送到 IoT Edge 中心。The analytics events are generated by nodes such as the motion detection processor, or the HTTP extension processor, and the IoT hub sink is used to send them to the IoT Edge Hub.

可以通过 $edgeHub 模块孪生的所需属性(位于部署清单中)控制以上所有事件的路由You can control the routing of all the above events via a desired property of the $edgeHub module twin (in the deployment manifest):

 "$edgeHub": {
   "properties.desired": {
     "schemaVersion": "1.0",
     "routes": {
       "moduleToHub": "FROM /messages/modules/lvaEdge/outputs/* INTO $upstream"
     },
     "storeAndForwardConfiguration": {
       "timeToLiveSecs": 7200
     }
   }
 }

在上文中,lvaEdge 是 IoT Edge 模块上实时视频分析的名称,并且路由规则遵循声明路由中定义的架构。In the above, lvaEdge is the name for the Live Video Analytics on IoT Edge module, and the routing rule follows the schema defined in declare routes.

备注

为了确保分析事件到达 IoT Edge 中心,在任何动作检测处理器节点和/或任何 HTTP 扩展处理器节点的下游都需要有一个 IoT 中心接收器节点。In order to ensure that analytics events reach the IoT Edge Hub, there needs to be an IoT hub sink node downstream of any motion detection processor node and/or any HTTP extension processor node.

事件架构Event schema

事件来自 Edge 设备,你可以在 Edge 或云中使用它。Events originate on the Edge device, and can be consumed on the Edge or in the cloud. 由 IoT Edge 上的实时视频分析生成的事件遵循由 Azure IoT 中心建立的流式处理消息传递模式,并且具有系统属性、应用程序属性和正文。Events generated by Live Video Analytics on IoT Edge conform to the streaming messaging pattern established by Azure IoT Hub, with system properties, application properties, and a body.

摘要Summary

通过 IoT 中心观察到的每个事件都将具有如下所述的一组共同属性。Every event, when observed via the IoT Hub, will have a set of common properties as described below.

属性Property 属性类型Property Type 数据类型Data Type 说明Description
message-idmessage-id systemsystem GUIDguid 唯一的事件 ID。Unique event ID.
主题topic applicationPropertyapplicationProperty stringstring 媒体服务帐户的 Azure 资源管理器路径。Azure Resource Manager path for the Media Services account.
subjectsubject applicationPropertyapplicationProperty stringstring 发出事件的实体的子路径。Sub-path to the entity emitting the event.
EventTimeeventTime applicationPropertyapplicationProperty stringstring 生成事件的时间。Time the event was generated.
eventTypeeventType applicationPropertyapplicationProperty stringstring 事件类型标识符(见下文)。Event Type identifier (see below).
bodybody bodybody objectobject 特定事件数据。Particular event data.
dataVersiondataVersion applicationPropertyapplicationProperty stringstring {Major}.{Minor}{Major}.{Minor}

属性Properties

message-idmessage-id

事件全局唯一标识符 (GUID)Event globally unique identifier (GUID)

主题topic

表示与关系图关联的 Azure 媒体服务帐户。Represents the Azure Media Service account associated with the graph.

/subscriptions/{subId}/resourceGroups/{rgName}/providers/Microsoft.Media/mediaServices/{accountName}

subjectsubject

发出事件的实体:Entity which is emitting the event:

/graphInstances/{graphInstanceName}
/graphInstances/{graphInstanceName}/sources/{sourceName}
/graphInstances/{graphInstanceName}/processors/{processorName}
/graphInstances/{graphInstanceName}/sinks/{sinkName}

subject 属性允许将一般事件映射到其生成模块。The subject property allows for generic events to be mapped to its generating module. 例如,如果 RTSP 用户名或密码无效,则生成的事件将是 /graphInstances/myGraph/sources/myRtspSource 节点上的 Microsoft.Media.Graph.Diagnostics.ProtocolErrorFor instance, in case of invalid RTSP username or password the generated event would be Microsoft.Media.Graph.Diagnostics.ProtocolError on the /graphInstances/myGraph/sources/myRtspSource node.

事件类型Event types

事件类型根据以下架构分配给命名空间:Event types are assigned to a namespace according with the following schema:

Microsoft.Media.Graph.{EventClass}.{EventType}

事件类Event classes

类名Class Name 说明Description
分析Analytics 在内容分析过程中生成的事件。Events generated as part of content analysis.
诊断Diagnostics 有助于诊断问题和性能的事件。Events that aid with diagnostics of problems and performance.
可运行Operational 在资源操作过程中生成的事件。Events generated as part of resource operation.

事件类型特定于每个事件类。The event types are specific to each event class.

示例:Examples:

  • Microsoft.Media.Graph.Analytics.InferenceMicrosoft.Media.Graph.Analytics.Inference
  • Microsoft.Media.Graph.Diagnostics.AuthorizationErrorMicrosoft.Media.Graph.Diagnostics.AuthorizationError
  • Microsoft.Media.Graph.Operational.GraphInstanceStartedMicrosoft.Media.Graph.Operational.GraphInstanceStarted

事件时间Event time

ISO8601 字符串中介绍了事件时间,它是事件发生的时间。Event time is described in ISO8601 string and it the time the event occurred.

日志记录Logging

与其他 IoT Edge 模块一样,你也可以检查 Edge 设备上的容器日志Like with other IoT Edge modules, you can also examine the container logs on the Edge device. 可以通过以下模块孪生属性来控制写入日志的信息:The information that is written to the logs can be controlled by the following module twin properties:

  • logLevellogLevel

    • 允许的值为“详细”、“信息”、“警告”、“错误”、“无”。Allowed values are Verbose, Information, Warning, Error, None.
    • 默认值为“信息”- 日志将包含错误、警告和信息。Default value is Information – the logs will contain error, warning, and information. 消息。messages.
    • 如果将值设置为“警告”,则日志将包含错误和警告消息If you set the value to Warning, the logs will contain error and warning messages
    • 如果将值设置为“错误”,则日志将仅包含错误消息。If you set the value to Error, the logs will only contain error messages.
    • 如果将值设置为“无”,则不会生成任何日志(不建议这样做)。If you set the value to None, no logs will be generated (this is not recommended).
    • 仅在需要与 Azure 支持共享日志以诊断问题时,才应使用“详细”。You should only use Verbose if you need to share logs with Azure Support for diagnosing an issue.
  • logCategorieslogCategories

    • 以逗号分隔的以下一项或多项的列表:应用程序、事件和 MediaPipeline。A comma-separated list of one or more of the following: Application, Events, MediaPipeline.
    • 默认值:应用程序和事件。Default: Application, Events.
    • 应用程序 - 这是来自模块的概要信息,例如模块启动消息、环境错误和直接方法调用。Application – this is high-level information from the module, such as module startup messages, environment errors, and direct method calls.
    • 事件 - 这些是本文前面介绍的所有事件。Events – these are all the events that were described earlier in this article.
    • MediaPipeline - 这些是一些低级别的日志,可在对问题(例如,与支持 RTSP 的相机建立连接时遇到困难)进行故障排除时提供见解。MediaPipeline – these are some low-level logs that may offer insight when troubleshooting issues, such as difficulties establishing a connection with an RTSP-capable camera.

生成调试日志Generating debug logs

在某些情况下,可能需要生成比上述日志更详细的日志才能帮助 Azure 支持解决问题。In certain cases, you may need to generate more detailed logs than the ones described above, to help Azure support resolve an issue. 可以通过两个步骤完成此操作。There are two steps to accomplish this.

首先,通过 createOptions 将模块存储链接到设备存储First, you link the module storage to the device storage via createOptions. 如果你从快速入门检查部署清单模板,则会看到以下内容:If you examine a deployment manifest template from the quick-starts, you will see:

"createOptions": {
   …
   "Binds": [
     "/var/local/mediaservices/:/var/lib/azuremediaservices/"
   ]
 }

上述内容允许 Edge 模块将日志写入(设备)存储路径“/var/local/mediaservices/”。Above lets the Edge module write logs to the (device) storage path “/var/local/mediaservices/”. 如果将以下所需属性添加到模块中:If you add the following desired property to the module:

"debugLogsDirectory": "/var/lib/azuremediaservices/debuglogs/",

然后,该模块将以二进制格式将调试日志写入(设备)存储路径 /var/local/mediaservices/debuglogs/,你可以与 Azure 支持共享该路径。Then, the module will write debug logs in a binary format to the (device) storage path /var/local/mediaservices/debuglogs/, which you can share with Azure Support.

常见问题FAQ

常见问题FAQs

后续步骤Next steps

连续视频录制Continuous video recording