如果在相应的健康检查中设置了 sourceRegions 字段,则系统仅会为 Cloud DNS 路由政策的探测填充此字段。
targetIp
string
作为探测目标的 IP 地址。此字段可能与 ipAddress 不同。探测的目的地 IP 地址取决于负载均衡器的类型。如需了解详情,请参阅健康检查概览中的探测数据包的目标。
targetPort
int
作为探测目标的端口。此端口可以是探测的默认端口,也可以是您创建健康检查时指定的端口。
过滤条件示例
本部分提供了常见日志过滤条件的示例。
查找特定实例组的所有健康检查结果
logName="projects/PROJECT_ID/logs/compute.googleapis.com%2Fhealthchecks" AND
resource.type="gce_instance_group" AND
resource.labels.instance_group_name="INSTANCE_GROUP_NAME"
查找特定 NEG 的所有健康检查结果
logName="projects/PROJECT_ID/logs/compute.googleapis.com%2Fhealthchecks" AND
resource.type="gce_network_endpoint_group" AND
resource.labels.network_endpoint_group_id="ENDPOINT_GROUP_ID"
[[["易于理解","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-09-04。"],[],[],null,["# Health check logging information\n\nYou can get logs of load balancing\n[health checks](/load-balancing/docs/health-check-concepts) when an endpoint\nchanges in health status. You can use health check logs for the following:\n\n- Live debugging and troubleshooting your endpoint health status\n- Getting visibility into your endpoint's health status\n- Auditing and compliance purposes\n\nHealth checks log health transition information to\n[Logging](/logging/docs).\nYou enable or disable logging on a per-health check basis.\n\nTo see health check logs in Logging, you must ensure that you\ndon't have a logs exclusion that applies to health checks. For instructions\nabout how to verify that `GCE Instance Group` and\n`Network Endpoint Group` logs are allowed, see\n[Exclusion filters](/logging/docs/routing/overview#exclusions).\n\nEnable and disable logging\n--------------------------\n\nThis section describes how to enable logging on a new or an existing\nhealth check, and how to disable logging on an existing health check.\n\n### Enable logging on a new health check\n\n### Console\n\n1. In the Google Cloud console, go to the **Health checks** page.\n\n [Go to Health checks](https://console.cloud.google.com/compute/healthChecks)\n2. Click **Create health check**.\n\n3. For **Logs** , select **On**.\n\n4. Continue setting up your health check.\n\n### gcloud\n\n```\ngcloud compute health-checks create PROTOCOL HEALTH_CHECK_NAME \\\n --enable-logging\n```\n\nThe flag `--enable-logging` enables logging for that health check.\n\n### Terraform\n\nTo create a health check for different protocols with logging, use the\n[`google_compute_health_check` resource](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_health_check).\n\n\n resource \"google_compute_health_check\" \"health_check_tcp_with_logging\" {\n provider = google-beta\n\n name = \"health-check-tcp\"\n\n timeout_sec = 1\n check_interval_sec = 1\n\n tcp_health_check {\n port = \"22\"\n }\n\n log_config {\n enable = true\n }\n }\n\n\u003cbr /\u003e\n\nFor a regional load balancer, use the [`google_compute_region_health_check` resource](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_region_health_check).\n\nTo learn how to apply or remove a Terraform configuration, see\n[Basic Terraform commands](/docs/terraform/basic-commands).\n\n### Enable logging on an existing health check\n\n### Console\n\n1. In the Google Cloud console, go to the **Health checks** page.\n\n [Go to Health checks](https://console.cloud.google.com/compute/healthChecks)\n2. Click the name of your health check.\n\n3. Click edit**Edit**.\n\n4. For **Logs** , select **On**.\n\n5. Click **Save**.\n\n### gcloud\n\n```\ngcloud compute health-checks update PROTOCOL HEALTH_CHECK_NAME \\\n --enable-logging\n```\n\nThe flag `--enable-logging` enables logging for that health check.\n\n### Disable logging on an existing health check\n\n### Console\n\n1. In the Google Cloud console, go to the **Health checks** page.\n\n [Go to Health checks](https://console.cloud.google.com/compute/healthChecks)\n2. Click the name of your health check.\n\n3. Click edit**Edit**.\n\n4. For **Logs** , select **Off**.\n\n5. Click **Save**.\n\n### gcloud\n\n```\ngcloud compute health-checks update PROTOCOL HEALTH_CHECK_NAME \\\n --no-enable-logging\n```\n\nThe flag `--no-enable-logging` disables logging for that health check.\n\nView logs\n---------\n\n1. To view logs, go to the [Logs explorer](https://console.cloud.google.com/logs).\n\n Health check logs are indexed by [instance group](/compute/docs/instance-groups)\n or [network endpoint group](/load-balancing/docs/negs).\n2. To see all logs, in the **Resource** menu, select either\n `GCE Instance Group` or `Network Endpoint Group`,\n depending on the type of backend.\n\n3. Alternatively, paste the following into the **Query** field. Replace\n \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your project's ID.\n\n ```\n logName=\"projects/PROJECT_ID/logs/compute.googleapis.com%2Fhealthchecks\"\n ```\n\nYou can configure export of\n[logs-based metrics](/logging/docs/logs-based-metrics) for load balancer\nhealth checks.\n\n### Use filters to view logs\n\nYou can also get logs based on more specific searches. For example, the\nfollowing filter shows all logs for a specified backend instance IP address: \n\n```\n logName=\"projects/PROJECT_ID/logs/compute.googleapis.com%2Fhealthchecks\"\njsonPayload.healthCheckProbeResult.ipAddress=\"IP_ADDRESS\"\n```\n\nLog fields of type *boolean* typically only appear if they have a value of `true`.\nIf a boolean field has a value of `false`, that field is omitted from the log.\n\n[UTF-8](https://en.wikipedia.org/wiki/UTF-8) encoding\nis enforced for log fields. Characters that are not UTF-8\ncharacters are replaced with question marks.\n\nWhat is logged\n--------------\n\nHealth check log entries contain information useful for monitoring\nand debugging the state of your endpoints. Log entries contain the following\ntypes of information:\n\n- General information shown in most logs, such as severity, project ID, project number, and timestamp.\n- Fields specific to health checks, described in the following tables.\n\n### Health check states\n\nAn endpoint is considered either `HEALTHY` or `UNHEALTHY`. These are the basic\nstates. Within each of these basic states, there are several more detailed\nstates.\n\n*Hybrid NEGs and regional internet NEGs using distributed Envoy\nhealth checks do not support detailed health states.*\n\nThe following table shows the mapping between basic and detailed health states.\n\nState changes don't always alter the behavior of the load balancer. Consider the\nfollowing case:\n\n1. The server is giving the wrong response, so the endpoint is considered `UNHEALTHY`.\n2. The server then stops responding, and the new state is `TIMEOUT`.\n3. The load balancer still considers the endpoint to be `UNHEALTHY` because the detailed `TIMEOUT` state maps to the basic `UNHEALTHY` state.\n\nThe following table provides a definition of each health state.\n\nThere are multiple health checkers probing each endpoint; Google Cloud\nde-duplicates the log entries before logging so that only unique logs are\ngenerated.\n\nIf a health checker restarts, you might occasionally see the logged health state\nchange from `UNKNOWN` to one of the known states listed earlier even though the\nendpoint's health state has not actually changed. Google Cloud uses\nbest-effort heuristics to suppress such log entries.\n\nIf you are using\n[connection draining](/load-balancing/docs/enabling-connection-draining), then\nhealth check logs are *not* be generated with the endpoint health status\n`DRAINING`. This is because health check logs reflect the results observed by\nthe health check probes, and connection draining does not impact the results\nobserved by the health check probe. Connection draining works by just informing\nthe load balancer that the new state is `DRAINING`, and it effectively overrides\nthe true health state of the endpoint as observed by the health checker.\n\nYou can interact with the logs by using the Cloud Logging API. The API\nprovides ways to interactively filter logs that have specific fields set and\nexport matching logs to Cloud Logging, Cloud Storage, BigQuery,\nor Pub/Sub. For more information about the Cloud Logging API,\nsee [Cloud Logging API overview](/logging/docs/reference/api-overview).\n\n### Health check log entry\n\nThe\n[LogEntry](/logging/docs/reference/v2/rest/v2/LogEntry)\n`jsonPayload` is populated with a field `healthCheckProbeResult` that contains\nthe following information.\n\nExample filters\n---------------\n\nThis section provides examples of common log filters.\n\n### Find all health check results for a particular instance group\n\n```\nlogName=\"projects/PROJECT_ID/logs/compute.googleapis.com%2Fhealthchecks\" AND\nresource.type=\"gce_instance_group\" AND\nresource.labels.instance_group_name=\"INSTANCE_GROUP_NAME\"\n```\n\n### Find all health check results for a particular NEG\n\n```\nlogName=\"projects/PROJECT_ID/logs/compute.googleapis.com%2Fhealthchecks\" AND\nresource.type=\"gce_network_endpoint_group\" AND\nresource.labels.network_endpoint_group_id=\"ENDPOINT_GROUP_ID\"\n```\n\n### Find all health check transitions for backend instance IP address `10.128.15.201`\n\n```\nlogName=\"projects/PROJECT_ID/logs/compute.googleapis.com%2Fhealthchecks\"\njsonPayload.healthCheckProbeResult.ipAddress=\"10.128.15.201\"\n```\n\n### Find all endpoints that were previously HEALTHY but now TIMEOUT\n\n```\nlogName=\"projects/PROJECT_ID/logs/compute.googleapis.com%2Fhealthchecks\"\njsonPayload.healthCheckProbeResult.previousDetailedHealthState=\"HEALTHY\"\njsonPayload.healthCheckProbeResult.detailedHealthState=\"TIMEOUT\"\n```\n\n### Find health logs from a specific time range\n\n```\nlogName=\"projects/PROJECT_ID/logs/compute.googleapis.com%2Fhealthchecks\"\ntimestamp\u003e\"2019-02-14T02:20:00.0Z\"\ntimestamp\u003c\"2019-02-14T03:30:00.0Z\"\n```\n\nLimitations\n-----------\n\n- Logs are generated for endpoint health transition only.\n- [Legacy health checks](/load-balancing/docs/health-checks#legacy-health-checks) are not supported.\n- Target pools are not supported.\n- Logs are not generated when the endpoint's health state is `UNKNOWN`.\n- In case of VM migrations, you might not see any log entries generated when the endpoint's health transitions to the `UNHEALTHY` state.\n- Logs are not generated when endpoints are deleted. For example, when you stop a VM.\n\nWhat's next\n-----------\n\n- Read [conceptual information about health checks](/load-balancing/docs/health-check-concepts).\n- Create a [health check](/load-balancing/docs/health-checks).\n- Read about [Logging](/logging/docs)."]]