Skip to content

describe_alarms_for_metric

describe_alarms_for_metric(
    *,
    config_overrides: Optional[CloudWatchClientConfig] = None,
    metric_name: Optional[MetricName] = None,
    namespace: Optional[Namespace] = None,
    statistic: Optional[Statistic] = None,
    extended_statistic: Optional[ExtendedStatistic] = None,
    dimensions: Optional[Dimensions] = None,
    period: Optional[Period] = None,
    unit: Optional[StandardUnit] = None,
) -> DescribeAlarmsForMetricOutput

Retrieves the alarms for the specified metric. To filter the results, specify a statistic, period, or unit.

This operation retrieves only standard alarms that are based on the specified metric. It does not return alarms based on math expressions that use the specified metric, or composite alarms that use the specified metric.

Parameters:

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

    The name of the metric.

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

    The namespace of the metric.

  • statistic (Optional[Statistic], default: None ) –

    The statistic for the metric, other than percentiles. For percentile statistics, use ExtendedStatistics.

  • extended_statistic (Optional[ExtendedStatistic], default: None ) –

    The percentile statistic for the metric. Specify a value between p0.0 and p100.

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

    The dimensions associated with the metric. If the metric has any associated dimensions, you must specify them in order for the call to succeed.

  • period (Optional[Period], default: None ) –

    The period, in seconds, over which the statistic is applied.

  • unit (Optional[StandardUnit], default: None ) –

    The unit for the metric.

Raises:

Source code in docs_src/capo_cloudwatch/_services/cloud_watch.py
def describe_alarms_for_metric(
    self,
    *,
    config_overrides: Optional[CloudWatchClientConfig] = None,
    metric_name: Optional["capo_cloudwatch.types.metric_name.MetricName"] = None,
    namespace: Optional["capo_cloudwatch.types.namespace.Namespace"] = None,
    statistic: Optional["capo_cloudwatch.types.statistic.Statistic"] = None,
    extended_statistic: Optional[
        "capo_cloudwatch.types.extended_statistic.ExtendedStatistic"
    ] = None,
    dimensions: Optional["capo_cloudwatch.types.dimensions.Dimensions"] = None,
    period: Optional["capo_cloudwatch.types.period.Period"] = None,
    unit: Optional["capo_cloudwatch.types.standard_unit.StandardUnit"] = None,
) -> "capo_cloudwatch.types.describe_alarms_for_metric_output.DescribeAlarmsForMetricOutput":
    """<p>Retrieves the alarms for the specified metric. To filter the results, specify a statistic, period, or unit.</p> <p>This operation retrieves only standard alarms that are based on the specified metric. It does not return alarms based on math expressions that use the specified metric, or composite alarms that use the specified metric.</p>

    Args:
        metric_name: <p>The name of the metric.</p>
        namespace: <p>The namespace of the metric.</p>
        statistic: <p>The statistic for the metric, other than percentiles. For percentile statistics, use <code>ExtendedStatistics</code>.</p>
        extended_statistic: <p>The percentile statistic for the metric. Specify a value between p0.0 and p100.</p>
        dimensions: <p>The dimensions associated with the metric. If the metric has any associated dimensions, you must specify them in order for the call to succeed.</p>
        period: <p>The period, in seconds, over which the statistic is applied.</p>
        unit: <p>The unit for the metric.</p>

    Raises:
        capo_cloudwatch.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_cloudwatch.types.describe_alarms_for_metric_input.DescribeAlarmsForMetricInput]",
    ) -> OperationResponse[
        "capo_cloudwatch.types.describe_alarms_for_metric_output.DescribeAlarmsForMetricOutput"
    ]:
        import capo_cloudwatch._operations.granite_service_version20100801.describe_alarms_for_metric

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DescribeAlarmsForMetric")
    )
    input_: capo_cloudwatch.types.describe_alarms_for_metric_input.DescribeAlarmsForMetricInput = {}
    if metric_name is not None:
        input_["metric_name"] = metric_name
    if namespace is not None:
        input_["namespace"] = namespace
    if statistic is not None:
        input_["statistic"] = statistic
    if extended_statistic is not None:
        input_["extended_statistic"] = extended_statistic
    if dimensions is not None:
        input_["dimensions"] = dimensions
    if period is not None:
        input_["period"] = period
    if unit is not None:
        input_["unit"] = unit

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