You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#### Configure clients for non-public Azure clouds
70
+
#### Configure client for Azure sovereign cloud
72
71
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:
74
73
75
74
```python
76
75
from azure.identity import AzureAuthorityHosts, DefaultAzureCredential
**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.
88
86
89
87
### Execute the query
90
88
@@ -96,7 +94,7 @@ For examples of Logs and Metrics queries, see the [Examples](#examples) section.
96
94
97
95
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).
98
96
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`.
100
98
101
99
### Metrics data structure
102
100
@@ -107,7 +105,7 @@ Each set of metric values is a time series with the following characteristics:
107
105
- A namespace that acts like a category for the metric
108
106
- A metric name
109
107
- 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.
111
109
112
110
## Examples
113
111
@@ -124,15 +122,15 @@ Each set of metric values is a time series with the following characteristics:
-[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)
128
126
129
127
### Logs query
130
128
131
129
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`.
132
130
133
131
#### Specify timespan
134
132
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:
136
134
137
135
- a `timedelta`
138
136
- a `timedelta` and a start `datetime`
@@ -178,7 +176,7 @@ except HttpResponseError as err:
178
176
179
177
#### Handle logs query response
180
178
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:
182
180
183
181
```
184
182
LogsQueryResult
@@ -282,7 +280,7 @@ for res in results:
282
280
283
281
### Resource logs query
284
282
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}`.
The same logs query can be executed across multiple Log Analytics workspaces. In addition to the Kusto query, the following parameters are required:
342
340
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:
345
343
- Qualified workspace names
346
344
- Workspace IDs
347
345
- Azure resource IDs
@@ -459,7 +457,7 @@ To find the resource ID/URI:
459
457
1. Select the **JSON View** link in the **Overview** section.
460
458
1. Copy the value in the **Resource ID** text box at the top of the JSON view.
461
459
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.
463
461
464
462
```python
465
463
import os
@@ -536,12 +534,19 @@ for metric in response.metrics:
536
534
)
537
535
```
538
536
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".
540
543
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:
542
545
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.
544
548
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].
0 commit comments