Empty datapoints when querying CloudWatch metrics for DocumentDB elastic cluster

0

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! 😊

2 Answers
0
Accepted Answer

Hello.

Try running the command with the dimensions "ClusterName", "ClusterId", and "ShardId".

aws cloudwatch get-metric-statistics \
    --namespace AWS/DocDB-Elastic \
    --metric-name PrimaryInstanceCPUUtilization \
    --period 360 \
    --start-time "$(date -u -d '1 hour ago' +'%Y-%m-%dT%H:%M:%SZ')" \
    --end-time "$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \
    --statistics Average --dimensions Name=ClusterName,Value=test Name=ClusterId,Value=cdbeaxxxxxxxxxxx Name=ShardId,Value=d618xxxxxxxxxxxxxxx

The metrics show that the dimensions are as follows, which must also be specified in the command options.
cw

profile picture
EXPERT
answered 7 months ago
  • Thank you Riku, it works. Yay!!!

        "Label": "PrimaryInstanceCPUUtilization",
        "Datapoints": [
            {
                "Timestamp": "2023-09-21T15:12:00+00:00",
                "Average": 7.508333333333333,
                "Unit": "Percent"
            },
            {
                "Timestamp": "2023-09-21T14:54:00+00:00",
                "Average": 7.473611111111111,
                "Unit": "Percent"
            },
            {
                "Timestamp": "2023-09-21T15:00:00+00:00",
                "Average": 7.713888888888889,
                "Unit": "Percent"
            },
    
0

Hi, I ran the following for Sagemaker endpoint, it gave me empty data point. Can you please help ?

aws cloudwatch get-metric-statistics
--namespace AWS/SageMaker
--metric-name CPUUtilization
--period 720
--start-time "$(date -u -d '1 week ago' '+%Y-%m-%dT%H:%M:%S')"
--end-time "$(date -u '+%Y-%m-%dT%H:%M:%S')"
--statistics Average --dimensions Name=EndpointName,Value=mysagemakerendpointname Name=VariantName,Value=CPUUtilization

Output:- { "Label": "CPUUtilization", "Datapoints": [] }

Sanjaya
answered 3 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions