Show anomaly detector band using GetMetricWidgetImage API

0

Hello everyone, I have set up a rule in EventBridge. When Cloudwatch state become alarm, Lambda will be called to send messages and metrics's image.

I want to know how can I show the anomaly detector band in the grapth background like I view it in metrics ? Thanks.


This is image api's json code I pasted in Lambda.

{
        "metrics": [
            [ "AWS/CloudFront", "BytesDownloaded", "Region", "Global", "DistributionId", "***********", { "id": "m1", "visible": True } ],
            [ { "id": "ad1", "label": "Expected", "expression": "ANOMALY_DETECTION_BAND(m1, 3)", "visible": True, "color": "#000000", "yAxis": "left" } ]
        ],
        "view": "timeSeries",
        "stacked": False,
        "period": 300,
        "stat": "Average",
        "annotations": {
            "horizontal": [],
            "vertical": []
        },
        "setPeriodToTimeRange": True,
        "width": 854,
        "height": 480,
        "start": "-PT3H",
        "end": "P0D",
        "timezone": "+0800"
    }

在此輸入圖片描述

Kerr
已提問 8 個月前檢視次數 514 次
2 個答案
0

Hi,

I followed Gabriel's advice and I was not able to produce a metric widget using AWS CLI.

Some suggestions seems to not work at all. For example, the property view can only be one of timeSeries, bar or pie, there is no "timeSeriesStacked". Also property "type" inside the metric does work either.

Best

C
已回答 7 個月前
-1

Hi Kerr,

To display the anomaly detection band in a graph background for CloudWatch metrics using an AWS Lambda function and the Image API, you need to modify the JSON code you provided to include the band definition. Here's how you can do it:

  1. Add a new "band" element within the "metrics" section, specifying the anomaly detection band:
"metrics": [
    ["AWS/CloudFront", "BytesDownloaded", "Region", "Global", "DistributionId", "***********", { "id": "m1", "visible": true }],
    [{ "id": "ad1", "label": "Expected", "expression": "ANOMALY_DETECTION_BAND(m1, 3)", "visible": true, "color": "#000000", "yAxis": "left" }],
    [{ "expression": "m1 + ad1", "label": "Band", "color": "#c4c4c4", "yAxis": "left", "type": "area", "id": "band1" }]
],

In the code above, a new metric "Band" is defined, which is the sum of your original metric "m1" (BytesDownloaded) and the anomaly detection band "ad1." The "type" is set to "area," which creates a filled area graph representing the band.

  1. Adjust the "view" parameter to "timeSeriesStacked," which is commonly used to display anomaly detection bands:
"view": "timeSeriesStacked",
  1. Update the "stacked" parameter to "true" to ensure the graph displays the anomaly detection band:
"stacked": true,
  1. Ensure that you have appropriate permissions for your Lambda function to access CloudWatch metrics and make the necessary modifications to the Lambda code to generate and display the graph as needed.

With these modifications, your CloudWatch graph generated using the Image API should include the anomaly detection band in the background, providing a visual representation of expected values and deviations.

Please give a thumbs up if my suggestion helps

profile picture
已回答 8 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南