Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 13 additions & 13 deletions sdk/monitor/azure-monitor-query/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ pip install azure-monitor-query --pre
```

### Authenticate the client
A **token credential** is necessary to instantiate both the LogsClient and the MetricsClient object.
A **token credential** is necessary to instantiate both the LogsQueryClient and the MetricsQueryClient object.

```Python
from azure.monitor.query import LogsClient
from azure.monitor.query import LogsQueryClient
from azure.identity import ClientSecretCredential


Expand All @@ -34,11 +34,11 @@ credential = ClientSecretCredential(
tenant_id = os.environ['AZURE_TENANT_ID']
)

client = LogsClient(credential)
client = LogsQueryClient(credential)
```

```Python
from azure.monitor.query import MetricsClient
from azure.monitor.query import MetricsQueryClient
from azure.identity import ClientSecretCredential


Expand All @@ -48,7 +48,7 @@ credential = ClientSecretCredential(
tenant_id = os.environ['AZURE_TENANT_ID']
)

client = MetricsClient(credential)
client = MetricsQueryClient(credential)
```

## Key concepts
Expand Down Expand Up @@ -111,7 +111,7 @@ time-stamped data. Each set of metric values is a time series with the following
```Python
import os
import pandas as pd
from azure.monitor.query import LogsClient
from azure.monitor.query import LogsQueryClient
from azure.identity import ClientSecretCredential


Expand All @@ -121,7 +121,7 @@ credential = ClientSecretCredential(
tenant_id = os.environ['AZURE_TENANT_ID']
)

client = LogsClient(credential)
client = LogsQueryClient(credential)

# Response time trend
# request duration over the last 12 hours.
Expand All @@ -145,7 +145,7 @@ for table in response.tables:
```Python
import os
import pandas as pd
from azure.monitor.query import LogsClient, LogsQueryRequest
from azure.monitor.query import LogsQueryClient, LogsQueryRequest
from azure.identity import ClientSecretCredential


Expand All @@ -155,7 +155,7 @@ credential = ClientSecretCredential(
tenant_id = os.environ['AZURE_TENANT_ID']
)

client = LogsClient(credential)
client = LogsQueryClient(credential)

requests = [
LogsQueryRequest(
Expand Down Expand Up @@ -191,7 +191,7 @@ for response in response.responses:
```Python
import os
import pandas as pd
from azure.monitor.query import LogsClient
from azure.monitor.query import LogsQueryClient
from azure.identity import ClientSecretCredential


Expand All @@ -201,7 +201,7 @@ credential = ClientSecretCredential(
tenant_id = os.environ['AZURE_TENANT_ID']
)

client = LogsClient(credential)
client = LogsQueryClient(credential)

