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 batch_query(queries: Union[Sequence[Dict], Sequence[azure.monitor.query._models.LogsQueryRequest]], **kwargs: Any)azure.monitor.query._models.LogsBatchResults[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[LogsQueryRequest]) – The list of queries that should be processed

Returns

BatchResponse, or the result of cls(response)

Return type

LogsBatchResults

Raises

~azure.core.exceptions.HttpResponseError

async close()None[source]

Close the LogsQueryClient session.

async query(workspace_id: str, query: str, duration: Optional[str] = None, **kwargs: Any)azure.monitor.query._models.LogsQueryResults[source]

Execute an Analytics query.

Executes an Analytics query for data.

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
  • workspace_id (str) – ID of the workspace. This is Workspace ID from the Properties blade in the Azure portal.

  • query (str) – The Analytics query. Learn more about the Analytics query syntax.

  • duration (str) – The duration for which to query the data. This can also be accompanied with either start_time or end_time. If start_time or end_time is not provided, the current time is taken as the end time. This should be provided in a ISO8601 string format like ‘PT1H’, ‘P1Y2M10DT2H30M’.

Keyword Arguments
  • start_time (datetime) – The start time from which to query the data. This should be accompanied with either end_time or duration.

  • end_time (datetime) – The end time till which to query the data. This should be accompanied with either start_time or duration.

  • 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_render (bool) – In the query language, it is possible to specify different render 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

  • workspaces (list[str]) – A list of workspaces that are included in the query.

  • qualified_names (list[str]) – A list of qualified workspace names that are included in the query.

  • workspace_ids (list[str]) – A list of workspace IDs that are included in the query.

  • azure_resource_ids (list[str]) – A list of Azure resource IDs that are included in the query.

Returns

QueryResults, or the result of cls(response)

Return type

LogsQueryResults

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, metric_namespace: Optional[str] = None, **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.

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

ItemPaged[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 (str) – The ISO 8601 conform Date start time from which to query for metric namespaces.

Returns

An iterator like instance of either MetricNamespaceCollection or the result of cls(response)

Return type

ItemPaged[MetricNamespace]

Raises

~azure.core.exceptions.HttpResponseError

async query(resource_uri: str, metric_names: List, duration: Optional[str] = None, **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.

  • duration (str) – The duration for which to query the data. This can also be accompanied with either start_time or end_time. If start_time or end_time is not provided, the current time is taken as the end time. This should be provided in a ISO8601 string format like ‘PT1H’, ‘P1Y2M10DT2H30M’.

Keyword Arguments
  • start_time (datetime) – The start time from which to query the data. This should be accompanied with either end_time or duration.

  • end_time (datetime) – The end time till which to query the data. This should be accompanied with either start_time or duration.

  • interval (timedelta) – The interval (i.e. timegrain) of the query.

  • aggregation (str) – The list of aggregation types (comma separated) to retrieve.

  • top (int) – The maximum number of records to retrieve. Valid only if $filter is specified. Defaults to 10.

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

  • result_type (str or ResultType) – Reduces the set of data collected. The syntax allowed depends on the operation. See the operation’s description for details.

  • 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