Skip to content

get_metric_widget_image async

get_metric_widget_image(
    *,
    config_overrides: Optional[AsyncCloudWatchClientConfig] = None,
    metric_widget: Optional[MetricWidget] = None,
    output_format: Optional[OutputFormat] = None,
) -> GetMetricWidgetImageOutput

You can use the GetMetricWidgetImage API to retrieve a snapshot graph of one or more Amazon CloudWatch metrics as a bitmap image. You can then embed this image into your services and products, such as wiki pages, reports, and documents. You could also retrieve images regularly, such as every minute, and create your own custom live dashboard.

The graph you retrieve can include all CloudWatch metric graph features, including metric math and horizontal and vertical annotations.

There is a limit of 20 transactions per second for this API. Each GetMetricWidgetImage action has the following limits:

  • As many as 100 metrics in the graph.

  • Up to 100 KB uncompressed payload.

Parameters:

  • metric_widget (Optional[MetricWidget], default: None ) –

    A JSON string that defines the bitmap graph to be retrieved. The string includes the metrics to include in the graph, statistics, annotations, title, axis limits, and so on. You can include only one MetricWidget parameter in each GetMetricWidgetImage call.

    For more information about the syntax of MetricWidget see GetMetricWidgetImage: Metric Widget Structure and Syntax.

    If any metric on the graph could not load all the requested data points, an orange triangle with an exclamation point appears next to the graph legend.

  • output_format (Optional[OutputFormat], default: None ) –

    The format of the resulting image. Only PNG images are supported.

    The default is png. If you specify png, the API returns an HTTP response with the content-type set to text/xml. The image data is in a MetricWidgetImage field. For example:

    >

    iVBORw0KGgoAAAANSUhEUgAAAlgAAAGQEAYAAAAip...

    6f0d4192-4d42-11e8-82c1-f539a07e0e3b

    The image/png setting is intended only for custom HTTP requests. For most use cases, and all actions using an Amazon Web Services SDK, you should use png. If you specify image/png, the HTTP response has a content-type set to image/png, and the body of the response is a PNG image.

Raises:

Source code in docs_src/capo_cloudwatch/_services/async_cloud_watch.py
async def get_metric_widget_image(
    self,
    *,
    config_overrides: Optional[AsyncCloudWatchClientConfig] = None,
    metric_widget: Optional[
        "capo_cloudwatch.types.metric_widget.MetricWidget"
    ] = None,
    output_format: Optional[
        "capo_cloudwatch.types.output_format.OutputFormat"
    ] = None,
) -> "capo_cloudwatch.types.get_metric_widget_image_output.GetMetricWidgetImageOutput":
    """<p>You can use the <code>GetMetricWidgetImage</code> API to retrieve a snapshot graph of one or more Amazon CloudWatch metrics as a bitmap image. You can then embed this image into your services and products, such as wiki pages, reports, and documents. You could also retrieve images regularly, such as every minute, and create your own custom live dashboard.</p> <p>The graph you retrieve can include all CloudWatch metric graph features, including metric math and horizontal and vertical annotations.</p> <p>There is a limit of 20 transactions per second for this API. Each <code>GetMetricWidgetImage</code> action has the following limits:</p> <ul> <li> <p>As many as 100 metrics in the graph.</p> </li> <li> <p>Up to 100 KB uncompressed payload.</p> </li> </ul>

    Args:
        metric_widget: <p>A JSON string that defines the bitmap graph to be retrieved. The string includes the metrics to include in the graph, statistics, annotations, title, axis limits, and so on. You can include only one <code>MetricWidget</code> parameter in each <code>GetMetricWidgetImage</code> call.</p> <p>For more information about the syntax of <code>MetricWidget</code> see <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Metric-Widget-Structure.html">GetMetricWidgetImage: Metric Widget Structure and Syntax</a>.</p> <p>If any metric on the graph could not load all the requested data points, an orange triangle with an exclamation point appears next to the graph legend.</p>
        output_format: <p>The format of the resulting image. Only PNG images are supported.</p> <p>The default is <code>png</code>. If you specify <code>png</code>, the API returns an HTTP response with the content-type set to <code>text/xml</code>. The image data is in a <code>MetricWidgetImage</code> field. For example:</p> <p> <code> <GetMetricWidgetImageResponse xmlns=<URLstring>></code> </p> <p> <code> <GetMetricWidgetImageResult></code> </p> <p> <code> <MetricWidgetImage></code> </p> <p> <code> iVBORw0KGgoAAAANSUhEUgAAAlgAAAGQEAYAAAAip...</code> </p> <p> <code> </MetricWidgetImage></code> </p> <p> <code> </GetMetricWidgetImageResult></code> </p> <p> <code> <ResponseMetadata></code> </p> <p> <code> <RequestId>6f0d4192-4d42-11e8-82c1-f539a07e0e3b</RequestId></code> </p> <p> <code> </ResponseMetadata></code> </p> <p> <code></GetMetricWidgetImageResponse></code> </p> <p>The <code>image/png</code> setting is intended only for custom HTTP requests. For most use cases, and all actions using an Amazon Web Services SDK, you should use <code>png</code>. If you specify <code>image/png</code>, the HTTP response has a content-type set to <code>image/png</code>, and the body of the response is a PNG image.</p>

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

    async def _handler(
        req: "AsyncOperationRequest[capo_cloudwatch.types.get_metric_widget_image_input.GetMetricWidgetImageInput]",
    ) -> AsyncOperationResponse[
        "capo_cloudwatch.types.get_metric_widget_image_output.GetMetricWidgetImageOutput"
    ]:
        import capo_cloudwatch._operations.granite_service_version20100801.get_metric_widget_image

        (
            output,
            http_response,
        ) = await capo_cloudwatch._operations.granite_service_version20100801.get_metric_widget_image.async_get_metric_widget_image(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("GetMetricWidgetImage")
    )
    input_: capo_cloudwatch.types.get_metric_widget_image_input.GetMetricWidgetImageInput = {}
    if metric_widget is not None:
        input_["metric_widget"] = metric_widget
    if output_format is not None:
        input_["output_format"] = output_format

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output