从 Application Insights 导出遥测数据Export telemetry from Application Insights

想要将遥测数据保留超过标准保留期限?Want to keep your telemetry for longer than the standard retention period? 或者要以某种专业方式处理这些数据?Or process it in some specialized way? 连续导出很适合此目的。Continuous Export is ideal for this. 可以使用 JSON 格式将 Application Insights 门户中显示的事件导出到世纪互联 Azure 中的存储。The events you see in the Application Insights portal can be exported to storage in 21Vianet Azure in JSON format. 可以从该存储中下载这些数据,并编写所需的代码来处理这些数据。From there you can download your data and write whatever code you need to process it.

在设置连续导出之前,请考虑一些备选方法:Before you set up continuous export, there are some alternatives you might want to consider:

  • 通过“指标”或“搜索”选项卡顶部的“导出”按钮,可将表格和图表传输到 Excel 电子表格。The Export button at the top of a metrics or search tab lets you transfer tables and charts to an Excel spreadsheet.

  • Analytics 提供功能强大的遥测查询语言。Analytics provides a powerful query language for telemetry. 它还可以导出结果。It can also export results.

  • 使用数据访问 REST API 能够以编程方式访问遥测数据。The Data access REST API lets you access your telemetry programmatically.

  • 也可以访问通过 Powershell 设置连续导出You can also access setup continuous export via Powershell.

连续导出将数据复制到存储后(数据可在其中保存任意长的时间),在正常保留期内,这些数据仍可在 Application Insights 中使用。After Continuous Export copies your data to storage (where it can stay for as long as you like), it's still available in Application Insights for the usual retention period.

连续导出高级存储配置Continuous Export advanced storage configuration

连续导出不支持以下 Azure 存储功能/配置:Continuous Export does not support the following Azure storage features/configurations:

创建连续导出Create a Continuous Export

  1. 在左侧“配置”下应用的 Application Insights 资源中,打开“连续导出”,并选择“添加” :In the Application Insights resource for your app under configure on the left, open Continuous Export and choose Add:

  2. 选择要导出的遥测数据类型。Choose the telemetry data types you want to export.

  3. 创建或选择要用于存储数据的 Azure 存储帐户Create or select an Azure storage account where you want to store the data. 有关存储定价选项的详细信息,请访问官方定价页面For more information on storage pricing options visit the official pricing page.

    单击“添加”、“导出目标”、“存储帐户”,并创建新存储或选择现有存储。Click Add, Export Destination, Storage account, and then either create a new store or choose an existing store.


    默认情况下,存储位置将设置为与 Application Insights 资源相同的地理区域。By default, the storage location will be set to the same geographical region as your Application Insights resource. 如果存储在不同的区域中,则可能会产生传输费用。If you store in a different region, you may incur transfer charges.

  4. 在存储中创建或选择一个容器。Create or select a container in the storage.

创建导出之后,将开始导出数据。Once you've created your export, it starts going. 只能获取创建导出后到达的数据。You only get data that arrives after you create the export.

数据出现在存储中之前可能有大约一小时的延迟。There can be a delay of about an hour before data appears in the storage.

编辑连续导出To edit continuous export

单击“连续导出”并选择要编辑的存储帐户。Click on continuous export and select the storage account to edit.

停止连续导出To stop continuous export

若要停止导出,请单击“禁用”。To stop the export, click Disable. 再次单击“启用”时,将使用新数据重新启动导出。When you click Enable again, the export will restart with new data. 无法获取在禁用导出时传入门户的数据。You won't get the data that arrived in the portal while export was disabled.

要永久停止导出,请将其删除。To stop the export permanently, delete it. 这样做不会将数据从存储中删除。Doing so doesn't delete your data from storage.

无法添加或更改导出?Can't add or change an export?

  • 若要添加或更改导出,需要“所有者”、“参与者”或“Application Insights 参与者”访问权限。To add or change exports, you need Owner, Contributor, or Application Insights Contributor access rights. 了解角色Learn about roles.

获取哪些事件?What events do you get?

导出的数据是从应用程序接收的原始遥测数据,只不过我们添加了从客户端 IP 地址计算的位置数据。The exported data is the raw telemetry we receive from your application, except that we add location data, which we calculate from the client IP address.

采样丢弃的数据不会包含在导出的数据中。Data that has been discarded by sampling is not included in the exported data.

