Skip to content

AWS CloudFront

Collect AWS CloudFront metrics and log data

Configuration

The core performance metrics of AWS CloudFront include total requests, data transfer volume, HTTP error rate, cache hit rate, and latency, which can help users evaluate and optimize the performance of the content delivery network.

Install Func

It is recommended to enable the Guance integration - extension - DataFlux Func (Automata): all prerequisites are automatically installed, please proceed with the script installation.

If you need to deploy Func manually, refer to Deploy Func manually

Install Script

Note: Please prepare an Amazon AK that meets the requirements in advance (for simplicity, you can directly grant global read-only permissions ReadOnlyAccess)

Managed Version Script

  1. Log in to the Guance console
  2. Click on the [Integration] menu and select [Cloud Account Management]
  3. Click [Add Cloud Account], select [AWS], and fill in the required information on the interface. If you have already configured the cloud account information before, you can skip this step
  4. Click [Test], and if the test is successful, click [Save]. If the test fails, please check if the relevant configuration information is correct and retest
  5. Click on the [Cloud Account Management] list to see the added cloud account, click on the corresponding cloud account to enter the details page
  6. Click the [Integration] button on the cloud account details page, find AWS CloudFront under the Not Installed list, and click the [Install] button to pop up the installation interface and proceed with the installation.

Manual Script

  1. Log in to the Func console, click on [Script Market], enter the Guance script market, and search for: integration_aws_cloudfront

  2. After clicking [Install], enter the corresponding parameters: AWS AK ID, AK Secret, and account name.

  3. Click [Deploy Startup Script], the system will automatically create the Startup script set and configure the corresponding startup script.

  4. After enabling, you can see the corresponding automatic trigger configuration in "Management / Automatic Trigger Configuration". Click [Execute] to execute it immediately without waiting for the scheduled time. After a while, you can check the execution task records and corresponding logs.

Verification

  1. In "Management / Automatic Trigger Configuration", confirm whether the corresponding task has the corresponding automatic trigger configuration, and check the corresponding task records and logs for any exceptions
  2. In Guance, check if there is asset information in "Infrastructure / Custom"
  3. In Guance, check if there is corresponding monitoring data in "Metrics"

Metrics

After configuring Amazon CloudWatch, the default measurement sets are as follows. You can collect more metrics through configuration Amazon CloudWatch Metrics Details

Monitoring Metrics

Metric Name Metric Chinese Name Description
Requests Total Requests The total number of viewer requests received by CloudFront for all HTTP methods and HTTP and HTTPS requests.
Bytes downloaded Downloaded Bytes The total number of bytes downloaded by viewers for GET, HEAD, and OPTIONS requests.
Bytes uploaded Uploaded Bytes The total number of bytes uploaded by viewers to your origin via CloudFront using POST and PUT requests.
4xx error rate 4xx Errors The percentage of all viewer requests with an HTTP status code of 4xx.
5xx error rate 5xx Errors The percentage of all viewer requests with an HTTP status code of 5xx.
Total error rate Total Errors The percentage of all viewer requests with an HTTP status code of 4xx or 5xx.

Logging

CloudFront

Log Collection Method

  • You can configure CloudFront to create log files that contain detailed information about each user (viewer) request received by CloudFront and store them in an S3 bucket. These logs are called standard logs, also known as access logs.
  • S3 triggers an Event to call a Lambda function, and data is reported to the platform through DataKit or DataWay (recommended to upload directly through DataWay)

CloudFront Logs Writing to S3 Bucket

  1. Select the corresponding CloudFront distribution and enter the details page
  2. In the 【Logging】 page, click 【Edit】 in the 【Settings】 section
  3. In the 【Standard Log Destination】 section, click 【Add】, select Amazon S3.
  4. Select the S3 bucket created for the log files, select the required log fields (you can add fields such as DistrubtionId, c-country, etc.), and select the output format as JSON.
  5. Click 【Submit】 to save the configuration.

Lambda Configuration

Refer to: Lambda Fetch S3 Log Data

Log Parsing

Guance has built-in CloudFront log parsing. You can go to [Logs] - [Pipelines] - [Pipeline Library] - select CloudFront, add it as a Central Pipeline, and save. This will take effect for newly reported data.

Object

The reported data example is as follows:

{
  "measurement": "aws_cloudfront",
  "tags": {
    "ARN": "arn:aws-cn:cloudfront::F",
    "DomainName": "d3q33pv83.cloudfront.cn",
    "Id": "E183FMUG1QDCZF",
    "Status": "Deployed",
    "name": "E183FMUG1ZF"
  },
  "fields": {
    "CreatedDate"              : "2022-03-09T06:13:31Z",
    "ApiKeySelectionExpression": "$request.header.",
    "DisableSchemaValidation"  : "xxxxx",
    "Description"              : "Created by AWS Lambda"
  }
}

Note: The fields in tags and fields may change with subsequent updates

Feedback

Is this page helpful? ×