Skip to content

list_metrics

list_metrics(
    *,
    config_overrides: Optional[CloudWatchClientConfig] = None,
    namespace: Optional[Namespace] = None,
    metric_name: Optional[MetricName] = None,
    dimensions: Optional[DimensionFilters] = None,
    next_token: Optional[NextToken] = None,
    recently_active: Optional[RecentlyActive] = None,
    include_linked_accounts: Optional[IncludeLinkedAccounts] = None,
    owning_account: Optional[AccountId] = None,
) -> ListMetricsOutput

List the specified metrics. You can use the returned metrics with GetMetricData or GetMetricStatistics to get statistical data.

Up to 500 results are returned for any one call. To retrieve additional results, use the returned token with subsequent calls.

After you create a metric, allow up to 15 minutes for the metric to appear. To see metric statistics sooner, use GetMetricData or GetMetricStatistics.

If you are using CloudWatch cross-account observability, you can use this operation in a monitoring account and view metrics from the linked source accounts. For more information, see CloudWatch cross-account observability.

ListMetrics doesn't return information about metrics if those metrics haven't reported data in the past two weeks. To retrieve those metrics, use GetMetricData or GetMetricStatistics.

Parameters:

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

    The metric namespace to filter against. Only the namespace that matches exactly will be returned.

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

    The name of the metric to filter against. Only the metrics with names that match exactly will be returned.

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

    The dimensions to filter against. Only the dimension with names that match exactly will be returned. If you specify one dimension name and a metric has that dimension and also other dimensions, it will be returned.

  • next_token (Optional[NextToken], default: None ) –

    The token returned by a previous call to indicate that there is more data available.

  • recently_active (Optional[RecentlyActive], default: None ) –

    To filter the results to show only metrics that have had data points published in the past three hours, specify this parameter with a value of PT3H. This is the only valid value for this parameter.

    The results that are returned are an approximation of the value you specify. There is a low probability that the returned results include metrics with last published data as much as 50 minutes more than the specified time interval.

  • include_linked_accounts (Optional[IncludeLinkedAccounts], default: None ) –

    If you are using this operation in a monitoring account, specify true to include metrics from source accounts in the returned data.

    The default is false.

  • owning_account (Optional[AccountId], default: None ) –

    When you use this operation in a monitoring account, use this field to return metrics only from one source account. To do so, specify that source account ID in this field, and also specify true for IncludeLinkedAccounts.

Raises:

Source code in docs_src/capo_cloudwatch/_services/cloud_watch.py
def list_metrics(
    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.dimension_filters.DimensionFilters"
    ] = None,
    next_token: Optional["capo_cloudwatch.types.next_token.NextToken"] = None,
    recently_active: Optional[
        "capo_cloudwatch.types.recently_active.RecentlyActive"
    ] = None,
    include_linked_accounts: Optional[
        "capo_cloudwatch.types.include_linked_accounts.IncludeLinkedAccounts"
    ] = None,
    owning_account: Optional["capo_cloudwatch.types.account_id.AccountId"] = None,
) -> "capo_cloudwatch.types.list_metrics_output.ListMetricsOutput":
    """<p>List the specified metrics. You can use the returned metrics with <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricData.html">GetMetricData</a> or <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricStatistics.html">GetMetricStatistics</a> to get statistical data.</p> <p>Up to 500 results are returned for any one call. To retrieve additional results, use the returned token with subsequent calls.</p> <p>After you create a metric, allow up to 15 minutes for the metric to appear. To see metric statistics sooner, use <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricData.html">GetMetricData</a> or <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricStatistics.html">GetMetricStatistics</a>.</p> <p>If you are using CloudWatch cross-account observability, you can use this operation in a monitoring account and view metrics from the linked source accounts. For more information, see <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Unified-Cross-Account.html">CloudWatch cross-account observability</a>.</p> <p> <code>ListMetrics</code> doesn't return information about metrics if those metrics haven't reported data in the past two weeks. To retrieve those metrics, use <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricData.html">GetMetricData</a> or <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_GetMetricStatistics.html">GetMetricStatistics</a>.</p>

    Args:
        namespace: <p>The metric namespace to filter against. Only the namespace that matches exactly will be returned.</p>
        metric_name: <p>The name of the metric to filter against. Only the metrics with names that match exactly will be returned.</p>
        dimensions: <p>The dimensions to filter against. Only the dimension with names that match exactly will be returned. If you specify one dimension name and a metric has that dimension and also other dimensions, it will be returned.</p>
        next_token: <p>The token returned by a previous call to indicate that there is more data available.</p>
        recently_active: <p>To filter the results to show only metrics that have had data points published in the past three hours, specify this parameter with a value of <code>PT3H</code>. This is the only valid value for this parameter.</p> <p>The results that are returned are an approximation of the value you specify. There is a low probability that the returned results include metrics with last published data as much as 50 minutes more than the specified time interval.</p>
        include_linked_accounts: <p>If you are using this operation in a monitoring account, specify <code>true</code> to include metrics from source accounts in the returned data.</p> <p>The default is <code>false</code>.</p>
        owning_account: <p>When you use this operation in a monitoring account, use this field to return metrics only from one source account. To do so, specify that source account ID in this field, and also specify <code>true</code> for <code>IncludeLinkedAccounts</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_value_exception.InvalidParameterValueException: <p>The value of an input parameter is bad or out-of-range.</p>
        capo_cloudwatch.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_cloudwatch.types.list_metrics_input.ListMetricsInput]",
    ) -> OperationResponse[
        "capo_cloudwatch.types.list_metrics_output.ListMetricsOutput"
    ]:
        import capo_cloudwatch._operations.granite_service_version20100801.list_metrics

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ListMetrics")
    )
    input_: capo_cloudwatch.types.list_metrics_input.ListMetricsInput = {}
    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 next_token is not None:
        input_["next_token"] = next_token
    if recently_active is not None:
        input_["recently_active"] = recently_active
    if include_linked_accounts is not None:
        input_["include_linked_accounts"] = include_linked_accounts
    if owning_account is not None:
        input_["owning_account"] = owning_account

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