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
The `query` API returns the `LogsQueryResult` while the `batch_query` API returns list of `LogsQueryResult`. Here's a hierarchy of the response:
143
+
The `query` API returns a union of `LogsQueryResult`and `LogsQueryPartialResult`while the `batch_query` API returns list of `LogsQueryResult`, `LogsQueryPartialResult` and `LogsQueryError` objects. Here's a hierarchy of the response:
142
144
143
145
```
144
146
LogsQueryResult
145
147
|---statistics
146
148
|---visualization
147
-
|---error
148
149
|---tables (list of `LogsTable` objects)
149
150
|---name
150
151
|---rows
151
-
|---columns (list of `LogsTableColumn` objects)
152
-
|---name
153
-
|---type
152
+
|---columns
153
+
|---column_types
154
+
155
+
156
+
LogsQueryPartialResult
157
+
|---statistics
158
+
|---visualization
159
+
|---partial_error (a `LogsQueryError` object)
160
+
|---partial_data (list of `LogsTable` objects)
161
+
|---name
162
+
|---rows
163
+
|---columns
164
+
|---column_types
154
165
```
155
166
167
+
The `LogsQueryResult` directly iterates over the table as a convinience.
156
168
For example, to handle a logs query response with tables and display it using pandas:
157
169
158
170
```python
159
-
table = response.tables[0]
160
-
df = pd.DataFrame(table.rows, columns=[col.name for col in table.columns])
171
+
response = client.query(...)
172
+
for table in response:
173
+
df = pd.DataFrame(table.rows, columns=[col.name for col in table.columns])
161
174
```
162
175
163
-
A full sample can be found [here](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/sample_log_query_client.py).
176
+
A full sample can be found [here](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/sample_logs_single_query.py).
164
177
165
178
In a similar fashion, to handle a batch logs query response:
166
179
167
180
```python
168
181
for result in response:
169
-
table = result.tables[0]
170
-
df = pd.DataFrame(table.rows, columns=[col.name for col in table.columns])
A full sample can be found [here](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/sample_batch_query.py).
@@ -178,41 +193,51 @@ The following example demonstrates sending multiple queries at the same time usi
178
193
179
194
```python
180
195
import os
181
-
from datetime import timedelta
196
+
from datetime import timedelta, datetime, timezone
182
197
import pandas as pd
183
-
from azure.monitor.query import LogsQueryClient, LogsQueryRequest
198
+
from azure.monitor.query import LogsQueryClient, LogsBatchQuery, LogsQueryStatus
184
199
from azure.identity import DefaultAzureCredential
185
200
186
201
credential = DefaultAzureCredential()
187
202
client = LogsQueryClient(credential)
188
-
189
203
requests = [
190
204
LogsBatchQuery(
191
205
query="AzureActivity | summarize count()",
192
206
timespan=timedelta(hours=1),
193
-
workspace_id=os.environ['LOG_WORKSPACE_ID']
207
+
workspace_id=os.environ['LOG_WORKSPACE_ID']
194
208
),
195
209
LogsBatchQuery(
196
-
query="""AppRequests | take 10 |
197
-
summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""",
2. From the **Overview** blade, select the **JSON View** link.
272
298
3. In the resulting JSON, copy the value of the `id` property.
273
299
300
+
**NOTE**: The metrics are returned in the order of the metric_names sent.
301
+
274
302
```python
275
303
import os
276
-
from datetime import timedelta
304
+
from datetime import timedelta, datetime
277
305
from azure.monitor.query import MetricsQueryClient
278
306
from azure.identity import DefaultAzureCredential
279
307
@@ -367,6 +395,27 @@ Optional keyword arguments can be passed in at the client and per-operation leve
367
395
368
396
To learn more about Azure Monitor, see the [Azure Monitor service documentation][azure_monitor_overview].
369
397
398
+
### Samples
399
+
These code samples show common champion scenario operations with the Azure Monitor Query client library.
400
+
401
+
* Send a single query with LogsQueryClient and handle the response as a table: [sample_logs_single_query.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/sample_logs_single_query.py) ([async_sample](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/async_samples/sample_log_query_async.py))
402
+
403
+
* Send a single query with LogsQueryClient and handle the response in key value form: [sample_logs_query_key_value_form.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/sample_logs_query_key_value_form.py)
404
+
405
+
* Send a single query with LogsQueryClient without pandas: [sample_single_log_query_without_pandas.py.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/sample_single_log_query_without_pandas.py)
406
+
407
+
* Send a single query with LogsQueryClient across multiple workspaces: [sample_logs_query_multiple_workspaces.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/sample_log_query_multiple_workspaces.py)
408
+
409
+
* Send multiple queries with LogsQueryClient: [sample_batch_query.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/sample_batch_query.py)
410
+
411
+
* Send a single query with LogsQueryClient using server timeout: [sample_server_timeout.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/sample_server_timeout.py)
412
+
413
+
* Send a query using MetricsQueryClient: [sample_metrics_query.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/sample_metrics_query.py) ([async_sample](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/async_samples/sample_metrics_query_async.py))
414
+
415
+
* Get a list of metric namespaces: [sample_metric_namespaces.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/sample_metric_namespaces.py) ([async_sample](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/async_samples/sample_metric_namespaces_async.py))
416
+
417
+
* Get a list of metric definitions: [sample_metric_definitions.py](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/sample_metric_definitions.py) ([async_sample](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/monitor/azure-monitor-query/samples/async_samples/sample_metric_definitions_async.py))
418
+
370
419
## Contributing
371
420
372
421
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].
0 commit comments