azure.monitor.query.aio package

class azure.monitor.query.aio.LogsQueryClient(credential: AsyncTokenCredential, **kwargs: Any)[source]
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(workspace_id: str, query: str, *, timespan: Union[datetime.timedelta, Tuple[datetime.datetime, datetime.timedelta], Tuple[datetime.datetime, datetime.datetime]], **kwargs: Any)azure.monitor.query._models.LogsQueryResult[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.

  • 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.

Keyword Arguments
  • server_timeout (int) – the server timeout. 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

QueryResults, or the result of cls(response)

Return type

LogsQueryResult

Raises

~azure.core.exceptions.HttpResponseError

async query_batch(queries: Union[Sequence[Dict], Sequence[azure.monitor.query._models.LogsBatchQuery]], **kwargs: Any)List[azure.monitor.query._models.LogsQueryResult][source]

Execute a list of analytics queries. Each request can be either a LogQueryRequest object or an equivalent serialized model.

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 objects, or the result of cls(response)

Return type

list[LogsQueryResult]

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 MetricDefinitionCollection 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_uri: str, metric_names: List, **kwargs: Any)azure.monitor.query._models.MetricsResult[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
  • resource_uri (str) – The identifier of the resource.

  • metric_names (list) – The names of the metrics to retrieve.

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 ‘*’.

  • metric_namespace (str) – Metric namespace to query metric definitions for.

Returns

Response, or the result of cls(response)

Return type

MetricsResult

Raises

~azure.core.exceptions.HttpResponseError