async def sample_create_detection_config_async():
    # [START create_anomaly_detection_config_async]
    from azure.ai.metricsadvisor import MetricsAdvisorKeyCredential
    from azure.ai.metricsadvisor.aio import MetricsAdvisorAdministrationClient
    from azure.ai.metricsadvisor.models import (
        ChangeThresholdCondition,
        HardThresholdCondition,
        SmartDetectionCondition,
        SuppressCondition,
        MetricDetectionCondition,
    )

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

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

    change_threshold_condition = ChangeThresholdCondition(
        anomaly_detector_direction="Both",
        change_percentage=20,
        shift_point=10,
        within_range=True,
        suppress_condition=SuppressCondition(
            min_number=5,
            min_ratio=2
        )
    )
    hard_threshold_condition = HardThresholdCondition(
        anomaly_detector_direction="Up",
        upper_bound=100,
        suppress_condition=SuppressCondition(
            min_number=2,
            min_ratio=2
        )
    )
    smart_detection_condition = SmartDetectionCondition(
        anomaly_detector_direction="Up",
        sensitivity=10,
        suppress_condition=SuppressCondition(
            min_number=2,
            min_ratio=2
        )
    )
    async with client:
        detection_config = await client.create_metric_anomaly_detection_configuration(
            name="my_detection_config",
            metric_id=metric_id,
            description="anomaly detection config for metric",
            whole_series_detection_condition=MetricDetectionCondition(
                cross_conditions_operator="OR",
                change_threshold_condition=change_threshold_condition,
                hard_threshold_condition=hard_threshold_condition,
                smart_detection_condition=smart_detection_condition
            )
        )

        return detection_config
Beispiel #2
0
 def _create_detection_config_for_update(self, name):
     try:
         data_feed = self._create_data_feed(name)
         detection_config_name = create_random_name("testupdated")
         detection_config = self.admin_client.create_detection_configuration(
             name=detection_config_name,
             metric_id=data_feed.metric_ids['cost'],
             description="My test metric anomaly detection configuration",
             whole_series_detection_condition=MetricDetectionCondition(
                 condition_operator="AND",
                 smart_detection_condition=SmartDetectionCondition(
                     sensitivity=50,
                     anomaly_detector_direction="Both",
                     suppress_condition=SuppressCondition(min_number=5,
                                                          min_ratio=5)),
                 hard_threshold_condition=HardThresholdCondition(
                     anomaly_detector_direction="Both",
                     suppress_condition=SuppressCondition(min_number=5,
                                                          min_ratio=5),
                     lower_bound=0,
                     upper_bound=100),
                 change_threshold_condition=ChangeThresholdCondition(
                     change_percentage=50,
                     shift_point=30,
                     within_range=True,
                     anomaly_detector_direction="Both",
                     suppress_condition=SuppressCondition(min_number=2,
                                                          min_ratio=2))),
             series_detection_conditions=[
                 MetricSingleSeriesDetectionCondition(
                     series_key={
                         "city": "Shenzhen",
                         "category": "Jewelry"
                     },
                     smart_detection_condition=SmartDetectionCondition(
                         anomaly_detector_direction="Both",
                         sensitivity=63,
                         suppress_condition=SuppressCondition(
                             min_number=1, min_ratio=100)))
             ],
             series_group_detection_conditions=[
                 MetricSeriesGroupDetectionCondition(
                     series_group_key={"city": "Sao Paulo"},
                     smart_detection_condition=SmartDetectionCondition(
                         anomaly_detector_direction="Both",
                         sensitivity=63,
                         suppress_condition=SuppressCondition(
                             min_number=1, min_ratio=100)))
             ])
         return detection_config, data_feed
     except Exception as e:
         self.admin_client.delete_data_feed(data_feed.id)
         raise e
Beispiel #3
0
 async def create_detection_config(self, name):
     detection_config_name = self.create_random_name(name)
     if is_live():
         self.variables["detection_config_name"] = detection_config_name
     detection_config = await self.client.create_detection_configuration(
         name=self.variables["detection_config_name"],
         metric_id=self.variables["data_feed_metric_id"],
         description="My test metric anomaly detection configuration",
         whole_series_detection_condition=MetricDetectionCondition(
             condition_operator="AND",
             smart_detection_condition=SmartDetectionCondition(
                 sensitivity=50,
                 anomaly_detector_direction="Both",
                 suppress_condition=SuppressCondition(min_number=5,
                                                      min_ratio=5)),
             hard_threshold_condition=HardThresholdCondition(
                 anomaly_detector_direction="Both",
                 suppress_condition=SuppressCondition(min_number=5,
                                                      min_ratio=5),
                 lower_bound=0,
                 upper_bound=100),
             change_threshold_condition=ChangeThresholdCondition(
                 change_percentage=50,
                 shift_point=30,
                 within_range=True,
                 anomaly_detector_direction="Both",
                 suppress_condition=SuppressCondition(min_number=2,
                                                      min_ratio=2))),
         series_detection_conditions=[
             MetricSingleSeriesDetectionCondition(
                 series_key={
                     "region": "Beijing",
                     "category": "Shoes Handbags & Sunglasses"
                 },
                 smart_detection_condition=SmartDetectionCondition(
                     anomaly_detector_direction="Both",
                     sensitivity=63,
                     suppress_condition=SuppressCondition(min_number=1,
                                                          min_ratio=100)))
         ],
         series_group_detection_conditions=[
             MetricSeriesGroupDetectionCondition(
                 series_group_key={"region": "Beijing"},
                 smart_detection_condition=SmartDetectionCondition(
                     anomaly_detector_direction="Both",
                     sensitivity=63,
                     suppress_condition=SuppressCondition(min_number=1,
                                                          min_ratio=100)))
         ])
     if is_live():
         self.variables["detection_config_id"] = detection_config.id
     return detection_config