Search code examples
azureloggingazure-diagnostics

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


Say I want to fetch WADLogsTable logs for last 24h of a given cloud service, perhaps narrow down to a given role, and even further down to a given instance. What does the query look like? Is there any high level api for that?


Solution

  • As such there is no API specific for querying diagnostics data. Because diagnostics data is stored in Azure Tables, you can simply query the table to fetch the desired data.

    One thing you would notice is that PartitionKey in these tables represent time (rounded to nearest minute) represented in ticks. If you're interested in fetching last "x" hours from WADLogsTable table, here's what you would need to do:

    • Convert from and to date/time (UTC) into ticks.
    • Prepend 0 in front of them.
    • Use these in query on PartitionKey. Assuming you're using REST API, the query would look something like:

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

    To further filter down by role or role instance, you would add appropriate filter criteria. For example:

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

    I wrote a blog post long time back which you may find useful: http://gauravmantri.com/2012/02/17/effective-way-of-fetching-diagnostics-data-from-windows-azure-diagnostics-table-hint-use-partitionkey/ (Caution: The code showing the use of storage client library is based on the older version of the library, so you may want to use that only for understanding purpose).