4
votes

Is there a way to display CloudFront metrics inside an existing CloudWatch dashboard ?

I can view CloudFront distributions metrics in the CloudFront console (Total requests, hit ratio ...) but i cant find theses metrics in CloudWatch dashboards.

On the Cloudfront documentation (https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cf-metricscollected.html) they talk about the "AWS/CloudFront" namespace, but there is no metric attached to this namespace in CloudWatch.

Also, I suspected there is an option to enable metrics(like the one to have detailed statistics from S3) , but I did not find such option.

I prefere having all metrics inside a single dashboard, it is easier to cross data (EC2 cpu utilization vs database connection vs cloudwatch req/s for example).

2

2 Answers

11
votes

Try to look in region us-east-1. You can find them there only because all CloudFront distributions are placed in us-east-1.

From there you can add them to your dashboard ;)

0
votes

You can write cloudwatch dashboard template and give the region in that resource available.

enter image description here

Below is a sample template, In which regions are given different as per resources.

You can set x,y, width and height as you want.

``

{
    "widgets": [
        {
            "type": "text",
            "x": 0,
            "y": 0,
            "width": 24,
            "height": 2,
            "properties": {
                "markdown": "\n# Resource Monitoring\n"
            }
        },
        {
            "type": "metric",
            "x": 16,
            "y": 2,
            "width": 8,
            "height": 5,
            "properties": {
                "metrics": [
                    [ "AWS/ApiGateway", "Count", "ApiName", "ApiGateway_name", { "stat": "SampleCount", "id": "m0r0" } ]
                ],
                "region": "ap-southeast-1",
                "title": "Count",
                "legend": {
                    "position": "right"
                },
                "copilot": true
            }
        },
        {
            "type": "metric",
            "x": 0,
            "y": 31,
            "width": 12,
            "height": 5,
            "properties": {
                "metrics": [
                    [ "AWS/CloudFront", "Requests", "DistributionId", "gfajshgjk", "Region", "Global", { "stat": "Sum", "id": "m0r0", "label": "cf_name" } ]
                ],
                "region": "us-east-1",
                "title": "Requests",
                "copilot": true
            }
        }
    ]
}

``