[英]Obtain latest metric from CloudWatch
I'm trying to obtain a custom CloudWatch metric.我正在尝试获取自定义 CloudWatch 指标。 I don't know up front how often it reports, so I have two problems: what start time do I use and what period to specify.
我不知道它多久报告一次,所以我有两个问题:我使用什么开始时间和指定什么时间段。 Is there any way to just get the latest recorded metric, maybe within the last hour or day?
有没有办法只获取最新记录的指标,也许是在过去一小时或一天之内? Ideally I don't want to return excessive data points just to discard all but the latest and also don't want to have my period be too large and combine multiple metrics into one or too small and maybe not have data.
理想情况下,我不想返回过多的数据点只是为了丢弃除最新数据之外的所有数据点,也不希望我的周期太大并将多个指标组合成一个或太小并且可能没有数据。
CloudWatch metrics can have one of two resolutions: CloudWatch指标可以采用以下两种解决方案之一:
When you publish a custom metric, you can define it as either standard resolution or high resolution.当您发布自定义指标时,您可以将其定义为标准分辨率或高分辨率。 You can read more about this here.
您可以在此处阅读更多相关信息。
It's up to you to configure how to send your custom metric data to CloudWatch.您可以配置如何将自定义指标数据发送到 CloudWatch。 A good resource can be found here .
可以在此处找到很好的资源。
You can install and use a CloudWatch Agent to record your custom metrics, or go the route of making your own script to call the AWS CloudWatch service with the CLI.您可以安装和使用 CloudWatch 代理来记录您的自定义指标,或者 go 制作您自己的脚本以使用 CLI 调用 AWS CloudWatch 服务的途径。 From a billing perspective, there is no penalty for sending too much custom metric data to the CloudWatch service.
从计费的角度来看,向 CloudWatch 服务发送过多的自定义指标数据不会受到惩罚。 You can find out more about the CloudWatch pricing scheme here, but I suspect what you're doing will incur a negligible cost.
您可以在此处找到有关CloudWatch 定价方案的更多信息,但我怀疑您正在做的事情会产生微不足道的成本。
This might be a little late but I had the same problem.这可能有点晚了,但我遇到了同样的问题。 As it looks like, the
GetMetricDataCommand
has a MaxDatapoints
parameter which might help you:看起来,
GetMetricDataCommand
有一个MaxDatapoints
参数,它可能对您有帮助:
const command = new GetMetricDataCommand({
StartTime: new Date(new Date().setDate(today.getDate() - 30)),
EndTime: new Date(),
MetricDataQueries: [/* put your queries here */],
MaxDatapoints: 1
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.