[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-14。"],[[["\u003cp\u003eEach Cloud CDN request is logged and can be accessed through the Google Cloud console's Logs Explorer, specifically under the Cloud HTTP Load Balancer resource.\u003c/p\u003e\n"],["\u003cp\u003eCloud CDN logs are primarily indexed by forwarding rule and then by URL map, which allows for granular log viewing, filtering by forwarding rule or URL map.\u003c/p\u003e\n"],["\u003cp\u003eYou can determine if a request was served from the backend or from the cache by examining fields such as \u003ccode\u003ehttpRequest\u003c/code\u003e and \u003ccode\u003ejsonPayload\u003c/code\u003e in the log entries.\u003c/p\u003e\n"],["\u003cp\u003eCloud CDN logs include specific fields like \u003ccode\u003ejsonPayload.cacheId\u003c/code\u003e to identify the cache location and instance, along with \u003ccode\u003estatusDetails\u003c/code\u003e to indicate the nature of the cache interaction (hit, miss, or revalidation).\u003c/p\u003e\n"],["\u003cp\u003eCloud Monitoring is used to manage the health of a Cloud CDN deployment and custom dashboards with MQL can be created to monitor metrics such as request bytes, client roundtrip TCP latency, and request count, broken out by various factors.\u003c/p\u003e\n"]]],[],null,["# Logs and metrics for caching\n\nEach Cloud CDN request is logged in\n[Cloud Logging](/logging/docs/write-query-log-entries-gcloud).\nFor information about enabling and disabling logging, see the [External Application Load Balancer\nand Cloud CDN logging and\nmonitoring overview](/cdn/docs/cdn-logging-monitoring).\n\nLogs for Cloud CDN are associated with the external Application Load Balancer that your\nCloud CDN backends are attached to. Cloud CDN logs are indexed\nfirst by [forwarding rule](/load-balancing/docs/forwarding-rule-concepts) and\nthen by [URL map](/load-balancing/docs/url-map-concepts).\n\nTo view Cloud CDN logs, follow these steps. \n\n### Console\n\n1. In the Google Cloud console, go to the **Logs Explorer** page.\n\n [Go to Logs Explorer](https://console.cloud.google.com/logs?service=network.googleapis.com)\n2. In the **Resource** menu, select **Cloud HTTP Load Balancer**.\n3. View logs as follows:\n - **View all logs:** select the **Resource** menu, and then select **All forwarding rules**.\n - **View the logs for a forwarding rule:** select the forwarding rule name from the list of forwarding rules.\n - **View the logs for a URL map used by a forwarding rule:** select a forwarding rule, and then select a URL map.\n\nRequest served from the backend\n-------------------------------\n\nTo confirm that a request is served from a Cloud CDN-enabled backend,\nthere are three main fields to look for, as follows:\n\n- `httpRequest`: When a request is served from a backend, you can see that the cache is filled and you can confirm the request URL.\n - `cacheFillBytes:` \u003cvar translate=\"no\"\u003eNUMBER_OF_BYTES\u003c/var\u003e\n - `cacheLookup: True`\n - `requestURL`: \u003cvar translate=\"no\"\u003eURL\u003c/var\u003e\n- `jsonPayload`: From the `statusDetails` field, you can confirm that the response was served by the backend.\n - `statusDetails: \"response_sent_by_backend\"`\n\nRequest served from cache\n-------------------------\n\nThe following log entry shows a cache hit. \n\n```\n {\n insertId: \"1oek5rg3l3fxj7\"\n jsonPayload: {\n @type: \"type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry\"\n cacheId: \"SFO-fbae48ad\"\n statusDetails: \"response_from_cache\"\n }\n httpRequest: {\n requestMethod: \"GET\"\n requestUrl: \"http://LOAD_BALANCER_IP_ADDRESS/static/us/three-cats.jpg\"\n requestSize: \"577\"\n status: 304\n responseSize: \"157\"\n userAgent: \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36\"\n remoteIp: \"CLIENT_IP_ADDRESS\"\n cacheHit: true\n cacheLookup: true\n }\n resource: {\n type: \"http_load_balancer\"\n labels: {\n zone: \"global\"\n url_map_name: \"URL_MAP_NAME\"\n forwarding_rule_name: \"FORWARDING_RULE_NAME\"\n target_proxy_name: \"TARGET_PROXY_NAME\"\n backend_service_name: \"\"\n project_id: \"PROJECT_ID\"\n }\n }\n timestamp: \"2020-06-08T23:41:30.078651Z\"\n severity: \"INFO\"\n logName: \"projects/PROJECT_ID/logs/requests\"\n trace: \"projects/PROJECT_ID/traces/241d69833e64b3bf83fabac8c873d992\"\n receiveTimestamp: \"2020-06-08T23:41:30.588272510Z\"\n spanId: \"7b6537d3672e08e1\"\n}\n```\n\nWhat is logged\n--------------\n\nIn addition to general information contained in most logs, such as severity,\nproject ID, project number, and timestamp, the\n[external Application Load Balancer and Cloud CDN\nlogs](/cdn/docs/cdn-logging-monitoring#logging) contain the following:\n\n- The [HttpRequest](/logging/docs/reference/v2/rest/v2/LogEntry#HttpRequest) log\n field, which captures the HTTP status code, bytes returned, and whether a\n cache lookup or cache fill was performed.\n\n- The `jsonPayload.cacheId` field, which indicates the location and cache\n instance that the cache response was served from. For example, a cache response\n served from a cache in Amsterdam would have a cacheId value of `AMS-85e2bd4b`,\n where `AMS` is the [IATA code](https://en.wikipedia.org/wiki/IATA_airport_code),\n and `85e2bd4b` is an opaque identifier of the cache instance (because some\n Cloud CDN locations have multiple discrete caches).\n\n- The [`statusDetails` and\n `cacheDetail`](/cdn/docs/cdn-logging-monitoring#what_is_logged)\n fields of the `jsonPayload`.\n\nYou can filter on the following fields to determine the cache hit, miss,\nor revalidation status of a request served by Cloud CDN:\n\n- **Cache Hit**\n\n `jsonPayload.statusDetails=(\"response_from_cache\" OR \"byte_range_caching\")`\n\n or\n\n `httpRequest.cacheHit=true` \n\n `httpRequest.cacheValidatedWithOriginServer!=true`\n- **Cache Hit Validated With Origin Server**\n\n `jsonPayload.statusDetails=\"response_from_cache_validated\"`\n\n or\n\n `httpRequest.cacheHit=true` \n\n `httpRequest.cacheValidatedWithOriginServer=true`\n- **Cache Miss**\n\n `jsonPayload.statusDetails=\"response_sent_by_backend\"`\n\n or\n\n `httpRequest.cacheHit!=true` \n\n `httpRequest.cacheLookup=true`\n\nAlternatively, you can observe the cache status from the client side by\nconfiguring a [custom response header](/cdn/docs/caching#custom-headers)\nwith `cdn_cache_status`.\n\nLog fields of type *boolean* typically only appear if they have a value of\n`true`. If a boolean field has a value of `false`, that field is omitted from\nthe log.\n\n[UTF-8](https://wikipedia.org/wiki/UTF-8)\nencoding is enforced for these fields. Characters that are not UTF-8\ncharacters are replaced with question marks.\n\nWhen Cloud CDN serves a client request by initiating validation\nrequests or byte range requests, it omits the `serverIp` field from the\nCloud Logging log entry for the client request. This is because\nCloud CDN can send requests to multiple server IP addresses in\nreaction to a single client request.\n\nEach request initiated by Cloud CDN creates a Cloud Logging log\nentry. The resulting log entry contains a `parentInsertId` field inside the\n`jsonPayload`. You can use this field to identify the `insertId` of the log\nentry for the single client request that prompted Cloud CDN to initiate\nthe validation request or byte range request. Furthermore, the log entry\nidentifies Cloud CDN as the user agent.\n\nMonitoring for Cloud CDN\n------------------------\n\nCloud CDN exports monitoring data to [Cloud Monitoring](/monitoring/docs).\nMonitoring is used to monitor the health\nof a Cloud CDN deployment.\n\nCloud Monitoring provides a set of dashboard definitions available on GitHub in\nthe [monitoring-dashboard-samples repository](https://github.com/GoogleCloudPlatform/monitoring-dashboard-samples)\nas JSON files. In the `dashboards/networking` directory, there is a Cloud CDN-specific dashboard called\n`cloud-cdn-monitoring.json`. Upload this custom dashboard to Monitoring\nby following the instructions in\n[Installing sample dashboards](/monitoring/dashboards/dashboard-templates).\n| **Note:** The dashboard does not filter on any specific backend; all load-balancing traffic for all backends is included. To filter on a specific backend, you need to add `backend_target_name=\"example-backend\"` to each chart's PromQL query. Additionally, to filter on only backends that have Cloud CDN enabled, include `cache_result!=\"DISABLED\"`.\n\nMonitoring Cloud CDN example queries\n------------------------------------\n\nMonitoring lets you\n[create custom dashboards](/cdn/docs/cdn-logging-monitoring#defining_custom_dashboards).\nDashboards can use any of the\n[monitoring metrics](/cdn/docs/cdn-logging-monitoring#monitoring)\nfor external Application Load Balancers. Following are some example PromQL\nsnippets that you can paste into custom Monitoring dashboards.\n\n**Request bytes count broken out by cache result**\n\nThis query focuses on backends\nthat have Cloud CDN enabled, which is done by including\n`cache_result!=\"DISABLED\"`. \n\n```\nsum by (cache_result) (\n rate({\"loadbalancing.googleapis.com/https/response_bytes_count\", monitored_resource=\"https_lb_rule\", cache_result!=\"DISABLED\"}[1m])\n)\n```\n\n**Client roundtrip TCP latency at 95% for a specific backend target**\n\nThis query includes `backend_target_name=\"example-backend\"`,\nwhich narrows down traffic to the backend `example-backend`. A backend can\nbe a Cloud Storage bucket, a Compute Engine VM group, or\nan external backend. \n\n```\nhistogram_quantile(\n 0.95,\n sum by (proxy_continent, le) (\n rate({\"loadbalancing.googleapis.com/https/frontend_tcp_rtt_bucket\",\n monitored_resource=\"https_lb_rule\",\n backend_target_name=\"example-backend\"\n }[1m])\n )\n)\n```\n\n**Request count broken out by response code class for Cloud CDN-enabled backends**\n\nThis query breaks out traffic by response code class (2xx, 3xx, 4xx, 5xx) to\nhelp separate client successes, client errors, and server errors. \n\n```\nsum by (response_code_class) (\n count_over_time(\n {\"loadbalancing.googleapis.com/https/request_count\",\n monitored_resource=\"https_lb_rule\",\n cache_result!=\"DISABLED\"\n }[1h]\n )\n)\n```\n\n**Request count broken out by country of origin**\n\nThis query shows traffic broken out by country of origin, which is determined\nby using client IP addresses. \n\n```\nsum by (client_country) (\n rate({\"loadbalancing.googleapis.com/https/request_count\", monitored_resource=\"https_lb_rule\"}[1m])\n)\n```\n\nWhat's next\n-----------\n\n- To learn more about logging, including how to export logs to BigQuery,\n Pub/Sub, or Cloud Storage, and how to configure logs-based metrics for\n monitoring and alerting, see the [Cloud Logging documentation](/logging/docs).\n\n- To learn about the fields that are included in the `httpRequest` log entry,\n see [`HttpRequest`](/logging/docs/reference/v2/rest/v2/LogEntry#httprequest)."]]