forked from Azure/azure-sdk-for-python
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove responses and return a list (Azure#19872)
* Remove responses and return a list * lint * Sample to fetch response in key-value form * fix test * Update sdk/monitor/azure-monitor-query/tests/test_logs_client.py * Update sdk/monitor/azure-monitor-query/tests/test_logs_client.py * flay * skip Azure#19917
- Loading branch information
Rakshith Bhyravabhotla
authored
Jul 26, 2021
1 parent
54d0b9a
commit a8fd00b
Showing
10 changed files
with
90 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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
51 changes: 51 additions & 0 deletions
51
sdk/monitor/azure-monitor-query/samples/sample_logs_query_key_value_form.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import os | ||
import pandas as pd | ||
from datetime import datetime, timedelta | ||
from msrest.serialization import UTC | ||
from azure.monitor.query import LogsQueryClient | ||
from azure.identity import DefaultAzureCredential | ||
|
||
credential = DefaultAzureCredential() | ||
client = LogsQueryClient(credential) | ||
|
||
# Response time trend | ||
# request duration over the last 12 hours. | ||
query = """AppRequests | | ||
summarize avgRequestDuration=avg(DurationMs) by bin(TimeGenerated, 10m), _ResourceId""" | ||
|
||
end_time = datetime.now(UTC()) | ||
|
||
# returns LogsQueryResults | ||
response = client.query(os.environ['LOG_WORKSPACE_ID'], query, duration=timedelta(days=1), end_time=end_time) | ||
|
||
if not response.tables: | ||
print("No results for the query") | ||
|
||
for table in response.tables: | ||
pd.json_normalize | ||
df = pd.DataFrame(table.rows, columns=[col.name for col in table.columns]) | ||
key_value = df.to_dict(orient='records') | ||
print(key_value) | ||
|
||
""" | ||
[ | ||
{ | ||
'TimeGenerated': '2021-07-21T04:40:00Z', | ||
'_ResourceId': '/subscriptions/faa080af....', | ||
'avgRequestDuration': 19.7987 | ||
}, | ||
{ | ||
'TimeGenerated': '2021-07-21T04:50:00Z', | ||
'_ResourceId': '/subscriptions/faa08....', | ||
'avgRequestDuration': 33.9654 | ||
}, | ||
{ | ||
'TimeGenerated': '2021-07-21T05:00:00Z', | ||
'_ResourceId': '/subscriptions/faa080....', | ||
'avgRequestDuration': 44.13115 | ||
} | ||
] | ||
""" |
This file contains 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 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