Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
"""
FILE: sample_logs_single_query_async.py
DESCRIPTION:
This sample demonstrates authenticating the LogsQueryClient and querying a single query.
This sample demonstrates authenticating the LogsQueryClient and executing a single
Kusto query.
USAGE:
python sample_logs_single_query_async.py
Set the environment variables with your own values before running the sample:
1) LOGS_WORKSPACE_ID - The first (primary) workspace ID.

In order to use the DefaultAzureCredential, the following environment variables must be set:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR updated per our discussion.

1) AZURE_CLIENT_ID - The client ID of a user-assigned managed identity.
2) AZURE_TENANT_ID - Tenant ID to use when authenticating a user.
3) AZURE_CLIENT_ID - The client secret to be used for authentication.

**Note** - Although this example uses pandas to prin the response, it is totally optional and is
not a required package for querying. Alternatively, native python can be used as well.
**Note** - Although this example uses pandas to print the response, it's optional and
isn't a required package for querying. Alternatively, native Python can be used as well.
"""
import asyncio
import os
Expand All @@ -34,7 +30,7 @@ async def logs_query():
query= """AppRequests | take 5"""

try:
response = await client.query_workspace(os.environ['LOG_WORKSPACE_ID'], query, timespan=timedelta(days=1))
response = await client.query_workspace(os.environ['LOGS_WORKSPACE_ID'], query, timespan=timedelta(days=1))
if response.status == LogsQueryStatus.PARTIAL:
error = response.partial_error
data = response.partial_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
USAGE:
python sample_metric_definitions_async.py
Set the environment variables with your own values before running the sample:
1) METRICS_RESOURCE_URI - The resource uri of the resource for which the metrics are being queried.
In this example, an eventgrid account resource URI is taken.
1) METRICS_RESOURCE_URI - The resource URI of the resource for which the metrics are being queried.

In order to use the DefaultAzureCredential, the following environment variables must be set:
1) AZURE_CLIENT_ID - The client ID of a user-assigned managed identity.
2) AZURE_TENANT_ID - Tenant ID to use when authenticating a user.
3) AZURE_CLIENT_ID - The client secret to be used for authentication.
In this example, an Event Grid account resource URI is taken.
"""
import os
import asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
USAGE:
python sample_metric_namespaces_async.py
Set the environment variables with your own values before running the sample:
1) METRICS_RESOURCE_URI - The resource uri of the resource for which the metrics are being queried.
In this example, a storage account resource URI is taken.

In order to use the DefaultAzureCredential, the following environment variables must be set:
1) AZURE_CLIENT_ID - The client ID of a user-assigned managed identity.
2) AZURE_TENANT_ID - Tenant ID to use when authenticating a user.
3) AZURE_CLIENT_ID - The client secret to be used for authentication.
1) METRICS_RESOURCE_URI - The resource URI of the resource for which the metrics are being queried.

In this example, a Storage account resource URI is taken.
"""
import os
import asyncio
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
"""
FILE: sample_metrics_query_async.py
DESCRIPTION:
This sample demonstrates authenticating the LogsQueryClient and querying a single query
on multiple workspaces using the additional_workspaces param.
This sample demonstrates authenticating the MetricsQueryClient and retrieving the "Ingress"
metric along with the "Average" aggregation type. The query will execute over a timespan
of 2 hours with a granularity of 15 minutes.
USAGE:
python sample_metrics_query_async.py
Set the environment variables with your own values before running the sample:
1) METRICS_RESOURCE_URI - The resource uri of the resource for which the metrics are being queried.
In this example, a storage account resource URI is taken.
1) METRICS_RESOURCE_URI - The resource URI of the resource for which the metrics are being queried.

In order to use the DefaultAzureCredential, the following environment variables must be set:
1) AZURE_CLIENT_ID - The client ID of a user-assigned managed identity.
2) AZURE_TENANT_ID - Tenant ID to use when authenticating a user.
3) AZURE_CLIENT_ID - The client secret to be used for authentication.
In this example, a Storage account resource URI is taken.
"""
import os
import asyncio
Expand Down
16 changes: 5 additions & 11 deletions sdk/monitor/azure-monitor-query/samples/sample_batch_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@
Set the environment variables with your own values before running the sample:
1) LOGS_WORKSPACE_ID - The The first (primary) workspace ID.

