简体   繁体   English

从 CloudWatch 获取最新指标

[英]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指标可以采用以下两种解决方案之一:

  1. Standard resolution, with data having a one-minute granularity.标准分辨率,数据具有一分钟的粒度。
  2. High resolution, with data at a granularity of one second .高分辨率,数据粒度为一秒

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.

相关问题 如何从日志组指标过滤器创建 CloudWatch 警报 - How to create a CloudWatch alarm from log group metric filter CloudWatch 指标过滤器中的布尔值问题 - Problem with booleans in CloudWatch Metric Filters 从 AWS CloudWatch 指标数学搜索中获取单个时间序列 function - Getting single time series from AWS CloudWatch metric maths SEARCH function CloudWatch 日志过滤器计数指标值 < 1 - CloudWatch log filter count metric values are < 1 CloudWatch 指标过滤器,用于检查 JSON 键是否存在 - CloudWatch Metric Filter for checking JSON key exists 无法使用 getMetricStatistics 获取 cloudwatch 指标数据 - cannot get cloudwatch metric data with getMetricStatistics AWS CloudWatch 代理指标错误 - MetricDataQueries 中参数 ID 的值不唯一 - AWS CloudWatch Agent Metric Error - The values for parameter id in MetricDataQueries are not unique CloudWatch 自定义指标可以是变量而不是硬编码字符串吗 - Can a CloudWatch Custom Metric be a variable instead of a hard-coded string 设置 CloudWatch 警报时,哪个“统计数据”适合“StatusCheckFailed”指标? - Which "statistic" is proper for "StatusCheckFailed" metric while setting CloudWatch alarms? 在 AWS cloudwatch 仪表板中,我可以 select 绘制指标的所有维度吗 - in AWS cloudwatch dashboard, can i select to chart all dimensions of a metric
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM