【问题标题】:Getting a "singleValue" image from aws CLI using "aws cloudwatch get-metric-widget-image"使用“aws cloudwatch get-metric-widget-image”从 aws CLI 获取“singleValue”图像
【发布时间】:2019-08-16 07:43:16
【问题描述】:

在 AWS 控制台中,我可以看到这个指标:

我尝试使用 AWS CLI 获取相同的图像(使用 Cloudwatch 的 Source 选项卡中的 json):

aws cloudwatch get-metric-widget-image --metric-widget '{
    "metrics": [
        [ "AWS/ApiGateway", "Count", "ApiName", "MikeGw", "Resource", "/x/y", "Method", "POST", "Stage", "prod", { "stat": "Sum" } ]
    ],
    "view": "singleValue",
    "period": 300,
    "title": "Number of api calls",
    "setPeriodToTimeRange": true,
    "width": 1430,
    "height": 250,
    "start": "-PT3H",
    "end": "P0D"
}' | jq -r '.MetricWidgetImage' | base64 --decode >| image.png

结果如下:

好像忽略了"view": "singleValue"

如何使用这种方法获得只是计数的图像?

【问题讨论】:

    标签: amazon-cloudwatch amazon-cloudwatch-metrics


    【解决方案1】:

    不支持单值小部件。

    由于这不是一个真正的图表,它只是一个数字,您可以使用 GetMetricData API 来获取这个数字并以其他方式显示它。

    或者,如果您不介意获取图表,您可以使用 GetMetricWidgetImage API 来获取完整的图表,并在图表上使用动态标签将调用总数放入图表图例中。见这里:https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph-dynamic-labels.html

    这将为您提供与您的问题相同的图表,但标签将类似于 [Sum: 11] Count 而不仅仅是 Count

    【讨论】:

      猜你喜欢
      • 2019-04-22
      • 2019-11-01
      • 2016-12-08
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多