Hi,
I am trying to get CloudWatch metrics for my DocumentDB elastic cluster using the AWS CLI, but I always get empty datapoints. I have tried different versions of the commands, by replacing the dimension name by DBInstanceIdentifier
|| DBClusterIdentifier
, or namespace to be AWS/DocDB-Elastic
|| AWS/DocDB
such as:
aws cloudwatch get-metric-statistics \
--namespace AWS/DocDB-Elastic \
--metric-name PrimaryInstanceCPUUtilization \
--period 360 \
--statistics Average \
--start-time "$(date -u -d '1 hour ago' +'%Y-%m-%dT%H:%M:%SZ')" \
--end-time "$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
--dimensions Name=DBInstanceIdentifier,Value=docdb-elastic-sharding-id
or
aws cloudwatch get-metric-statistics \
--namespace AWS/DocDB \
--metric-name CPUUtilization \
--period 360 \
--statistics Average \
--start-time "$(date -u -d '1 hour ago' +'%Y-%m-%dT%H:%M:%SZ')" \
--end-time "$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
--dimensions Name=DBClusterIdentifier,Value=docdb-elastic-sharding-id
I also tried with a Java Program:
final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.standard()
.withCredentials(DefaultAWSCredentialsProviderChain.getInstance())
.build();
final String metricName = "PrimaryInstanceCPUUtilization";
final String namespace = "AWS/DocDB-Elastic";
final String dimensionName = "DBClusterIdentifier";
final String dimensionValue = "docdb-elastic-sharding-id";
final int period = 60;
final Date startTime = new Date(new Date().getTime() - 3600 * 1000); // 1 hour ago
final Date endTime = new Date();
GetMetricStatisticsRequest request = new GetMetricStatisticsRequest()
.withMetricName(metricName)
.withNamespace(namespace)
.withDimensions(new Dimension().withName(dimensionName).withValue(dimensionValue))
.withStartTime(startTime)
.withEndTime(endTime)
.withPeriod(period)
.withStatistics("Average");
GetMetricStatisticsResult result = cw.getMetricStatistics(request);
System.out.println(result);
However, the output is always something like this:
{
"Label": "PrimaryInstanceCPUUtilization",
"Datapoints": []
}
I have checked on the monitoring tab for this metric on the AWS DocumentDB console, and it shows data there. So I am wondering why I can't get the same data using the CLI. Is there something wrong with my commands or parameters? How can I fix this issue?
Any help or guidance would be greatly appreciated. Thank you in advance! 😊
Thank you Riku, it works. Yay!!!