In order to use the DefaultAzureCredential, the following environment variables must be set:
1) AZURE_CLIENT_ID - The client ID of a user-assigned managed identity.
2) AZURE_TENANT_ID - Tenant ID to use when authenticating a user.
3) AZURE_CLIENT_ID - The client secret to be used for authentication.

**Note** - Although this example uses pandas to prin the response, it is totally optional and is
not a required package for querying. Alternatively, native python can be used as well.
**Note** - Although this example uses pandas to print the response, it's optional and
isn't a required package for querying. Alternatively, native Python can be used as well.
"""

from datetime import datetime, timedelta, timezone
Expand All @@ -24,7 +19,6 @@
from azure.monitor.query import LogsQueryClient, LogsBatchQuery, LogsQueryStatus
from azure.identity import DefaultAzureCredential


credential = DefaultAzureCredential()

client = LogsQueryClient(credential)
Expand All @@ -34,18 +28,18 @@
LogsBatchQuery(
query="AzureActivity | summarize count()",
timespan=timedelta(hours=1),
workspace_id= os.environ['LOG_WORKSPACE_ID']
workspace_id= os.environ['LOGS_WORKSPACE_ID']
),
LogsBatchQuery(
query= """bad query""",
timespan=timedelta(days=1),
workspace_id= os.environ['LOG_WORKSPACE_ID']
workspace_id= os.environ['LOGS_WORKSPACE_ID']
),
LogsBatchQuery(
query= """let Weight = 92233720368547758;
range x from 1 to 3 step 1
| summarize percentilesw(x, Weight * 100, 50)""",
workspace_id= os.environ['LOG_WORKSPACE_ID'],
workspace_id= os.environ['LOGS_WORKSPACE_ID'],
timespan=(datetime(2021, 6, 2, tzinfo=timezone.utc), datetime(2021, 6, 5, tzinfo=timezone.utc)), # (start, end)
include_statistics=True
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@
1) LOGS_WORKSPACE_ID - The first (primary) workspace ID.
2) SECONDARY_WORKSPACE_ID - An additional workspace.

In order to use the DefaultAzureCredential, the following environment variables must be set:
1) AZURE_CLIENT_ID - The client ID of a user-assigned managed identity.
2) AZURE_TENANT_ID - Tenant ID to use when authenticating a user.
3) AZURE_CLIENT_ID - The client secret to be used for authentication.

**Note** - Although this example uses pandas to prin the response, it is totally optional and is
not a required package for querying. Alternatively, native python can be used as well.
**Note** - Although this example uses pandas to print the response, it's optional and
isn't a required package for querying. Alternatively, native Python can be used as well.
"""
import os
import pandas as pd
Expand All @@ -34,7 +29,7 @@

try:
response = client.query_workspace(
os.environ['LOG_WORKSPACE_ID'],
os.environ['LOGS_WORKSPACE_ID'],
query,
timespan=timedelta(days=1),
additional_workspaces=[os.environ['SECONDARY_WORKSPACE_ID']]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@
Set the environment variables with your own values before running the sample:
1) LOGS_WORKSPACE_ID - The first (primary) workspace ID.

In order to use the DefaultAzureCredential, the following environment variables must be set:
1) AZURE_CLIENT_ID - The client ID of a user-assigned managed identity.
2) AZURE_TENANT_ID - Tenant ID to use when authenticating a user.
3) AZURE_CLIENT_ID - The client secret to be used for authentication.

