如何通过云服务、角色、角色实例查询WADLogsTable?

how to query WADLogsTable by cloud service, role and role instance?

假设我想获取给定云服务最后 24 小时的 WADLogsTable 日志,可能缩小到给定角色,甚至进一步缩小到给定实例。查询是什么样的?有没有高级别的api?

因此,没有 API 专门用于查询诊断数据。由于诊断数据存储在 Azure 表中,您只需查询 table 即可获取所需数据。

您会注意到的一件事是,这些 table 中的 PartitionKey 代表时间(四舍五入到最接近的分钟),以刻度表示。如果您有兴趣从 WADLogsTable table 获取最后 "x" 小时,您需要执行以下操作:

  • 将 date/time (UTC) 转换为报价。
  • 在他们前面添加 0
  • PartitionKey 的查询中使用这些。假设您使用的是 REST API,查询将类似于:

(PartitionKey ge 'from date/time ticks with prepended zero' and PartitionKey le 'to date/time ticks with prepended zero')

要按角色或角色实例进一步过滤,您可以添加适当的过滤条件。例如:

(PartitionKey ge 'from date/time ticks with prepended zero' and PartitionKey le 'to date/time ticks with prepended zero') and (Role eq 'Role Name')

很久以前我写了一篇博客post,你可能会觉得有用:http://gauravmantri.com/2012/02/17/effective-way-of-fetching-diagnostics-data-from-windows-azure-diagnostics-table-hint-use-partitionkey/(注意:显示存储客户端库使用的代码是基于旧版本的库,所以您可能只想将其用于理解目的。