我正在尝试使用cloudwatch代理监视内存指标,我目前有指标报告给AWS仪表板,但是当我尝试从api获取该信息时,什么也没有返回。请求成功,但值始终为0,在仪表板上我得到了真实数据。
string AccessID = "accessId";
string AccessSecret = "accessSecretId";
AmazonCloudWatchClient cloudWatchUsage = new AmazonCloudWatchClient(AccessID, AccessSecret, RegionEndpoint.USEast2);
Dimension dimension = new Dimension()
{
Name = "InstanceId",
Value = "i-Id"
};
var dimensionList = new List<Dimension>();
dimensionList.Add(dimension);
Metric metrics = new Metric();
metrics.Dimensions = dimensionList;
metrics.Namespace = "CWAgent";
metrics.MetricName = "Memory % Committed Bytes In Use";
MetricStat metricStatMemoryAverage = new MetricStat();
metricStatMemoryAverage.Metric = metrics;
metricStatMemoryAverage.Period = 300;
metricStatMemoryAverage.Stat = "Average";
metricStatMemoryAverage.Unit = StandardUnit.Percent;
MetricDataQuery metricMemoryDataQueryAverage = new MetricDataQuery();
metricMemoryDataQueryAverage.Id = "memoryUsageAverage";
metricMemoryDataQueryAverage.Label = "memoryUtilizationAverage";
metricMemoryDataQueryAverage.MetricStat = metricStatMemoryAverage;
var requestMemoryAverage = new GetMetricDataRequest
{
StartTimeUtc = testStart,
EndTimeUtc = testEnd,
MetricDataQueries = { metricMemoryDataQueryAverage }
};
var responceMemoryAverage = cloudWatchUsage.GetMetricData(requestMemoryAverage);
{
"metrics": {
"append_dimensions": {
"InstanceId": "${aws:InstanceId}"
},
"metrics_collected":{
"Memory":{
"measurement":[
"% Committed Bytes In Use"
],
"metrics_collection_interval": 60
},
"Paging File": {
"measurement": [
"% Usage"
],
"metrics_collection_interval": 60,
"resources": [
"*"
]
}
}
}
}