**Note** - Although this example uses pandas to prin the response, it is totally optional and is
not a required package for querying. Alternatively, native python can be used as well.
**Note** - Although this example uses pandas to print the response, it's optional and
isn't a required package for querying. Alternatively, native Python can be used as well.
"""
import os
import pandas as pd
Expand All @@ -33,7 +28,7 @@
query= """AppRequests | take 5"""

try:
response = client.query_workspace(os.environ['LOG_WORKSPACE_ID'], query, timespan=timedelta(days=1))
response = client.query_workspace(os.environ['LOGS_WORKSPACE_ID'], query, timespan=timedelta(days=1))
if response.status == LogsQueryStatus.PARTIAL:
error = response.partial_error
data = response.partial_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,8 @@
Set the environment variables with your own values before running the sample:
1) LOGS_WORKSPACE_ID - The first (primary) workspace ID.

In order to use the DefaultAzureCredential, the following environment variables must be set:
1) AZURE_CLIENT_ID - The client ID of a user-assigned managed identity.
2) AZURE_TENANT_ID - Tenant ID to use when authenticating a user.
3) AZURE_CLIENT_ID - The client secret to be used for authentication.

**Note** - Although this example uses pandas to prin the response, it is totally optional and is
not a required package for querying. Alternatively, native python can be used as well.
**Note** - Although this example uses pandas to print the response, it's optional and
isn't a required package for querying. Alternatively, native Python can be used as well.
"""
import os
import pandas as pd
Expand All @@ -34,7 +29,7 @@
query= """AppRequests | take 5"""

try:
response = client.query_workspace(os.environ['LOG_WORKSPACE_ID'], query, timespan=timedelta(days=1))
response = client.query_workspace(os.environ['LOGS_WORKSPACE_ID'], query, timespan=timedelta(days=1))
if response.status == LogsQueryStatus.PARTIAL:
error = response.partial_error
data = response.partial_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@
Set the environment variables with your own values before running the sample:
1) LOGS_WORKSPACE_ID - The first (primary) workspace ID.

In order to use the DefaultAzureCredential, the following environment variables must be set:
1) AZURE_CLIENT_ID - The client ID of a user-assigned managed identity.
2) AZURE_TENANT_ID - Tenant ID to use when authenticating a user.
3) AZURE_CLIENT_ID - The client secret to be used for authentication.

**Note** - Although this example uses pandas to prin the response, it is totally optional and is
not a required package for querying. Alternatively, native python can be used as well.
**Note** - Although this example uses pandas to print the response, it's optional and
isn't a required package for querying. Alternatively, native Python can be used as well.
"""
import os
import pandas as pd
Expand All @@ -37,7 +32,7 @@
# this block of code is exactly the same whether the expected result is a success, a failure or a
# partial success
try:
response = client.query_workspace(os.environ['LOG_WORKSPACE_ID'], query, timespan=timedelta(days=1))
response = client.query_workspace(os.environ['LOGS_WORKSPACE_ID'], query, timespan=timedelta(days=1))
if response.status == LogsQueryStatus.PARTIAL:
# handle error here
error = response.partial_error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
USAGE:
python sample_metric_definitions.py
Set the environment variables with your own values before running the sample:
1) METRICS_RESOURCE_URI - The resource uri of the resource for which the metrics are being queried.
In this example, an eventgrid account resource URI is taken.

In order to use the DefaultAzureCredential, the following environment variables must be set:
1) AZURE_CLIENT_ID - The client ID of a user-assigned managed identity.
2) AZURE_TENANT_ID - Tenant ID to use when authenticating a user.
3) AZURE_CLIENT_ID - The client secret to be used for authentication.
1) METRICS_RESOURCE_URI - The resource URI of the resource for which the metrics are being queried.

In this example, an Event Grid account resource URI is taken.
"""
import os
from azure.monitor.query import MetricsQueryClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
USAGE:
python sample_metric_namespaces.py
Set the environment variables with your own values before running the sample:
1) METRICS_RESOURCE_URI - The resource uri of the resource for which the metrics are being queried.
In this example, a storage account resource URI is taken.

