class ListAnomaliesTest(PerfStressTest):
    def __init__(self, arguments):
        super().__init__(arguments)
        service_endpoint = os.getenv("AZURE_METRICS_ADVISOR_ENDPOINT")
        subscription_key = os.getenv("AZURE_METRICS_ADVISOR_SUBSCRIPTION_KEY")
        api_key = os.getenv("AZURE_METRICS_ADVISOR_API_KEY")
        self.anomaly_alert_configuration_id = os.getenv(
            "AZURE_METRICS_ADVISOR_ANOMALY_ALERT_CONFIGURATION_ID")
        self.alert_id = os.getenv("AZURE_METRICS_ADVISOR_ALERT_ID")
        self.service_client = SyncClient(
            service_endpoint,
            MetricsAdvisorKeyCredential(subscription_key, api_key))
        self.async_service_client = AsyncClient(
            service_endpoint,
            MetricsAdvisorKeyCredential(subscription_key, api_key))

    async def close(self):
        await self.async_service_client.close()
        await super().close()

    def run_sync(self):
        results = self.service_client.list_anomalies(
            alert_configuration_id=self.anomaly_alert_configuration_id,
            alert_id=self.alert_id,
        )
        for _ in results:
            pass

    async def run_async(self):
        results = self.async_service_client.list_anomalies(
            alert_configuration_id=self.anomaly_alert_configuration_id,
            alert_id=self.alert_id,
        )
        async for _ in results:
            pass
Beispiel #2
0
async def sample_list_anomalies_for_alert_async(alert_config_id, alert_id):
    # [START list_anomalies_for_alert_async]
    from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential
    from azure.ai.metricsadvisor.aio import MetricsAdvisorClient

    service_endpoint = os.getenv("METRICS_ADVISOR_ENDPOINT")
    subscription_key = os.getenv("METRICS_ADVISOR_SUBSCRIPTION_KEY")
    api_key = os.getenv("METRICS_ADVISOR_API_KEY")

    client = MetricsAdvisorClient(service_endpoint,
                                  MetricsAdvisorKeyCredential(subscription_key, api_key))

    async with client:
        results = client.list_anomalies(
            alert_configuration_id=alert_config_id,
            alert_id=alert_id,
        )
        async for result in results:
            print("Create time: {}".format(result.created_time))
            print("Severity: {}".format(result.severity))
            print("Status: {}".format(result.status))