AWS-SDK CloudWatch MaxQueryTimerangeExceed
我是AWS SDK(和nodejs)的新手,我正在尝试让CloudWatch的GetMetricData工作。我使用简单的CloudWatch查询来获取实例的CPU利用率。但是无论我做什么,我一直在
{
ResponseMetadata: { RequestId: '5253fbfc-5aa2-4dfb-871b-1453f8610d80' },
MetricDataResults: [
{
Id: 'q1',
Label: 'q1',
Timestamps: [],
Values: [],
StatusCode: 'Complete',
Messages: []
}
],
Messages: [
{
Code: 'MaxQueryTimeRangeExceeded',
Value: 'Max time window exceeded for query'
}
]
}
这里得到这个是我的代码
const AWS = require("aws-sdk");
AWS.config.loadFromPath("./config.json");
var cloudwatch = new AWS.CloudWatch({apiVersion: "2010-08-01"});
var params = {
StartTime: new Date('june 06, 2022 17:30'),
EndTime: new Date('june 06, 2022 18:00'),
MetricDataQueries: [
{
Id: 'q1',
Expression: "SELECT AVG(CPUUtilization) FROM SCHEMA(\"AWS/EC2\", InstanceId) WHERE InstanceId = 'i-**********'",
Period: '600'
},
],
};
cloudwatch.getMetricData(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
});
I am new to AWS SDK (and nodejs) and I am trying to get cloudwatch's getMetricData to work. Im using a simple Cloudwatch query to grab the CPU utilization of an instance. But no matter what I do, I just keep getting this
{
ResponseMetadata: { RequestId: '5253fbfc-5aa2-4dfb-871b-1453f8610d80' },
MetricDataResults: [
{
Id: 'q1',
Label: 'q1',
Timestamps: [],
Values: [],
StatusCode: 'Complete',
Messages: []
}
],
Messages: [
{
Code: 'MaxQueryTimeRangeExceeded',
Value: 'Max time window exceeded for query'
}
]
}
here is my code
const AWS = require("aws-sdk");
AWS.config.loadFromPath("./config.json");
var cloudwatch = new AWS.CloudWatch({apiVersion: "2010-08-01"});
var params = {
StartTime: new Date('june 06, 2022 17:30'),
EndTime: new Date('june 06, 2022 18:00'),
MetricDataQueries: [
{
Id: 'q1',
Expression: "SELECT AVG(CPUUtilization) FROM SCHEMA(\"AWS/EC2\", InstanceId) WHERE InstanceId = 'i-**********'",
Period: '600'
},
],
};
cloudwatch.getMetricData(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只能使用
选择...
语法请求最新的3个小时数据。来自 docs
看起来您只为一个实例获得
cpuutilization
。您可以使用metricstat
对象获得它。这样的事情:You can only request the latest 3 hours of data using the
SELECT ...
syntax.From docs,
Looks like you're only getting the
CPUUtilization
for a single instance. You can get that with theMetricStat
object. Something like this: