您可以使用GetMetricWidgetImage API 或get-metric-widget-image command 来实现。
get-metric-widget-image 命令行示例:
aws cloudwatch get-metric-widget-image --metric-widget '
{
"metrics": [
[ { "expression": "AVG(METRICS())", "label": "Average Access Speed", "id": "e1", "region": "eu-central-1" } ],
[ "...", "www.xyz.ee", { "label": "[avg: ${AVG}] www.xyz.ee", "id": "m2", "visible": false } ],
[ "...", "www.abc.com", { "label": "[avg: ${AVG}] www.abc.com", "id": "m3", "visible": false } ],
],
"view": "timeSeries",
"stacked": false,
"region": "eu-central-1",
"title": "Response Time",
"period": 300,
"stat": "Average"
}
' | jq -r .MetricWidgetImage | base64 -d | display
要获取 metric-widget 源,最简单的方法是转到 cloudwatch 仪表板,选择要编辑的小部件,然后选择“源”选项卡。在那里你可以复制源代码并在上面的命令行中使用它。
还有一个关于如何使用命令的帖子:How to use aws cloudwatch get-metric-widget-image?