Get metrics by using the Amazon CloudWatch API (original) (raw)

You can use the CloudWatch API or AWS Command Line Interface (AWS CLI) to get the CloudFront metrics in programs or applications that you build. You can use the raw data to build your own custom dashboards, your own alarming tools, and so on.

For more information, see get-metric-data in the AWS CLI Command Reference or theGetMetricData API operation in the Amazon CloudWatch API Reference.

Topics
Note

To get the CloudFront metrics from the CloudWatch API, you must use the US East (N. Virginia) Region (us-east-1). You also need to know certain values and types for each metric.

Values for all CloudFront metrics

The following values apply to all CloudFront metrics:

Namespace

The value for Namespace is alwaysAWS/CloudFront.

Dimensions

Each CloudFront metric has the following dimensions:

DistributionId

The ID of the CloudFront distribution for which you want to get metrics.

FunctionName

The name of the function (in CloudFront Functions) for which you want to get metrics.

This dimension applies only to functions.

Region

The value for Region is alwaysGlobal, because CloudFront is a global service.

Values for CloudFront distribution metrics

Use information from the following list to get details about specific CloudFront distribution metrics from the CloudWatch API. Some of these metrics are available only when you have turned on additional metrics for the distribution.

Note

Only one statistic, Average or Sum, is applicable for each metric. The following list specifies which statistic is applicable to that metric.

4xx error rate

The percentage of all viewer requests for which the response's HTTP status code is 4xx.

401 error rate

The percentage of all viewer requests for which the response's HTTP status code is 401. To get this metric, you must firstturn on additional metrics.

403 error rate

The percentage of all viewer requests for which the response's HTTP status code is 403. To get this metric, you must firstturn on additional metrics.

404 error rate

The percentage of all viewer requests for which the response's HTTP status code is 404. To get this metric, you must firstturn on additional metrics.

5xx error rate

The percentage of all viewer requests for which the response's HTTP status code is 5xx.

502 error rate

The percentage of all viewer requests for which the response's HTTP status code is 502. To get this metric, you must firstturn on additional metrics.

503 error rate

The percentage of all viewer requests for which the response's HTTP status code is 503. To get this metric, you must firstturn on additional metrics.

504 error rate

The percentage of all viewer requests for which the response's HTTP status code is 504. To get this metric, you must firstturn on additional metrics.

Bytes downloaded

The total number of bytes downloaded by viewers for GET,HEAD, and OPTIONS requests.

Bytes uploaded

The total number of bytes that viewers uploaded to your origin with CloudFront, using POST and PUT requests.

Cache hit rate

The percentage of all cacheable requests for which CloudFront served the content from its cache. HTTP POST and PUT requests, and errors, are not considered cacheable requests. To get this metric, you must first turn on additional metrics.

Origin latency

The total time spent, in milliseconds, from when CloudFront receives a request to when it starts providing a response to the network (not the viewer), for requests that are served from the origin, not the CloudFront cache. This is also known as first byte latency, or time-to-first-byte. To get this metric, you must firstturn on additional metrics.

Note

To get a Percentile statistic from the CloudWatch API, use the ExtendedStatistics parameter, notStatistics. For more information, see GetMetricStatistics in the_Amazon CloudWatch API Reference_, or the reference documentation for the AWS SDKs.

Requests

The total number of viewer requests received by CloudFront, for all HTTP methods and for both HTTP and HTTPS requests.

Total error rate

The percentage of all viewer requests for which the response's HTTP status code is 4xx or 5xx.

Values for CloudFront function metrics

Use information from the following list to get details about specific CloudFront function metrics from the CloudWatch API.

Note

Only one statistic, Average or Sum, is applicable for each metric. The following list specifies which statistic is applicable to that metric.

Invocations

The number of times the function was started (invoked) in a given time period.

Validation errors

The number of validation errors produced by the function in a given time period. Validation errors occur when the function runs successfully but returns invalid data (an invalid event object).

Execution errors

The number of execution errors that occurred in a given time period. Execution errors occur when the function fails to complete successfully.

Compute utilization

The amount of time (0-100) that the function took to run as a percentage of the maximum allowed time. For example, a value of 35 means that the function completed in 35% of the maximum allowed time.

Throttles

The number of times that the function was throttled in a given time period.