Skip to content

put_anomaly_detector

put_anomaly_detector(
    *,
    config_overrides: Optional[CloudWatchClientConfig] = None,
    namespace: Optional[Namespace] = None,
    metric_name: Optional[MetricName] = None,
    dimensions: Optional[Dimensions] = None,
    stat: Optional[AnomalyDetectorMetricStat] = None,
    configuration: Optional[AnomalyDetectorConfiguration] = None,
    metric_characteristics: Optional[MetricCharacteristics] = None,
    single_metric_anomaly_detector: Optional[SingleMetricAnomalyDetector] = None,
    metric_math_anomaly_detector: Optional[MetricMathAnomalyDetector] = None,
) -> PutAnomalyDetectorOutput

Creates an anomaly detection model for a CloudWatch metric. You can use the model to display a band of expected normal values when the metric is graphed.

If you have enabled unified cross-account observability, and this account is a monitoring account, the metric can be in the same account or a source account. You can specify the account ID in the object you specify in the SingleMetricAnomalyDetector parameter.

For more information, see CloudWatch Anomaly Detection.

Parameters:

  • namespace (Optional[Namespace], default: None ) –

    The namespace of the metric to create the anomaly detection model for.

  • metric_name (Optional[MetricName], default: None ) –

    The name of the metric to create the anomaly detection model for.

  • dimensions (Optional[Dimensions], default: None ) –

    The metric dimensions to create the anomaly detection model for.

  • stat (Optional[AnomalyDetectorMetricStat], default: None ) –

    The statistic to use for the metric and the anomaly detection model.

  • configuration (Optional[AnomalyDetectorConfiguration], default: None ) –

    The configuration specifies details about how the anomaly detection model is to be trained, including time ranges to exclude when training and updating the model. You can specify as many as 10 time ranges.

    The configuration can also include the time zone to use for the metric.

  • metric_characteristics (Optional[MetricCharacteristics], default: None ) –

    Use this object to include parameters to provide information about your metric to CloudWatch to help it build more accurate anomaly detection models. Currently, it includes the PeriodicSpikes parameter.

  • single_metric_anomaly_detector (Optional[SingleMetricAnomalyDetector], default: None ) –

    A single metric anomaly detector to be created.

    When using SingleMetricAnomalyDetector, you cannot include the following parameters in the same operation:

    • Dimensions

    • MetricName

    • Namespace

    • Stat

    • the MetricMathAnomalyDetector parameters of PutAnomalyDetectorInput

    Instead, specify the single metric anomaly detector attributes as part of the property SingleMetricAnomalyDetector.

  • metric_math_anomaly_detector (Optional[MetricMathAnomalyDetector], default: None ) –

    The metric math anomaly detector to be created.

    When using MetricMathAnomalyDetector, you cannot include the following parameters in the same operation:

    • Dimensions

    • MetricName

    • Namespace

    • Stat

    • the SingleMetricAnomalyDetector parameters of PutAnomalyDetectorInput

    Instead, specify the metric math anomaly detector attributes as part of the property MetricMathAnomalyDetector.

Raises:

