Exemple #1
0
async def test_metrics_definitions():
    client = MetricsQueryClient(_credential())

    async with client:
        response = client.list_metric_definitions(os.environ['METRICS_RESOURCE_URI'], namespace='microsoft.eventgrid/topics')

        assert response is not None
Exemple #2
0
async def test_metrics_namespaces():
    client = MetricsQueryClient(_credential())

    async with client:
        response = client.list_metric_namespaces(os.environ['METRICS_RESOURCE_URI'])

        assert response is not None
    async def list_namespaces(self):
        credential  = DefaultAzureCredential()

        client = MetricsQueryClient(credential)

        metrics_uri = os.environ['METRICS_RESOURCE_URI']
        async with client:
            response = client.list_metric_namespaces(metrics_uri)
            async for item in response:
                print(item.fully_qualified_namespace)
                print(item.type)
Exemple #4
0
    async def list_definitions(self):
        credential = DefaultAzureCredential()

        client = MetricsQueryClient(credential)

        metrics_uri = os.environ['METRICS_RESOURCE_URI']
        async with client:
            response = client.list_metric_definitions(metrics_uri)

            async for item in response:
                print(item.namespace)
                for availability in item.metric_availabilities:
                    print(availability.granularity)
Exemple #5
0
async def list_namespaces():
    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)

    metrics_uri = os.environ['METRICS_RESOURCE_URI']
    response = client.list_metric_namespaces(metrics_uri)

    async for item in response:
        print(item.metric_namespace_name)
        print(item.type)
Exemple #6
0
async def list_namespaces():
    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)

    metrics_uri = os.environ['METRICS_RESOURCE_URI']
    response = client.list_metric_definitions(metrics_uri)

    async for item in response:
        print(item)
        for availability in item.metric_availabilities:
            print(availability.time_grain)
Exemple #7
0
async def test_metrics_auth():
    credential = _credential()
    client = MetricsQueryClient(credential)
    response = await client.query(os.environ['METRICS_RESOURCE_URI'],
                                  metric_names=["MatchedEventCount"],
                                  timespan=timedelta(days=1),
                                  aggregations=[MetricAggregationType.COUNT])
    assert response
    assert response.metrics
async def test_metrics_auth():
    credential = _credential()
    client = MetricsQueryClient(credential)
    # returns LogsQueryResults
    response = await client.query(os.environ['METRICS_RESOURCE_URI'],
                                  metric_names=["PublishSuccessCount"],
                                  timespan='P2D')

    assert response is not None
    assert response.metrics is not None
Exemple #9
0
async def test_metrics_filter():
    credential = _credential()
    client = MetricsQueryClient(credential)
    response = await client.query_resource(
        os.environ['METRICS_RESOURCE_URI'],
        metric_names=["MatchedEventCount"],
        timespan=timedelta(days=1),
        granularity=timedelta(minutes=5),
        filter="EventSubscriptionName eq '*'",
        aggregations=[MetricAggregationType.COUNT])
    assert response
    metric = response.metrics['MatchedEventCount']
    for t in metric.timeseries:
        assert t.metadata_values is not None
Exemple #10
0
async def test_metrics_list():
    credential = _credential()
    client = MetricsQueryClient(credential)
    response = await client.query_resource(
        os.environ['METRICS_RESOURCE_URI'],
        metric_names=["MatchedEventCount"],
        timespan=timedelta(days=1),
        granularity=timedelta(minutes=5),
        aggregations=[MetricAggregationType.COUNT])
    assert response
    metrics = response.metrics
    assert len(metrics) == 1
    assert metrics[0].__class__ == Metric
    assert metrics['MatchedEventCount'].__class__ == Metric
    assert metrics['MatchedEventCount'] == metrics[0]
Exemple #11
0
async def query_metrics():
    credential  = DefaultAzureCredential()

    client = MetricsQueryClient(credential)

    metrics_uri = os.environ['METRICS_RESOURCE_URI']
    async with client:
        response = await client.query_resource(
            metrics_uri,
            metric_names=["Ingress"],
            timespan=timedelta(hours=2),
            granularity=timedelta(minutes=15),
            aggregations=[MetricAggregationType.AVERAGE],
            )

    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.timestamp)
Exemple #12
0
async def query_metrics():
    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)

    metrics_uri = os.environ['METRICS_RESOURCE_URI']
    async with client:
        response = await 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)