-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Readme and xmlk docs for Azure.Monitor.Query #20731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pakrym
merged 9 commits into
Azure:master
from
pakrym:pakrym/Readme-and-docs-for-Azure-Monitor-Query
Apr 29, 2021
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
33ae638
Readme and docs for Azure.Monitor.Query
pakrym 3a96faa
auth
pakrym c792909
TS
pakrym 09a63df
en-us
pakrym dc090bc
A
pakrym b556c32
Apply suggestions from code review
pakrym a2175b5
Update sdk/monitor/Azure.Monitor.Query/src/Models/LogsBatchQuery.cs
pakrym 57bcbd4
more fb
pakrym cb59368
readme
pakrym File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,62 @@ | ||
| # Azure Monitor Query client library for .NET | ||
|
|
||
| TODO | ||
| The `Azure.Monitor.Query` package provides an ability to query [Azure Monitor Logs](https://docs.microsoft.com/azure/azure-monitor/logs/data-platform-logs) and [Azure Monitor Metrics](https://docs.microsoft.com/azure/azure-monitor/essentials/data-platform-metrics) data. | ||
|
|
||
| [Azure Monitor Logs](https://docs.microsoft.com/azure/azure-monitor/logs/data-platform-logs) is a feature of Azure Monitor that collects and organizes log and performance data from monitored resources. Data from different sources such as platform logs from Azure services, log and performance data from virtual machines agents, and usage and performance data from applications can be consolidated into a single workspace so they can be analyzed together using a sophisticated query language that's capable of quickly analyzing millions of records. | ||
|
|
||
| ## Samples | ||
| [Azure Monitor Metrics](https://docs.microsoft.com/azure/azure-monitor/essentials/data-platform-metrics) is a feature of Azure Monitor that collects numeric data from monitored resources into a time series database. Metrics are numerical values that are collected at regular intervals and describe some aspect of a system at a particular time. Metrics in Azure Monitor are lightweight and capable of supporting near real-time scenarios making them particularly useful for alerting and fast detection of issues. | ||
|
|
||
| [Source code][query_client_src] | [Package (NuGet)][query_client_nuget_package] | ||
|
|
||
| ## Getting started | ||
|
|
||
| ### Install the package | ||
| Install the Azure Monitor Query client library for .NET with [NuGet][query_client_nuget_package]: | ||
|
|
||
| ``` | ||
| dotnet add package Azure.Monitor.Query --prerelease | ||
| ``` | ||
|
|
||
| ### Prerequisites | ||
| * An [Azure subscription][azure_sub]. | ||
| * To be able to query logs you would need an existing Log Analytics workspace. You can create it in one of the following approaches: | ||
| * [Azure Portal](https://docs.microsoft.com/azure/azure-monitor/logs/quick-create-workspace) | ||
| * [Azure CLI](https://docs.microsoft.com/azure/azure-monitor/logs/quick-create-workspace-cli) | ||
| * [PowerShell](https://docs.microsoft.com/azure/azure-monitor/logs/powershell-workspace-configuration) | ||
|
|
||
| * To be able to query metrics all you need is an Azure resource of any kind (Storage Account, KeyVault, CosmosDB etc.) | ||
|
|
||
| ### Authenticate the Client | ||
|
|
||
| In order to interact with the Azure Monitor service, you will need to create an instance of a [TokenCredential](https://docs.microsoft.com/dotnet/api/azure.core.tokencredential?view=azure-dotnet) class and pass it to the constructor of your `LogsClient` or `MetricsClient` class. | ||
|
|
||
| ## Key concepts | ||
|
|
||
| - `LogsClient` - Client that provides methods to query logs from Azure Monitor Logs. | ||
| - `MetricsClient` - Client that provides methods to query metrics from Azure Monitor Metrics. | ||
|
|
||
| ### Thread safety | ||
| We guarantee that all client instance methods are thread-safe and independent of each other ([guideline](https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-service-methods-thread-safety)). This ensures that the recommendation of reusing client instances is always safe, even across threads. | ||
|
|
||
| ### Additional concepts | ||
| <!-- CLIENT COMMON BAR --> | ||
| [Client options](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#configuring-service-clients-using-clientoptions) | | ||
| [Accessing the response](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#accessing-http-response-details-using-responset) | | ||
| [Long-running operations](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#consuming-long-running-operations-using-operationt) | | ||
| [Handling failures](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#reporting-errors-requestfailedexception) | | ||
| [Diagnostics](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Diagnostics.md) | | ||
| [Mocking](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/README.md#mocking) | | ||
| [Client lifetime](https://devblogs.microsoft.com/azure-sdk/lifetime-management-and-thread-safety-guarantees-of-azure-sdk-net-clients/) | ||
| <!-- CLIENT COMMON BAR --> | ||
|
|
||
| ## Examples | ||
|
|
||
| - [Query logs](#query-logs) | ||
| - [Query logs as model](#query-logs-as-model) | ||
| - [Query logs as primitive](#query-logs-as-primitive) | ||
| - [Batch query](#batch-query) | ||
| - [Query dynamic table](#query-dynamic-table) | ||
| - [Increase query timeout](#increase-query-timeout) | ||
|
|
||
| ### Query logs | ||
|
|
||
|
|
@@ -92,7 +145,7 @@ foreach (var logEntryModel in topEntries) | |
| } | ||
| ``` | ||
|
|
||
| ### Query dynamic table | ||
| ### Query dynamic table | ||
|
|
||
| You can also dynamically inspect the list of columns. The following example prints the result of the query as a table: | ||
|
|
||
|
|
@@ -120,4 +173,104 @@ foreach (var row in table.Rows) | |
|
|
||
| Console.WriteLine(); | ||
| } | ||
| ``` | ||
| ``` | ||
|
|
||
| ### Increase query timeout | ||
|
|
||
| Some queries take longer to execute than the default service timeout allows. You can use the `LogsQueryOptions` parameter to specify the service timeout. | ||
|
|
||
| ```C# Snippet:QueryLogsPrintTable | ||
| LogsClient client = new LogsClient(new DefaultAzureCredential()); | ||
| string workspaceId = "<workspace_id>"; | ||
| Response<LogsQueryResult> response = await client.QueryAsync(workspaceId, "AzureActivity | top 10 by TimeGenerated"); | ||
|
|
||
| LogsQueryResultTable table = response.Value.PrimaryTable; | ||
|
|
||
| foreach (var column in table.Columns) | ||
| { | ||
| Console.Write(column.Name + ";"); | ||
| } | ||
|
|
||
| Console.WriteLine(); | ||
|
|
||
| var columnCount = table.Columns.Count; | ||
| foreach (var row in table.Rows) | ||
| { | ||
| for (int i = 0; i < columnCount; i++) | ||
| { | ||
| Console.Write(row[i] + ";"); | ||
| } | ||
|
|
||
| Console.WriteLine(); | ||
| } | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### General | ||
|
|
||
| When you interact with the Azure Monitor Query client library using the .NET SDK, errors returned by the service correspond to the same HTTP status codes returned for [REST API][monitor_rest_api] requests. | ||
|
|
||
| For example, if you submit an invalid query a `400` error is returned, indicating "Bad Request". | ||
|
|
||
| ```C# Snippet:BadRequest | ||
| string workspaceId = "<workspace_id>"; | ||
| LogsClient client = new LogsClient(new DefaultAzureCredential()); | ||
| try | ||
| { | ||
| await client.QueryAsync(workspaceId, "My Not So Valid Query"); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| Console.WriteLine(e); | ||
| throw; | ||
| } | ||
| ``` | ||
|
|
||
| The exception also contains some additional information like the full error content. | ||
|
|
||
| ``` | ||
| Azure.RequestFailedException : The request had some invalid properties | ||
| Status: 400 (Bad Request) | ||
| ErrorCode: BadArgumentError | ||
|
|
||
| Content: | ||
| {"error":{"message":"The request had some invalid properties","code":"BadArgumentError","correlationId":"34f5f93a-6007-48a4-904f-487ca4e62a82","innererror":{"code":"SyntaxError","message":"A recognition error occurred in the query.","innererror":{"code":"SYN0002","message":"Query could not be parsed at 'Not' on line [1,3]","line":1,"pos":3,"token":"Not"}}}} | ||
| ``` | ||
|
|
||
| ### Setting up console logging | ||
|
|
||
| The simplest way to see the logs is to enable the console logging. | ||
| To create an Azure SDK log listener that outputs messages to console use AzureEventSourceListener.CreateConsoleLogger method. | ||
|
|
||
| ```C# | ||
| // Setup a listener to monitor logged events. | ||
| using AzureEventSourceListener listener = AzureEventSourceListener.CreateConsoleLogger(); | ||
| ``` | ||
|
|
||
| To learn more about other logging mechanisms see [here][logging]. | ||
|
|
||
| ## Next steps | ||
|
|
||
| ## Contributing | ||
|
|
||
| This project welcomes contributions and suggestions. Most contributions require | ||
| you to agree to a Contributor License Agreement (CLA) declaring that you have | ||
| the right to, and actually do, grant us the rights to use your contribution. For | ||
| details, visit [cla.microsoft.com][cla]. | ||
|
|
||
| This project has adopted the [Microsoft Open Source Code of Conduct][coc]. | ||
| For more information see the [Code of Conduct FAQ][coc_faq] or contact | ||
| [[email protected]][coc_contact] with any additional questions or comments. | ||
|
|
||
| [query_client_src]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/monitor/Azure.Monitor.Query/src | ||
| [query_client_nuget_package]: https://www.nuget.org/packages?q=Azure.Monitor.Query | ||
| [monitor_rest_api]: https://docs.microsoft.com/rest/api/monitor/ | ||
| [azure_cli]: https://docs.microsoft.com/cli/azure | ||
| [azure_sub]: https://azure.microsoft.com/free/ | ||
| [cla]: https://cla.microsoft.com | ||
| [coc]: https://opensource.microsoft.com/codeofconduct/ | ||
| [coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ | ||
| [coc_contact]: mailto:[email protected] | ||
|
|
||
|  | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we say what the default is rather than the default value of the type? For example,
Defaults to the HttpClient default ...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an interesting question. I was trying to avoid presuming what service does as it might change with the service version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would someone know what to set this to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Their query would fail. No matter whether we give them a default value or not they need to see their query timing out to start setting this value.