response = client.query(
os.environ['LOG_WORKSPACE_ID'],
Expand All @@ -218,7 +218,7 @@ for table in response.tables:

```Python
import os
from azure.monitor.query import MetricsClient
from azure.monitor.query import MetricsQueryClient
from azure.identity import ClientSecretCredential


Expand All @@ -228,7 +228,7 @@ credential = ClientSecretCredential(
tenant_id = os.environ['AZURE_TENANT_ID']
)

client = MetricsClient(credential)
client = MetricsQueryClient(credential)
response = client.query(os.environ['METRICS_RESOURCE_URI'], metric_names=["Microsoft.CognitiveServices/accounts"])
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------

from ._log_query_client import LogsClient
from ._metrics_query_client import MetricsClient
from ._log_query_client import LogsQueryClient
from ._metrics_query_client import MetricsQueryClient

from ._models import (
LogsQueryResults,
Expand All @@ -28,15 +28,15 @@
from ._version import VERSION

__all__ = [
"LogsClient",
"LogsQueryClient",
"LogsBatchResults",
"LogsBatchResultError",
"LogsQueryResults",
"LogsQueryResultColumn",
"LogsQueryResultTable",
"LogsQueryRequest",
"LogsErrorDetails",
"MetricsClient",
"MetricsQueryClient",
"MetricNamespace",
"MetricDefinition",
"MetricsResult",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# license information.
# --------------------------------------------------------------------------

from typing import Mapping, TYPE_CHECKING
from typing import TYPE_CHECKING
from azure.core.exceptions import HttpResponseError
from azure.core.pipeline.policies import BearerTokenCredentialPolicy

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
from azure.core.credentials import TokenCredential


class LogsClient(object):
"""LogsClient
class LogsQueryClient(object):
"""LogsQueryClient

:param credential: The credential to authenticate the client
:type credential: ~azure.core.credentials.TokenCredential
:keyword endpoint: The endpoint to connect to. Defaults to 'https://api.loganalytics.io/v1'.
:keyword endpoint: The endpoint to connect to. Defaults to 'https://api.loganalytics.io'.
:paramtype endpoint: str
"""

Expand Down Expand Up @@ -133,11 +133,11 @@ def batch_query(self, queries, **kwargs):

def close(self):
# type: () -> None
"""Close the :class:`~azure.monitor.query.LogsClient` session."""
"""Close the :class:`~azure.monitor.query.LogsQueryClient` session."""
return self._client.close()

def __enter__(self):
# type: () -> LogsClient
# type: () -> LogsQueryClient
self._client.__enter__() # pylint:disable=no-member
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# pylint: disable=anomalous-backslash-in-string

from datetime import time
from typing import TYPE_CHECKING, Any

from ._generated._monitor_query_client import (
Expand All @@ -19,39 +20,41 @@
if TYPE_CHECKING:
from azure.core.credentials import TokenCredential
from azure.core.paging import ItemPaged
from ._models import MetricNamespace


class MetricsClient(object):
"""MetricsClient
class MetricsQueryClient(object):
"""MetricsQueryClient

:param credential: The credential to authenticate the client
:type credential: ~azure.core.credentials.TokenCredential
:keyword endpoint: The endpoint to connect to. Defaults to 'https://management.azure.com'.
:paramtype endpoint: str
"""

def __init__(self, credential, **kwargs):
# type: (TokenCredential, Any) -> None
endpoint = kwargs.pop('endpoint', 'https://management.azure.com')
self._client = MonitorQueryClient(
credential=credential,
base_url='https://management.azure.com',
base_url=endpoint,
authentication_policy=get_metrics_authentication_policy(credential),
**kwargs
)
self._metrics_op = self._client.metrics
self._namespace_op = self._client.metric_namespaces
self._definitions_op = self._client.metric_definitions

def query(self, resource_uri, metric_names, **kwargs):
# type: (str, list, Any) -> MetricsResult
def query(self, resource_uri, metric_names, timespan=None, **kwargs):
# type: (str, list, str, Any) -> MetricsResult
"""Lists the metric values for a resource.

:param resource_uri: The identifier of the resource.
:type resource_uri: str
:param metric_names: The names of the metrics to retrieve.
:type metric_names: list
:keyword timespan: The timespan of the query. It is a string with the following format
:param timespan: The timespan of the query. It is a string with the following format
'startDateTime_ISO/endDateTime_ISO'.
:paramtype timespan: str
:type timespan: str
:keyword interval: The interval (i.e. timegrain) of the query.
:paramtype interval: ~datetime.timedelta
:keyword aggregation: The list of aggregation types (comma separated) to retrieve.
Expand Down Expand Up @@ -84,6 +87,7 @@ def query(self, resource_uri, metric_names, **kwargs):
:raises: ~azure.core.exceptions.HttpResponseError
"""
kwargs.setdefault("metricnames", ",".join(metric_names))
kwargs.setdefault("timespan", timespan)
generated = self._metrics_op.list(resource_uri, connection_verify=False, **kwargs)
return MetricsResult._from_generated(generated) # pylint: disable=protected-access

Expand All @@ -105,7 +109,7 @@ def list_metric_namespaces(self, resource_uri, **kwargs):
cls=kwargs.pop(
"cls",
lambda objs: [
MetricNamespace._from_generated(x) for x in objs
MetricNamespace._from_generated(x) for x in objs # pylint: disable=protected-access
]
),
**kwargs)
Expand All @@ -128,18 +132,18 @@ def list_metric_definitions(self, resource_uri, metric_namespace=None, **kwargs)
cls=kwargs.pop(
"cls",
lambda objs: [
MetricDefinition._from_generated(x) for x in objs
MetricDefinition._from_generated(x) for x in objs # pylint: disable=protected-access
]
),
**kwargs)

def close(self):
# type: () -> None
"""Close the :class:`~azure.monitor.query.MetricsClient` session."""
"""Close the :class:`~azure.monitor.query.MetricsQueryClient` session."""
return self._client.close()

def __enter__(self):
# type: () -> MetricsClient
# type: () -> MetricsQueryClient
self._client.__enter__() # pylint:disable=no-member
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _from_generated(cls, generated):
)

class LogsQueryRequest(InternalLogQueryRequest):
"""An single request in a batch.
"""A single request in a batch.

Variables are only populated by the server, and will be ignored when sending a request.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------

from ._log_query_client_async import LogsClient
from ._metrics_query_client_async import MetricsClient
from ._log_query_client_async import LogsQueryClient
from ._metrics_query_client_async import MetricsQueryClient

__all__ = [
"LogsClient",
"MetricsClient"
"LogsQueryClient",
"MetricsQueryClient"
]
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
from azure.core.credentials_async import AsyncTokenCredential


class LogsClient(object):
"""LogsClient
class LogsQueryClient(object):
"""LogsQueryClient

:param credential: The credential to authenticate the client
:type credential: ~azure.core.credentials_async.AsyncTokenCredential
Expand Down Expand Up @@ -106,9 +106,10 @@ async def batch_query(
queries: Union[Sequence[Dict], Sequence[LogsQueryRequest]],
**kwargs: Any
) -> LogsBatchResults:
"""Execute an Analytics query.
"""Execute a list of analytics queries. Each request can be either a LogQueryRequest
object or an equivalent serialized model.

Executes an Analytics query for data.
The response is returned in the same order as that of the requests sent.

:param queries: The list of queries that should be processed
:type queries: list[dict] or list[~azure.monitor.query.LogsQueryRequest]
Expand All @@ -129,13 +130,13 @@ async def batch_query(
await self._query_op.batch(batch, **kwargs), request_order
)

async def __aenter__(self) -> "LogsClient":
async def __aenter__(self) -> "LogsQueryClient":
await self._client.__aenter__()
return self

async def __aexit__(self, *args: "Any") -> None:
await self._client.__aexit__(*args)

async def close(self) -> None:
"""Close the :class:`~azure.monitor.query.aio.LogsClient` session."""
"""Close the :class:`~azure.monitor.query.aio.LogsQueryClient` session."""
await self._client.__aexit__()
Loading