1
votes

AWS Cloudwatch stores custom metrics for a duration dependent upon the metric's period:

  • Data points with a period of less than 60 seconds are available for 3 hours. These data points are high-resolution custom metrics.
  • Data points with a period of 60 seconds (1 minute) are available for 15 days
  • Data points with a period of 300 seconds (5 minute) are available for 63 days
  • Data points with a period of 3600 seconds (1 hour) are available for 455 days (15 months)

from https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html

However, I cannot find out how to set the Period for a given metric using the JS SDK:

// Calling the putMetricData operation

var params = {
  MetricData: [ /* required */
    {
      MetricName: 'STRING_VALUE', /* required */
      Counts: [
        'NUMBER_VALUE',
        /* more items */
      ],
      Dimensions: [
        {
          Name: 'STRING_VALUE', /* required */
          Value: 'STRING_VALUE' /* required */
        },
        /* more items */
      ],
      StatisticValues: {
        Maximum: 'NUMBER_VALUE', /* required */
        Minimum: 'NUMBER_VALUE', /* required */
        SampleCount: 'NUMBER_VALUE', /* required */
        Sum: 'NUMBER_VALUE' /* required */
      },
      StorageResolution: 'NUMBER_VALUE',
      Timestamp: new Date || 'Wed Dec 31 1969 16:00:00 GMT-0800 (PST)' || 123456789,
      Unit: Seconds | Microseconds | Milliseconds | Bytes | Kilobytes | Megabytes | Gigabytes | Terabytes | Bits | Kilobits | Megabits | Gigabits | Terabits | Percent | Count | Bytes/Second | Kilobytes/Second | Megabytes/Second | Gigabytes/Second | Terabytes/Second | Bits/Second | Kilobits/Second | Megabits/Second | Gigabits/Second | Terabits/Second | Count/Second | None,
      Value: 'NUMBER_VALUE',
      Values: [
        'NUMBER_VALUE',
        /* more items */
      ]
    },
    /* more items */
  ],
  Namespace: 'STRING_VALUE' /* required */
};
cloudwatch.putMetricData(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatch.html#putMetricData-property

There's references to period elsewhere in the docs, but not directly relating to MetricData. Is a "Data point" different from "Metric Data"?

How do I control how long metric data will survive?

Edit, more information:

CloudWatch metrics are rolled up over time; resolution effectively decreases as the metrics age. Here’s the schedule:

1 second metrics are available for 3 hours.
60 second metrics are available for 15 days.
5 minute metrics are available for 63 days.
1 hour metrics are available for 455 days (15 months).

When you call GetMetricStatistics you can specify a period of 1, 5, 10, 30 or any multiple of 60 seconds for high-resolution metrics. You can specify any multiple of 60 seconds for standard metrics. from https://aws.amazon.com/blogs/aws/new-high-resolution-custom-metrics-and-alarms-for-amazon-cloudwatch/ Based on this post, it sounds like data points will automatically average metrics as they age. In that case does this mean that data points are only entirely deleted once they fully expire at 15 months?

1

1 Answers

3
votes

You're not controlling how long the data will be stored, you control how often you publish the data.

For example, if you publish your data once every minute, you can graph it at 1 minute resolution for 15 days. When the data ages over 15 days, you can only graph it at 5 minute resolution. Same for 1 hour.

Exception is the data at resolution lower than 1 minute. In that case you need to publish the resolution you need. If you publish data every second and you want to graph it at 1 second resolution, you would set StorageResolution=1.

Period is used for graphing the data or retrieving the data via the APIs. Even if you publish the data every minute for example, you may want to graph 1 hour or 1 days aggregates of the data. In that case you would set the period to 3600 or 86400.