コード例 #1
0
def test_metrics_auth():
    credential = _credential()
    client = MetricsQueryClient(credential)
    response = client.query(os.environ['METRICS_RESOURCE_URI'],
                            metric_names=["MatchedEventCount"],
                            timespan=timedelta(days=1),
                            aggregations=[MetricAggregationType.COUNT])
    assert response
    assert response.metrics
コード例 #2
0
class MetricsPerfTest(PerfStressTest):
    def __init__(self, arguments):
        super().__init__(arguments)

        # auth configuration
        self.metrics_uri = self.get_from_env('METRICS_RESOURCE_URI')
        self.names = ["MatchedEventCount"]
        self.aggregations = [MetricAggregationType.COUNT]

        # Create clients
        self.metrics_client = SyncMetricsQueryClient(
            credential=SyncDefaultAzureCredential())
        self.async_metrics_client = AsyncMetricsQueryClient(
            credential=AsyncDefaultAzureCredential())

    async def close(self):
        """This is run after cleanup.
        
        Use this to close any open handles or clients.
        """
        await self.async_metrics_client.close()
        await super().close()

    def run_sync(self):
        """The synchronous perf test.
        
        Try to keep this minimal and focused. Using only a single client API.
        Avoid putting any ancilliary logic (e.g. generating UUIDs), and put this in the setup/init instead
        so that we're only measuring the client API call.
        """
        self.metrics_client.query(self.metrics_uri,
                                  self.names,
                                  aggregations=self.aggregations)

    async def run_async(self):
        """The asynchronous perf test.
        
        Try to keep this minimal and focused. Using only a single client API.
        Avoid putting any ancilliary logic (e.g. generating UUIDs), and put this in the setup/init instead
        so that we're only measuring the client API call.
        """
        await self.async_metrics_client.query(self.metrics_uri,
                                              self.names,
                                              aggregations=self.aggregations)
コード例 #3
0
def test_metrics_auth():
    credential = _credential()
    client = MetricsQueryClient(credential)
    # returns LogsQueryResults
    response = client.query(os.environ['METRICS_RESOURCE_URI'],
                            metric_names=["PublishSuccessCount"],
                            timespan='P2D')

    assert response is not None
    assert response.metrics is not None
コード例 #4
0
import os
from datetime import datetime
import urllib3
from azure.monitor.query import MetricsQueryClient
from azure.identity import ClientSecretCredential

urllib3.disable_warnings()

# [START metrics_client_auth_with_token_cred]
credential = ClientSecretCredential(
    client_id=os.environ['AZURE_CLIENT_ID'],
    client_secret=os.environ['AZURE_CLIENT_SECRET'],
    tenant_id=os.environ['AZURE_TENANT_ID'])

client = MetricsQueryClient(credential)
# [END metrics_client_auth_with_token_cred]

# [START send_metrics_query]
metrics_uri = os.environ['METRICS_RESOURCE_URI']
response = client.query(metrics_uri,
                        metric_names=["PublishSuccessCount"],
                        start_time=datetime(2021, 5, 25),
                        duration='P1D')

for metric in response.metrics:
    print(metric.name)
    for time_series_element in metric.timeseries:
        for metric_value in time_series_element.data:
            print(metric_value.time_stamp)
# [END send_metrics_query]
コード例 #5
0
from azure.monitor.query import MetricsQueryClient, MetricAggregationType
from azure.identity import DefaultAzureCredential

# urllib3.disable_warnings()

# [START metrics_client_auth_with_token_cred]
credential  = DefaultAzureCredential()

client = MetricsQueryClient(credential)
# [END metrics_client_auth_with_token_cred]

# [START send_metrics_query]
metrics_uri = os.environ['METRICS_RESOURCE_URI']
response = client.query(
    metrics_uri,
    metric_names=["Ingress"],
    timespan=timedelta(hours=2),
    granularity=timedelta(minutes=5),
    aggregations=[MetricAggregationType.AVERAGE],
    )

for metric in response.metrics:
    print(metric.name + ' -- ' + metric.display_description)
    for time_series_element in metric.timeseries:
        for metric_value in time_series_element.data:
            print('The ingress at {} is {}'.format(
                metric_value.timestamp,
                metric_value.average
            ))
# [END send_metrics_query]