假设我想要获取给定云服务最后 24 小时的 WADLogsTable 日志,可能会缩小到给定角色,甚至进一步缩小到给定实例。查询是什么样的?有没有高级 API 可以实现?
最佳答案
因此,没有专门用于查询诊断数据的 API。由于诊断数据存储在 Azure 表中,因此您只需查询表即可获取所需数据。
您会注意到的一件事是,这些表中的 PartitionKey
表示以刻度表示的时间(四舍五入到最接近的分钟)。如果您有兴趣从 WADLogsTable
表中获取最后“x”个小时,您需要执行以下操作:
- 将起始日期/时间 (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')
我很久以前写过一篇博文,您可能会觉得有用:http://gauravmantri.com/2012/02/17/effective-way-of-fetching-diagnostics-data-from-windows-azure-diagnostics-table-hint-use-partitionkey/ (注意:显示存储客户端库使用的代码基于该库的旧版本,因此您可能只想将其用于理解目的)。
关于azure - 如何按云服务、角色、角色实例查询WADLogsTable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27736888/