In order to use the DefaultAzureCredential, the following environment variables must be set:
1) AZURE_CLIENT_ID - The client ID of a user-assigned managed identity.
2) AZURE_TENANT_ID - Tenant ID to use when authenticating a user.
3) AZURE_CLIENT_ID - The client secret to be used for authentication.
1) METRICS_RESOURCE_URI - The resource URI of the resource for which the metrics are being queried.

In this example, a Storage account resource URI is taken.
"""
import os
from azure.monitor.query import MetricsQueryClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
"""
FILE: sample_metrics_query.py
DESCRIPTION:
This sample demonstrates authenticating the LogsQueryClient and querying a single query
on multiple workspaces using the additional_workspaces param.
This sample demonstrates authenticating the MetricsQueryClient and retrieving the "Ingress"
metric along with the "Average" aggregation type. The query will execute over a timespan
of 2 hours with a granularity of 5 minutes.
USAGE:
python sample_metrics_query.py
Set the environment variables with your own values before running the sample:
1) METRICS_RESOURCE_URI - The resource uri of the resource for which the metrics are being queried.
In this example, a storage account resource URI is taken.

In order to use the DefaultAzureCredential, the following environment variables must be set:
1) AZURE_CLIENT_ID - The client ID of a user-assigned managed identity.
2) AZURE_TENANT_ID - Tenant ID to use when authenticating a user.
3) AZURE_CLIENT_ID - The client secret to be used for authentication.
In this example, a Storage account resource URI is taken.
"""
import os
from datetime import timedelta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
"""
FILE: sample_server_timeout.py
DESCRIPTION:
This sample demostrates how to update a server timeout for a long running query.
This sample demonstrates how to update a server timeout for a long running query.
USAGE:
python sample_server_timeout.py
Set the environment variables with your own values before running the sample:
1) LOGS_WORKSPACE_ID - The first (primary) workspace ID.

In order to use the DefaultAzureCredential, the following environment variables must be set:
1) AZURE_CLIENT_ID - The client ID of a user-assigned managed identity.
2) AZURE_TENANT_ID - Tenant ID to use when authenticating a user.
3) AZURE_CLIENT_ID - The client secret to be used for authentication.

**Note** - Although this example uses pandas to prin the response, it is totally optional and is
not a required package for querying. Alternatively, native python can be used as well.
**Note** - Although this example uses pandas to print the response, it's optional and
isn't a required package for querying. Alternatively, native Python can be used as well.
"""
import os
import pandas as pd
Expand All @@ -32,7 +27,7 @@

try:
response = client.query_workspace(
os.environ['LOG_WORKSPACE_ID'],
os.environ['LOGS_WORKSPACE_ID'],
query,
timespan=timedelta(days=1),
server_timeout=3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
python sample_single_log_query_without_pandas.py
Set the environment variables with your own values before running the sample:
1) LOGS_WORKSPACE_ID - The first (primary) workspace ID.

In order to use the DefaultAzureCredential, the following environment variables must be set:
1) AZURE_CLIENT_ID - The client ID of a user-assigned managed identity.
2) AZURE_TENANT_ID - Tenant ID to use when authenticating a user.
3) AZURE_CLIENT_ID - The client secret to be used for authentication.
"""
import os
from datetime import timedelta
Expand All @@ -27,9 +22,8 @@

query= """AppRequests | take 5"""


try:
response = client.query_workspace(os.environ['LOG_WORKSPACE_ID'], query, timespan=timedelta(days=1))
response = client.query_workspace(os.environ['LOGS_WORKSPACE_ID'], query, timespan=timedelta(days=1))
if response.status == LogsQueryStatus.PARTIAL:
# handle error here
error = response.partial_error
Expand Down