azure.monitor.query.aio package¶
-
class
azure.monitor.query.aio.
LogsQueryClient
(credential: AsyncTokenCredential, **kwargs: Any)[source]¶ LogsQueryClient. Use this client to collect and organize log and performance data from monitored resources. Data from different sources such as platform logs from Azure services, log and performance data from virtual machines agents, and usage and performance data from apps can be consolidated into a single Azure Log Analytics workspace.
The various data types can be analyzed together using the [Kusto Query Language](https://docs.microsoft.com/azure/data-explorer/kusto/query/)
- Parameters
credential (AsyncTokenCredential) – The credential to authenticate the client
- Keyword Arguments
endpoint (str) – The endpoint to connect to. Defaults to ‘https://api.loganalytics.io/v1’.
-
async
close
() → None[source]¶ Close the
LogsQueryClient
session.
-
async
query_batch
(queries: Union[Sequence[Dict], Sequence[azure.monitor.query._models.LogsBatchQuery]], **kwargs: Any) → List[Union[azure.monitor.query._models.LogsQueryResult, azure.monitor.query._exceptions.LogsQueryError, azure.monitor.query._models.LogsQueryPartialResult]][source]¶ Execute a list of analytics queries. Each request can be either a LogsBatchQuery object or an equivalent serialized model.
NOTE: The response is returned in the same order as that of the requests sent.
- Parameters
queries (list[dict] or list[LogsBatchQuery]) – The list of Kusto queries to execute.
- Returns
List of LogsQueryResult, LogsQueryPartialResult and LogsQueryError. For a given query, a LogsQueryResult is returned if the response is a success, LogsQueryPartialResult is returned when there is a partial success and a LogsQueryError is returned when there is a failure. The status of each response can be checked using LogsQueryStatus enum.
- Return type
list[LogsQueryResult or LogsQueryPartialResult or LogsQueryError]
- Raises
~azure.core.exceptions.HttpResponseError
-
async
query_workspace
(workspace_id: str, query: str, *, timespan: Union[datetime.timedelta, Tuple[datetime.datetime, datetime.timedelta], Tuple[datetime.datetime, datetime.datetime]], **kwargs: Any) → Union[azure.monitor.query._models.LogsQueryResult, azure.monitor.query._models.LogsQueryPartialResult][source]¶ Execute an Analytics query.
Executes an Analytics query for data.
- Parameters
workspace_id (str) – ID of the workspace. This is Workspace ID from the Properties blade in the Azure portal.
query (str) – The Kusto query. Learn more about the Kusto query syntax.
- Keyword Arguments
timespan (timedelta or tuple[datetime, timedelta] or tuple[datetime, datetime]) – Required. The timespan for which to query the data. This can be a timedelta, a timedelta and a start datetime, or a start datetime/end datetime.
server_timeout (int) – the server timeout in seconds. The default timeout is 3 minutes, and the maximum timeout is 10 minutes.
include_statistics (bool) – To get information about query statistics.
include_visualization (bool) – In the query language, it is possible to specify different visualization options. By default, the API does not return information regarding the type of visualization to show. If your client requires this information, specify the preference
additional_workspaces (list[str]) – A list of workspaces that are included in the query. These can be qualified workspace names, workspace Ids, or Azure resource Ids.
- Returns
LogsQueryResult if there is a success or LogsQueryPartialResult when there is a partial success.
- Return type
- Raises
~azure.core.exceptions.HttpResponseError
-
class
azure.monitor.query.aio.
MetricsQueryClient
(credential: AsyncTokenCredential, **kwargs: Any)[source]¶ - Parameters
credential (TokenCredential) – The credential to authenticate the client
- Keyword Arguments
endpoint (str) – The endpoint to connect to. Defaults to ‘https://management.azure.com’.
-
async
close
() → None[source]¶ Close the
MetricsQueryClient
session.
-
list_metric_definitions
(resource_uri: str, **kwargs: Any) → azure.core.async_paging.AsyncItemPaged[azure.monitor.query._models.MetricDefinition][source]¶ Lists the metric definitions for the resource.
- Parameters
resource_uri (str) – The identifier of the resource.
- Keyword Arguments
namespace (str) – Metric namespace to query metric definitions for.
- Returns
An iterator like instance of either MetricDefinition or the result of cls(response)
- Return type
~azure.core.paging.AsyncItemPaged[:class: ~azure.monitor.query.MetricDefinition]
- Raises
~azure.core.exceptions.HttpResponseError
-
list_metric_namespaces
(resource_uri: str, **kwargs: Any) → azure.core.async_paging.AsyncItemPaged[azure.monitor.query._models.MetricNamespace][source]¶ Lists the metric namespaces for the resource.
- Parameters
resource_uri (str) – The identifier of the resource.
- Keyword Arguments
start_time (datetime) – The start time from which to query for metric namespaces. This should be provided as a datetime object.
- Returns
An iterator like instance of either MetricNamespace or the result of cls(response)
- Return type
~azure.core.paging.AsyncItemPaged[:class: ~azure.monitor.query.MetricNamespace]
- Raises
~azure.core.exceptions.HttpResponseError
-
async
query_resource
(resource_uri: str, metric_names: List[str], **kwargs: Any) → azure.monitor.query._models.MetricsQueryResult[source]¶ Lists the metric values for a resource.
Note: Although the start_time, end_time, duration are optional parameters, it is highly recommended to specify the timespan. If not, the entire dataset is queried.
- Parameters
- Keyword Arguments
timespan (timedelta or tuple[datetime, timedelta] or tuple[datetime, datetime]) – The timespan for which to query the data. This can be a timedelta, a timedelta and a start datetime, or a start datetime/end datetime.
granularity (timedelta) – The interval (i.e. timegrain) of the query.
aggregations (list[str]) – The list of aggregation types to retrieve. Use azure.monitor.query.MetricAggregationType enum to get each aggregation type.
max_results (int) – The maximum number of records to retrieve. Valid only if $filter is specified. Defaults to 10.
order_by (str) – The aggregation to use for sorting results and the direction of the sort. Only one order can be specified. Examples: sum asc.
filter (str) – The $filter is used to reduce the set of metric data returned.:code:<br>`Example::code:`<br>`Metric contains metadata A, B and C.:code:`<br>- Return all time series of C where A = a1 and B = b1 or b2:code:<br>$filter=A eq ‘a1’ and B eq ‘b1’ or B eq ‘b2’ and C eq ‘*’
<br>
- Invalid variant:<br>
$filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘*’ or B = ‘b2’<br>`This is invalid because the logical or operator cannot separate two different metadata names.:code:`<br>
- Return all time series where A = a1, B = b1 and C = c1:<br>
$filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘c1’<br>
- Return all time series where A = a1:code:<br>$filter=A eq ‘a1’ and B eq ‘*’ and C eq ‘*’. To use the split feature, set the value to * - for example, like “City eq ‘*’”metric_namespace (str) – Metric namespace to query metric definitions for.
- Returns
A MetricsQueryResult object.
- Return type
- Raises
~azure.core.exceptions.HttpResponseError