Source code in docs_src/capo_cloudwatch/_services/cloud_watch.py
def put_anomaly_detector(
    self,
    *,
    config_overrides: Optional[CloudWatchClientConfig] = None,
    namespace: Optional["capo_cloudwatch.types.namespace.Namespace"] = None,
    metric_name: Optional["capo_cloudwatch.types.metric_name.MetricName"] = None,
    dimensions: Optional["capo_cloudwatch.types.dimensions.Dimensions"] = None,
    stat: Optional[
        "capo_cloudwatch.types.anomaly_detector_metric_stat.AnomalyDetectorMetricStat"
    ] = None,
    configuration: Optional[
        "capo_cloudwatch.types.anomaly_detector_configuration.AnomalyDetectorConfiguration"
    ] = None,
    metric_characteristics: Optional[
        "capo_cloudwatch.types.metric_characteristics.MetricCharacteristics"
    ] = None,
    single_metric_anomaly_detector: Optional[
        "capo_cloudwatch.types.single_metric_anomaly_detector.SingleMetricAnomalyDetector"
    ] = None,
    metric_math_anomaly_detector: Optional[
        "capo_cloudwatch.types.metric_math_anomaly_detector.MetricMathAnomalyDetector"
    ] = None,
) -> "capo_cloudwatch.types.put_anomaly_detector_output.PutAnomalyDetectorOutput":
    """<p>Creates an anomaly detection model for a CloudWatch metric. You can use the model to display a band of expected normal values when the metric is graphed.</p> <p>If you have enabled unified cross-account observability, and this account is a monitoring account, the metric can be in the same account or a source account. You can specify the account ID in the object you specify in the <code>SingleMetricAnomalyDetector</code> parameter.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Anomaly_Detection.html">CloudWatch Anomaly Detection</a>.</p>

    Args:
        namespace: <p>The namespace of the metric to create the anomaly detection model for.</p>
        metric_name: <p>The name of the metric to create the anomaly detection model for.</p>
        dimensions: <p>The metric dimensions to create the anomaly detection model for.</p>
        stat: <p>The statistic to use for the metric and the anomaly detection model.</p>
        configuration: <p>The configuration specifies details about how the anomaly detection model is to be trained, including time ranges to exclude when training and updating the model. You can specify as many as 10 time ranges.</p> <p>The configuration can also include the time zone to use for the metric.</p>
        metric_characteristics: <p>Use this object to include parameters to provide information about your metric to CloudWatch to help it build more accurate anomaly detection models. Currently, it includes the <code>PeriodicSpikes</code> parameter.</p>
        single_metric_anomaly_detector: <p>A single metric anomaly detector to be created.</p> <p>When using <code>SingleMetricAnomalyDetector</code>, you cannot include the following parameters in the same operation:</p> <ul> <li> <p> <code>Dimensions</code> </p> </li> <li> <p> <code>MetricName</code> </p> </li> <li> <p> <code>Namespace</code> </p> </li> <li> <p> <code>Stat</code> </p> </li> <li> <p>the <code>MetricMathAnomalyDetector</code> parameters of <code>PutAnomalyDetectorInput</code> </p> </li> </ul> <p>Instead, specify the single metric anomaly detector attributes as part of the property <code>SingleMetricAnomalyDetector</code>.</p>
        metric_math_anomaly_detector: <p>The metric math anomaly detector to be created.</p> <p>When using <code>MetricMathAnomalyDetector</code>, you cannot include the following parameters in the same operation:</p> <ul> <li> <p> <code>Dimensions</code> </p> </li> <li> <p> <code>MetricName</code> </p> </li> <li> <p> <code>Namespace</code> </p> </li> <li> <p> <code>Stat</code> </p> </li> <li> <p>the <code>SingleMetricAnomalyDetector</code> parameters of <code>PutAnomalyDetectorInput</code> </p> </li> </ul> <p>Instead, specify the metric math anomaly detector attributes as part of the property <code>MetricMathAnomalyDetector</code>.</p>

    Raises:
        capo_cloudwatch.errors.internal_service_fault.InternalServiceFault: <p>Request processing has failed due to some unknown error, exception, or failure.</p>
        capo_cloudwatch.errors.invalid_parameter_combination_exception.InvalidParameterCombinationException: <p>Parameters were used together that cannot be used together.</p>
        capo_cloudwatch.errors.invalid_parameter_value_exception.InvalidParameterValueException: <p>The value of an input parameter is bad or out-of-range.</p>
        capo_cloudwatch.errors.limit_exceeded_exception.LimitExceededException: <p>The operation exceeded one or more limits.</p>
        capo_cloudwatch.errors.missing_required_parameter_exception.MissingRequiredParameterException: <p>An input parameter that is required is missing.</p>
        capo_cloudwatch.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_cloudwatch.types.put_anomaly_detector_input.PutAnomalyDetectorInput]",
    ) -> OperationResponse[
        "capo_cloudwatch.types.put_anomaly_detector_output.PutAnomalyDetectorOutput"
    ]:
        import capo_cloudwatch._operations.granite_service_version20100801.put_anomaly_detector

        output, http_response = (
            capo_cloudwatch._operations.granite_service_version20100801.put_anomaly_detector.put_anomaly_detector(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("PutAnomalyDetector")
    )
    input_: capo_cloudwatch.types.put_anomaly_detector_input.PutAnomalyDetectorInput = {}
    if namespace is not None:
        input_["namespace"] = namespace
    if metric_name is not None:
        input_["metric_name"] = metric_name
    if dimensions is not None:
        input_["dimensions"] = dimensions
    if stat is not None:
        input_["stat"] = stat
    if configuration is not None:
        input_["configuration"] = configuration
    if metric_characteristics is not None:
        input_["metric_characteristics"] = metric_characteristics
    if single_metric_anomaly_detector is not None:
        input_["single_metric_anomaly_detector"] = single_metric_anomaly_detector
    if metric_math_anomaly_detector is not None:
        input_["metric_math_anomaly_detector"] = metric_math_anomaly_detector

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output