PageRenderTime 50ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/articles/media-services/media-services-telemetry.md

https://gitlab.com/yeah568/azure-content
Markdown | 236 lines | 182 code | 54 blank | 0 comment | 0 complexity | 8584e7cf9b70692ba276f1b49bb89706 MD5 | raw file
  1. <properties pageTitle="Azure Media Services Telemetry with .NET | Microsoft Azure"
  2. description="This article shows you how to use the Azure Media Services telemetry."
  3. services=""
  4. documentationCenter=""
  5. authors="juliako" />
  6. # Azure Media Services Telemetry with .NET
  7. ## Overview
  8. Media Services telemetry/monitoring allows Media Services customers to access metrics data for its services. Current version supports telemetry data for "Channel" and "StreamingEndpoint" entities. You can configure telemetry on component level granularity. There are two detail levels "Normal" and "Verbose". The current version only supports "Normal".
  9. Telemetry is written to an Azure Storage Account provided by the customer (a storage account must be attached to the Media Services account). Telemetry is written to an Azure Storage Table in the specified storage account. Telemetry system will create a separate table for each new day based at 00:00 UTC. As an example "TelemetryMetrics20160321" where "20160321" is date of table created. For each day there will be separate table.
  10. Telemetry system doesnt provide data retention nor auto delete of old records. For that reason, you need to manage and delete old records. Having separate tables for each day makes it easy to delete old records. You can just delete old tables.
  11. This topic shows how to enable telemetry for the specified AMS services and how to query the metrics using .NET.
  12. ## Configuring telemetry for a Media Services account
  13. The following steps are needed to enable telemetry:
  14. - Get the credentials of the storage account attached to the Media Services account.
  15. - Create a Notification Endpoint with **EndPointType** set to **AzureTable** and endPontAddress pointing to the storage table.
  16. INotificationEndPoint notificationEndPoint =
  17. _context.NotificationEndPoints.Create("monitoring",
  18. NotificationEndPointType.AzureTable,
  19. "https://" + _mediaServicesStorageAccountName + ".table.core.windows.net/");
  20. - Create a monitoring configuration settings for the services you want to monitor. No more than one monitoring configuration settings is allowed.
  21. IMonitoringConfiguration monitoringConfiguration = _context.MonitoringConfigurations.Create(notificationEndPoint.Id,
  22. new List<ComponentMonitoringSetting>()
  23. {
  24. new ComponentMonitoringSetting(MonitoringComponent.Channel, MonitoringLevel.Normal),
  25. new ComponentMonitoringSetting(MonitoringComponent.StreamingEndpoint, MonitoringLevel.Normal)
  26. });
  27. ## StreamingEndpoint log
  28. ###Available metrics
  29. You can query for the following StreamingEndPoint metrics.
  30. - **PartitionKey** gets the partition key of the record.
  31. - **RowKey** gets the row key of the record.
  32. - **AccountId** gets the Media Services account ID.
  33. - **AccountId** gets the Media Services Streaming Endpoint ID.
  34. - **ObservedTime** gets the observed time of the metric.
  35. - **HostName** gets the Streaming Endpoint host name.
  36. - **StatusCode** gets the status code.
  37. - **ResultCode** gets the result code.
  38. - **RequestCount** gets the request count.
  39. - **BytesSent** gets the bytes sent.
  40. - **BytesSent** gets the server latency.
  41. - **BytesSent** gets the end to end request time.
  42. ###Streaming Endpoint query result example
  43. ![Streaming Endpoint query](media/media-services-telemetry/media-services-telemetry01.png)
  44. ## Live channel heartbeat
  45. ###Available metrics
  46. You can query for the following live channel metrics.
  47. - **PartitionKey** gets the partition key of the record.
  48. - **RowKey** gets the row key of the record.
  49. - **AccountId** gets the Media Services account ID.
  50. - **ChannelId** gets the Media Services Channel ID.
  51. - **ObservedTime** gets the observed time of the metric.
  52. - **CustomAttributes** gets the custom attributes.
  53. - **TrackType** gets the track type.
  54. - **TrackName** gets the track name.
  55. - **Bitrate** gets the bitrate.
  56. - **IncomingBitrate** gets the incoming bitrate.
  57. - **OverlapCount** gets the overlap count.
  58. - **DiscontinuityCount** gets the discontinuity count.
  59. - **LastTimestamp** gets the last time stamp.
  60. ###Live Channel query result example
  61. ![Streaming Endpoint query](media/media-services-telemetry/media-services-telemetry01.png)
  62. ## StreamingEndpoint metrics example
  63. using System;
  64. using System.Collections.Generic;
  65. using System.Configuration;
  66. using System.Linq;
  67. using Microsoft.WindowsAzure.MediaServices.Client;
  68. namespace AMSMetrics
  69. {
  70. class Program
  71. {
  72. // Read values from the App.config file.
  73. private static readonly string _mediaServicesAccountName =
  74. ConfigurationManager.AppSettings["MediaServicesAccountName"];
  75. private static readonly string _mediaServicesAccountKey =
  76. ConfigurationManager.AppSettings["MediaServicesAccountKey"];
  77. private static readonly string _mediaServicesAccountID =
  78. ConfigurationManager.AppSettings["MediaServicesAccountID"];
  79. private static readonly string _streamingEndpointID =
  80. ConfigurationManager.AppSettings["StreamingEndpointID"];
  81. private static readonly string _mediaServicesStorageAccountName =
  82. ConfigurationManager.AppSettings["StorageAccountName"];
  83. private static readonly string _mediaServicesStorageAccountKey =
  84. ConfigurationManager.AppSettings["StorageAccountKey"];
  85. // Field for service context.
  86. private static CloudMediaContext _context = null;
  87. private static MediaServicesCredentials _cachedCredentials = null;
  88. static void Main(string[] args)
  89. {
  90. // Create and cache the Media Services credentials in a static class variable.
  91. _cachedCredentials = new MediaServicesCredentials(
  92. _mediaServicesAccountName,
  93. _mediaServicesAccountKey);
  94. // Used the cached credentials to create CloudMediaContext.
  95. _context = new CloudMediaContext(_cachedCredentials);
  96. INotificationEndPoint notificationEndPoint =
  97. _context.NotificationEndPoints.Create("monitoring", NotificationEndPointType.AzureTable, GetTableEndPoint());
  98. var monitoringConfigurations = _context.MonitoringConfigurations;
  99. IMonitoringConfiguration monitoringConfiguration = null;
  100. // No more than one monitoring configuration settings is allowed.
  101. if (monitoringConfigurations.ToArray().Length != 0)
  102. {
  103. monitoringConfiguration = _context.MonitoringConfigurations.FirstOrDefault();
  104. }
  105. else
  106. {
  107. monitoringConfiguration = _context.MonitoringConfigurations.Create(notificationEndPoint.Id,
  108. new List<ComponentMonitoringSetting>()
  109. {
  110. new ComponentMonitoringSetting(MonitoringComponent.StreamingEndpoint, MonitoringLevel.Normal)
  111. });
  112. }
  113. //Print metrics for a Streaming Endpoint.
  114. PrintStreamingEndpointMetrics();
  115. Console.ReadLine();
  116. }
  117. private static string GetTableEndPoint()
  118. {
  119. return "https://" + _mediaServicesStorageAccountName + ".table.core.windows.net/";
  120. }
  121. private static void PrintStreamingEndpointMetrics()
  122. {
  123. var end = DateTime.UtcNow;
  124. var start = DateTime.UtcNow.AddHours(-5);
  125. // Get some streaming endpoint metrics.
  126. var res = _context.StreamingEndPointRequestLogs.GetStreamingEndPointMetrics(
  127. GetTableEndPoint(),
  128. _mediaServicesStorageAccountKey,
  129. _mediaServicesAccountID,
  130. _streamingEndpointID,
  131. start,
  132. end);
  133. Console.Title = "Streaming endpoint metrics:";
  134. foreach (var log in res)
  135. {
  136. Console.WriteLine("AccountId: {0}", log.AccountId);
  137. Console.WriteLine("BytesSent: {0}", log.BytesSent);
  138. Console.WriteLine("EndToEndLatency: {0}", log.EndToEndLatency);
  139. Console.WriteLine("HostName: {0}", log.HostName);
  140. Console.WriteLine("ObservedTime: {0}", log.ObservedTime);
  141. Console.WriteLine("PartitionKey: {0}", log.PartitionKey);
  142. Console.WriteLine("RequestCount: {0}", log.RequestCount);
  143. Console.WriteLine("ResultCode: {0}", log.ResultCode);
  144. Console.WriteLine("RowKey: {0}", log.RowKey);
  145. Console.WriteLine("ServerLatency: {0}", log.ServerLatency);
  146. Console.WriteLine("StatusCode: {0}", log.StatusCode);
  147. Console.WriteLine("StreamingEndpointId: {0}", log.StreamingEndpointId);
  148. Console.WriteLine();
  149. }
  150. Console.WriteLine();
  151. }
  152. private static void PrintChannelMetrics()
  153. {
  154. var end = DateTime.UtcNow;
  155. var start = DateTime.UtcNow.AddHours(-5);
  156. // Get some channel metrics.
  157. var channelMetrics = _context.ChannelMetrics.GetChannelMetrics(
  158. GetTableEndPoint(),
  159. _mediaServicesStorageAccountKey,
  160. _mediaServicesAccountName,
  161. _context.Channels.FirstOrDefault().Id,
  162. start,
  163. end);
  164. // Print the channel metrics.
  165. Console.WriteLine("Channel metrics:");
  166. foreach (var channelHeartbeat in channelMetrics.OrderBy(x => x.ObservedTime))
  167. {
  168. Console.WriteLine(
  169. " Observed time: {0}, Last timestamp: {1}, Incoming bitrate: {2}",
  170. channelHeartbeat.ObservedTime,
  171. channelHeartbeat.LastTimestamp,
  172. channelHeartbeat.IncomingBitrate);
  173. }
  174. Console.WriteLine();
  175. }
  176. }
  177. }
  178. ##Provide feedback
  179. [AZURE.INCLUDE [media-services-user-voice-include](../../includes/media-services-user-voice-include.md)]
  180. ##Next step
  181. See Azure Media Services learning paths to help you learn about great features offered by AMS.
  182. [AZURE.INCLUDE [media-services-learning-paths-include](../../includes/media-services-learning-paths-include.md)]