Skip to content

Commit ed7cbc7

Browse files
authored
Edit pass on Monitor Query README (#34864)
1 parent b8ec1af commit ed7cbc7

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

sdk/monitor/azure-monitor-query/README.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ async_logs_query_client = LogsQueryClient(credential)
6666
async_metrics_query_client = MetricsQueryClient(credential)
6767
async_metrics_client = MetricsClient("https://<regional endpoint>", credential)
6868
```
69-
```
7069

71-
#### Configure clients for non-public Azure clouds
70+
#### Configure client for Azure sovereign cloud
7271

73-
By default, `LogsQueryClient` and `MetricsQueryClient` are configured to connect to the public Azure cloud. These can be configured to connect to non-public Azure clouds by passing in the correct `endpoint` argument: For example:
72+
By default, `LogsQueryClient` and `MetricsQueryClient` are configured to use the Azure Public Cloud. To use a sovereign cloud instead, provide the correct `endpoint` argument. For example:
7473

7574
```python
7675
from azure.identity import AzureAuthorityHosts, DefaultAzureCredential
@@ -81,10 +80,9 @@ credential = DefaultAzureCredential(authority=AzureAuthorityHosts.AZURE_GOVERNME
8180

8281
logs_query_client = LogsQueryClient(credential, endpoint="https://api.loganalytics.us/v1")
8382
metrics_query_client = MetricsQueryClient(credential, endpoint="https://management.usgovcloudapi.net")
84-
8583
```
8684

87-
**Note**: Currently, `MetricsQueryClient` uses the Azure Resource Manager (ARM) endpoint for querying metrics, so you will need the corresponding management endpoint for your cloud when using this client. This is subject to change in the future.
85+
**Note**: Currently, `MetricsQueryClient` uses the Azure Resource Manager (ARM) endpoint for querying metrics. You need the corresponding management endpoint for your cloud when using this client. This detail is subject to change in the future.
8886

8987
### Execute the query
9088

@@ -96,7 +94,7 @@ For examples of Logs and Metrics queries, see the [Examples](#examples) section.
9694

9795
The Log Analytics service applies throttling when the request rate is too high. Limits, such as the maximum number of rows returned, are also applied on the Kusto queries. For more information, see [Query API](https://learn.microsoft.com/azure/azure-monitor/service-limits#la-query-api).
9896

99-
If you're executing a batch logs query, a throttled request will return a `LogsQueryError` object. That object's `code` value will be `ThrottledError`.
97+
If you're executing a batch logs query, a throttled request returns a `LogsQueryError` object. That object's `code` value is `ThrottledError`.
10098

10199
### Metrics data structure
102100

@@ -107,7 +105,7 @@ Each set of metric values is a time series with the following characteristics:
107105
- A namespace that acts like a category for the metric
108106
- A metric name
109107
- The value itself
110-
- Some metrics may have multiple dimensions as described in multi-dimensional metrics. Custom metrics can have up to 10 dimensions.
108+
- Some metrics have multiple dimensions as described in multi-dimensional metrics. Custom metrics can have up to 10 dimensions.
111109

112110
## Examples
113111

@@ -124,15 +122,15 @@ Each set of metric values is a time series with the following characteristics:
124122
- [Metrics query](#metrics-query)
125123
- [Handle metrics query response](#handle-metrics-query-response)
126124
- [Example of handling response](#example-of-handling-response)
127-
- [Metrics batch query](#metrics-batch-query)
125+
- [Query metrics for multiple resources](#query-metrics-for-multiple-resources)
128126

129127
### Logs query
130128

131129
This example shows how to query a Log Analytics workspace. To handle the response and view it in a tabular form, the [`pandas`](https://pypi.org/project/pandas/) library is used. See the [samples][samples] if you choose not to use `pandas`.
132130

133131
#### Specify timespan
134132

135-
The `timespan` parameter specifies the time duration for which to query the data. This value can be one of the following:
133+
The `timespan` parameter specifies the time duration for which to query the data. This value can take one of the following forms:
136134

137135
- a `timedelta`
138136
- a `timedelta` and a start `datetime`
@@ -178,7 +176,7 @@ except HttpResponseError as err:
178176

179177
#### Handle logs query response
180178

181-
The `query_workspace` API returns either a `LogsQueryResult` or a `LogsQueryPartialResult` object. The `batch_query` API returns a list that may contain `LogsQueryResult`, `LogsQueryPartialResult`, and `LogsQueryError` objects. Here's a hierarchy of the response:
179+
The `query_workspace` API returns either a `LogsQueryResult` or a `LogsQueryPartialResult` object. The `batch_query` API returns a list that can contain `LogsQueryResult`, `LogsQueryPartialResult`, and `LogsQueryError` objects. Here's a hierarchy of the response:
182180

183181
```
184182
LogsQueryResult
@@ -282,7 +280,7 @@ for res in results:
282280

283281
### Resource logs query
284282

285-
The following example demonstrates how to query logs directly from an Azure resource without the use of a Log Analytics workspace. Here, the `query_resource` method is used instead of `query_workspace`, and instead of a workspace ID, an Azure resource identifier is passed in (e.g. `/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider}/{resource-type}/{resource-name}`).
283+
The following example demonstrates how to query logs directly from an Azure resource without the use of a Log Analytics workspace. Here, the `query_resource` method is used instead of `query_workspace`. Instead of a workspace ID, an Azure resource identifier is passed in. For example, `/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/{resource-provider}/{resource-type}/{resource-name}`.
286284

287285
```python
288286
import os
@@ -340,8 +338,8 @@ response = client.query_workspace(
340338

341339
The same logs query can be executed across multiple Log Analytics workspaces. In addition to the Kusto query, the following parameters are required:
342340

343-
- `workspace_id` - The first (primary) workspace ID.
344-
- `additional_workspaces` - A list of workspaces, excluding the workspace provided in the `workspace_id` parameter. The parameter's list items may consist of the following identifier formats:
341+
- `workspace_id` - The first (primary) workspace ID
342+
- `additional_workspaces` - A list of workspaces, excluding the workspace provided in the `workspace_id` parameter. The parameter's list items can consist of the following identifier formats:
345343
- Qualified workspace names
346344
- Workspace IDs
347345
- Azure resource IDs
@@ -459,7 +457,7 @@ To find the resource ID/URI:
459457
1. Select the **JSON View** link in the **Overview** section.
460458
1. Copy the value in the **Resource ID** text box at the top of the JSON view.
461459

462-
**NOTE**: The metrics are returned in the order of the metric_names sent.
460+
**NOTE**: The metrics are returned in the order of the `metric_names` sent.
463461

464462
```python
465463
import os
@@ -536,12 +534,19 @@ for metric in response.metrics:
536534
)
537535
```
538536

539-
### Metrics batch query
537+
#### Query metrics for multiple resources
538+
539+
To query metrics for multiple Azure resources in a single request, use the `query_resources` method of `MetricsClient`. This method:
540+
541+
- Calls a different API than the `MetricsQueryClient` methods.
542+
- Requires a regional endpoint when creating the client. For example, "https://westus3.metrics.monitor.azure.com".
540543

541-
A user can also query metrics from multiple resources at once using the `query_resources` method of `MetricsClient`. This uses a different API than the `MetricsQueryClient` and requires that a user pass in a regional endpoint when instantiating the client (for example, "https://westus3.metrics.monitor.azure.com").
544+
Each Azure resource must reside in:
542545

543-
Note, each resource must be in the same region as the endpoint passed in when instantiating the client, and each resource must be in the same Azure subscription. Furthermore, the metric namespace that contains the metrics to be queried must also be passed. A list of metric namespaces can be found [here][metric_namespaces].
546+
- The same region as the endpoint specified when creating the client.
547+
- The same Azure subscription.
544548

549+
Furthermore, the metric namespace containing the metrics to be queried must be provided. For a list of metric namespaces, see [Supported metrics and log categories by resource type][metric_namespaces].
545550

546551
```python
547552
from datetime import timedelta

0 commit comments

Comments
 (0)