不包含其他计算的指标。Other calculated metrics are not included. 例如,不会导出平均 CPU 使用率,但会导出用来计算平均值的原始遥测数据。For example, we don't export average CPU utilization, but we do export the raw telemetry from which the average is computed.

该数据还包含已设置的任何可用性 Web 测试的结果。The data also includes the results of any availability web tests that you have set up.


采样。Sampling. 如果应用程序发送大量数据,采样功能可能会运行,并只发送一小部分生成的遥测数据。If your application sends a lot of data, the sampling feature may operate and send only a fraction of the generated telemetry. 了解有关采样的详细信息。Learn more about sampling.

检查数据Inspect the data

可以直接在门户中检查存储。You can inspect the storage directly in the portal. 单击最左侧菜单中的“主页”,在顶部显示“Azure 服务”的位置选择“存储帐户” ,选择存储帐户名称,在“概述”页上选择“服务”下的“Blob” ,最后选择容器名称。Click home in the leftmost menu, at the top where it says "Azure services" select Storage accounts, select the storage account name, on the overview page select Blobs under services, and finally select the container name.

若要在 Visual Studio 中检查 Azure 存储,请依次打开“视图”、“Cloud Explorer”。 To inspect Azure storage in Visual Studio, open View, Cloud Explorer. (如果没有此菜单命令,则需要安装 Azure SDK:打开“新建项目” 对话框,展开 Visual C#/云/并选择“用于 .NET 的 Microsoft Azure SDK” 。)(If you don't have that menu command, you need to install the Azure SDK: Open the New Project dialog, expand Visual C#/Cloud and choose Get Microsoft Azure SDK for .NET.)

打开 Blob 存储后,会看到包含一组 Blob 文件的容器。When you open your blob store, you'll see a container with a set of blob files. 每个文件的 URI 派生自 Application Insights 的资源名称、其检测密钥、遥测类型/日期/时间。The URI of each file derived from your Application Insights resource name, its instrumentation key, telemetry-type/date/time. (资源名称为全小写形式,检测密钥不包含连字符。)(The resource name is all lowercase, and the instrumentation key omits dashes.)

使用适当的工具检查 Blob 存储

日期和时间采用 UTC,表示在存储中存放遥测数据的时间 - 而不是生成遥测数据的时间。The date and time are UTC and are when the telemetry was deposited in the store - not the time it was generated. 因此,如果编写代码来下载数据,数据的日期和时间可能会线性移动。So if you write code to download the data, it can move linearly through the data.

路径格式如下:Here's the form of the path:

$"{applicationName}_{instrumentationKey}/{type}/{blobDeliveryTimeUtc:yyyy-MM-dd}/{ blobDeliveryTimeUtc:HH}/{blobId}_{blobCreationTimeUtc:yyyyMMdd_HHmmss}.blob"


  • blobCreationTimeUtc 是在内部暂存存储中创建 Blob 的时间blobCreationTimeUtc is time when blob was created in the internal staging storage
  • blobDeliveryTimeUtc 是将 Blob 复制到导出目标存储的时间blobDeliveryTimeUtc is the time when blob is copied to the export destination storage

数据格式Data format

  • 每个 Blob 是一个文本文件,其中包含多个以“\n”分隔的行。Each blob is a text file that contains multiple '\n'-separated rows. 它包含大约半分钟时间内处理的遥测数据。It contains the telemetry processed over a time period of roughly half a minute.
  • 每行代表遥测数据点,例如请求或页面视图。Each row represents a telemetry data point such as a request or page view.
  • 每行是未设置格式的 JSON 文档。Each row is an unformatted JSON document. 如果想要琢磨该文档,请在 Visual Studio 中打开它,并依次选择“编辑”、“高级”、“设置文件格式”:If you want to sit and stare at it, open it in Visual Studio and choose Edit, Advanced, Format File:


持续时间以刻度为单位,10000 刻度 = 1 毫秒。Time durations are in ticks, where 10 000 ticks = 1 ms. 例如,这些值显示从浏览器发送请求用了 1 毫秒时间,接收它用了 3 毫秒,在浏览器中处理页面用了 1.8 秒:For example, these values show a time of 1 ms to send a request from the browser, 3 ms to receive it, and 1.8 s to process the page in the browser:

"sendRequest": {"value": 10000.0},
"receiveRequest": {"value": 30000.0},
"clientProcess": {"value": 17970000.0}

属性类型和值的详细数据模型参考。Detailed data model reference for the property types and values.

处理数据Processing the data

如果数据规模不大,可以编写一些代码来提取数据,在电子表格中阅读这些数据,或执行其他操作。On a small scale, you can write some code to pull apart your data, read it into a spreadsheet, and so on. 例如:For example:

private IEnumerable<T> DeserializeMany<T>(string folderName)
  var files = Directory.EnumerateFiles(folderName, "*.blob", SearchOption.AllDirectories);
  foreach (var file in files)
     using (var fileReader = File.OpenText(file))
        string fileContent = fileReader.ReadToEnd();
        IEnumerable<string> entities = fileContent.Split('\n').Where(s => !string.IsNullOrWhiteSpace(s));
        foreach (var entity in entities)
            yield return JsonConvert.DeserializeObject<T>(entity);

如需更详细的代码示例,请参阅使用辅助角色For a larger code sample, see using a worker role.

删除旧数据Delete your old data

要负责管理存储容量,以及在必要时删除旧数据。You are responsible for managing your storage capacity and deleting the old data if necessary.

如果重新生成存储密钥...If you regenerate your storage key...

如果更改存储密钥,连续导出将停止运行。If you change the key to your storage, continuous export will stop working. Azure 帐户中会显示通知。You'll see a notification in your Azure account.

打开“连续导出”选项卡并编辑导出。Open the Continuous Export tab and edit your export. 编辑“导出目标”,只保留选定的同一存储。Edit the Export Destination, but just leave the same storage selected. 单击“确定”以确认。Click OK to confirm.

连续导出将重新开始。The continuous export will restart.

导出示例Export samples

如果数据规模较大,可以考虑 HDInsight - 云中的 Hadoop 群集。On larger scales, consider HDInsight - Hadoop clusters in the cloud. HDInsight 提供多种技术用于管理和分析大数据。可以使用 HDInsight 来处理从 Application Insights 导出的数据。HDInsight provides a variety of technologies for managing and analyzing big data, and you could use it to process data that has been exported from Application Insights.

问题解答Q & A

  • 我想要一次性下载某个图表。But all I want is a one-time download of a chart.

    没问题,可以这样做。Yes, you can do that. 在选项卡顶部单击“导出数据”。 At the top of the tab, click Export Data.

  • 我设置了导出,但存储中没有数据。I set up an export, but there's no data in my store.

    自设置导出之后,Application Insights 是否从应用程序收到了任何遥测数据?Did Application Insights receive any telemetry from your app since you set up the export? 只会收到新数据。You'll only receive new data.

  • 尝试设置导出时出现拒绝访问错误I tried to set up an export, but was denied access

    如果帐户由组织拥有,则你必须是所有者或参与者组的成员。If the account is owned by your organization, you have to be a member of the owners or contributors groups.

  • 是否可以直接导出到我自己的本地存储?Can I export straight to my own on-premises store?

    很抱歉,不可以。No, sorry. 我们的导出引擎目前仅适用于 Azure 存储。Our export engine currently only works with Azure storage at this time.

  • 放置在存储中的数据量是否有任何限制?Is there any limit to the amount of data you put in my store?

    否。No. 我们将持续推送数据,直到删除了导出。We'll keep pushing data in until you delete the export. 如果达到 Blob 存储的外在限制,推送会停止,但那个限制极大。We'll stop if we hit the outer limits for blob storage, but that's pretty huge. 可以自行控制使用的存储量。It's up to you to control how much storage you use.

  • 存储中应会出现多少个 Blob?How many blobs should I see in the storage?

    • 对于选择要导出的每种数据类型,将每隔分钟创建一个新 Blob(如果有可用的数据)。For every data type you selected to export, a new blob is created every minute (if data is available).
    • 此外,对于高流量应用程序,将分配额外的分区单元。In addition, for applications with high traffic, additional partition units are allocated. 在此情况下,每个单元每隔一分钟创建一个 Blob。In this case, each unit creates a blob every minute.
  • 我为存储重新生成了密钥或更改了容器的名称,但现在导出不能正常进行。I regenerated the key to my storage or changed the name of the container, and now the export doesn't work.

    编辑导出并打开“导出目标”选项卡。像以前一样保留选择相同的存储,并单击“确定”以确认。Edit the export and open the export destination tab. Leave the same storage selected as before, and click OK to confirm. 导出将重新开始。Export will restart. 如果更改是在最近几天内做出的,则不会丢失数据。If the change was within the past few days, you won't lose data.

  • 是否可以暂停导出?Can I pause the export?

    是的。Yes. 单击“禁用”即可。Click Disable.

代码示例Code samples