高级过滤条件库

本页面为您提供过滤条件建议,以便您更轻松地查找重要日志。所有列出的过滤条件都可以在日志查看器Stackdriver Logging API命令行界面中应用,但本页面重点介绍如何在日志查看器中使用过滤条件。

高级日志过滤条件是一个布尔表达式,用于指定项目中所有日志条目的子集。您可以使用这些过滤条件从特定日志或日志服务中选择日志条目,或选择满足元数据或用户定义字段的日志条目。如需详细了解高级过滤条件,请转到高级日志过滤条件

高级过滤条件使用入门

本页面上显示的过滤条件旨在用于日志查看器高级过滤条件界面。

要导航到日志查看器中的高级过滤条件界面,请执行以下操作:

  1. 转到 GCP Console 中的 Stackdriver Logging > 日志(日志查看器)页面:

    转到“日志查看器”页面

  2. 在页面顶部选择相应的 GCP 项目。

  3. 点击搜索过滤框最右侧的下拉箭头 (▾),然后选择转换为高级过滤条件

    转换为高级日志过滤条件

    系统会显示高级日志过滤条件界面。

使用过滤条件

要应用下表中的过滤条件,请通过点击任何表达式行末尾的剪贴板图标来复制表达式,然后将复制的表达式粘贴到高级过滤条件界面的搜索过滤框中:

高级过滤条件搜索框

与过滤条件匹配的日志列在搜索过滤框下方。

下面列出的一些过滤条件包括您应该用有效值替换的变量(用方括号 [] 表示)。当过滤条件包含 logName 时,您提供的 [PROJECT_ID] 必须引用当前选定的 GCP 项目;否则,过滤器条件将无法工作。如需了解详情,请转至问题排查

如果要编写包含时间戳的过滤条件,您必须从搜索过滤框下方的时间范围选择器中选择无限制

以下部分按 Google Cloud Platform 服务对过滤条件进行分组。

App Engine 过滤条件

过滤条件名称 表达式
新年前夜(按世界协调时间)的 App Engine 日志

resource.type="gae_app" AND
severity>=ERROR AND
timestamp>="2018-12-31T00:00:00Z" AND timestamp<="2019-01-01T00:00:00Z" 
具有服务器错误的 App Engine 请求日志

resource.type="gae_app" AND
log_name="projects/[PROJECT_ID]/logs/appengine.googleapis.com%2Frequest_log" AND
http_request.status>=500 
采样 HTTP 错误日志

resource.type="gae_app" AND
proto_payload.status >= 400 AND
sample(insertId, 0.1) 
搜索 App Engine 跟踪 ID

resource.type="gae_app" AND
trace="projects/[PROJECT_ID]/traces/[TRACE_ID]" 

BigQuery 过滤条件

过滤条件名称 表达式
BigQuery 审核日志

resource.type="bigquery_resource" AND
log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com" 
BigQuery 数据传输服务作业

resource.type="bigquery_resource" AND
proto_payload.request_metadata.caller_supplied_user_agent="BigQuery Data Transfer Service" AND
proto_payload.method_name="jobservice.insert" 
BigQuery 数据集更新

resource.type="bigquery_resource" AND
log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Factivity" AND
proto_payload.method_name="datasetservice.update" 
已完成的 BigQuery 工作

resource.type="bigquery_resource" AND
log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Fdata_access" AND
proto_payload.method_name="jobservice.jobcompleted" 
BigQuery 大型查询

resource.type="bigquery_resource" AND
proto_payload.method_name="jobservice.jobcompleted" AND
proto_payload.service_data.job_completed_event.job.job_statistics.total_billed_bytes>1073741824 
超出的 BigQuery 配额

resource.type="bigquery_resource" AND
proto_payload.status.code=8 AND
severity>=WARNING 
已开启的 BigQuery 查询

resource.type="bigquery_resource" AND
proto_payload.method_name="jobservice.insert" 

Cloud Dataflow 过滤条件

过滤条件名称 表达式
Dataflow 工作器中的错误和警告

resource.type="dataflow_step" AND
log_name="projects/[PROJECT_ID]/logs/dataflow.googleapis.com%2Fworker" AND
severity>=WARNING 

Cloud Dataproc 过滤条件

过滤条件名称 表达式
Dataproc Apache Hadoop 日志

resource.type="cloud_dataproc_cluster" AND
json_payload.class:"org.apache.hadoop.mapreduce" 

Cloud Deployment Manager

过滤条件名称 表达式
Deployment Manager 错误

resource.type="deployment" AND
severity>=ERROR 

Cloud Functions 过滤条件

过滤条件名称 表达式
Cloud function 错误

resource.type="cloud_function" AND
log_name="projects/[PROJECT_ID]/logs/cloudfunctions.googleapis.com%2Fcloud-functions" AND
severity>=ERROR 

Cloud Identity and Access Management 过滤条件

过滤条件名称 表达式
服务帐号创建日志

resource.type="service_account" AND
log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Factivity" AND
proto_payload.method_name="google.iam.admin.v1.CreateServiceAccount" 
服务帐号创建密钥日志

resource.type="service_account" AND
log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Factivity" AND
proto_payload.method_name="google.iam.admin.v1.CreateServiceAccountKey" 
设置访问控制政策日志

resource.type="project" AND
log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Factivity" AND
proto_payload.method_name="SetIamPolicy" 

Cloud Source Repositories 过滤条件

过滤条件名称 表达式
Cloud Source Repository 日志

resource.type="csr_repository" AND
resource.labels.name="[REPOSITORY_NAME]"

Cloud Spanner 过滤条件

过滤条件名称 表达式
特定 Spanner 实例的 Cloud Spanner 日志

resource.type="spanner_instance" AND
resource.labels.instance_id="[SPANNER_INSTANCE]"

Cloud SQL 过滤条件

过滤条件名称 表达式
Cloud SQL 数据库

resource.type="cloudsql_database" AND
resource.labels.database_id="[DATABASE_ID]"
Cloud SQL MySQL 错误日志

resource.type="cloudsql_database" AND
log_name="projects/[PROJECT_ID]/logs/cloudsql.googleapis.com%2Fmysql.err"
基于 Cloud SQL MySQL 的数据库

resource.type="cloudsql_database" AND
resource.labels.database_id="[DATABASE_ID]" AND
log_name="projects/[PROJECT_ID]/logs/cloudsql.googleapis.com%2Fmysql"
基于 Cloud SQL Postgres 的数据库

resource.type="cloudsql_database" AND
resource.labels.database_id="[DATABASE_ID]" AND
log_name="projects/[PROJECT_ID]/logs/cloudsql.googleapis.com%2Fpostgres.log"

Compute Engine 过滤条件

过滤条件名称 表达式
Google Compute Engine 管理员活动日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Factivity"
Google Compute Engine 防火墙规则删除

resource.type="gce_firewall_rule" AND
log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Factivity" AND
proto_payload.method_name:"firewalls.delete" 
Google Compute Engine 旧活动日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/compute.googleapis.com%2Factivity_log" 
Google Compute Engine 虚拟机系统日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/syslog" 

Cloud Storage 过滤条件

过滤条件名称 表达式
GCS 存储分区日志

resource.type="gcs_bucket" AND
resource.labels.bucket_name="[BUCKET_NAME]"
GCS 存储分区审核日志

resource.type="gcs_bucket" AND
log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com" 
GCS 存储分区创建日志

resource.type="gcs_bucket" AND
log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Factivity" AND
proto_payload.method_name="storage.buckets.create" 
GCS 存储分区删除日志

resource.type="gcs_bucket" AND
log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Factivity" AND
proto_payload.method_name="storage.buckets.delete" 

Cloud Tasks 过滤条件

过滤条件名称 表达式
Cloud Tasks 队列日志

resource.type="cloud_tasks_queue" AND
resource.labels.queue_id="[QUEUE_ID]"

Logging 代理应用过滤条件

过滤条件名称 表达式
Apache 日志

resource.type="gce_instance" AND
(log_name:"/apache-access" OR log_name:"/apache-error")
Cassandra 日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/cassandra"
Chef 日志

resource.type="gce_instance" AND
log_name:"projects/[PROJECT_ID]/logs/chef-"
Gitlab 日志

resource.type="gce_instance"
log_name:"projects/[PROJECT_ID]/logs/gitlab-" 
Jenkins 日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/jenkins"
Jetty 日志

resource.type="gce_instance" AND
log_name:"projects/[PROJECT_ID]/logs/jetty-"
Joomla 日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/joomla"
Linux 系统日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/syslog"
Magneto 日志

resource.type="gce_instance" AND
log_name:"projects/[PROJECT_ID]/logs/magneto-"
Mediawiki 日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/mediawiki"
memcached 日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/memcached"
MongoDB 日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/mongodb"
MySQL 日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/mysql"
Nginx 日志

resource.type="gce_instance" AND
log_name:"projects/[PROJECT_ID]/logs/nginx-"
Postgresql 日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/postgresql"
Puppet 日志

resource.type="gce_instance" AND
log_name:"projects/[PROJECT_ID]/logs/puppet-"
RabbitMQ 日志

resource.type="gce_instance" AND
log_name:"projects/[PROJECT_ID]/logs/rabbitmq-"
Redmine 日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/redmine"
Salt 日志

resource.type="gce_instance" AND
log_name:"projects/[PROJECT_ID]/logs/salt-"
Slow MySQL 查询

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/mysql-slow"
Solr 日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/solr"
SugarCRM 日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/sugarcrm"
Tomcat 日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/tomcat"
Zookeeper 日志

resource.type="gce_instance" AND
log_name="projects/[PROJECT_ID]/logs/zookeeper"

网络过滤条件

过滤条件名称 表达式
防火墙 - 所有日志

resource.type="gce_subnetwork" AND
log_name="projects/[PROJECT_ID]/logs/compute.googleapis.com%2Ffirewall"
各国家/地区的防火墙日志

resource.type="gce_subnetwork" AND
log_name="projects/[PROJECT_ID]/logs/compute.googleapis.com%2Ffirewall" AND
json_payload.remote_location.country=[COUNTRY_ISO_ALPHA_3]
各虚拟机的防火墙日志

resource.type="gce_subnetwork" AND
log_name="projects/[PROJECT_ID]/logs/compute.googleapis.com%2Ffirewall" AND
json_payload.instance.vm_name="[INSTANCE_NAME]"
防火墙子网日志

resource.type="gce_subnetwork" AND
log_name="projects/[PROJECT_ID]/logs/compute.googleapis.com%2Ffirewall" AND
resource.labels.subnetwork_name="[SUBNET_NAME]"
Compute Engine 子网络到某一子网的流量日志

resource.type="gce_subnetwork" AND
ip_in_net(json_payload.connection.dest_ip, "[SUBNET_IP]")
VPC 流日志

resource.type="gce_subnetwork" AND
log_name="projects/[PROJECT_ID]/logs/compute.googleapis.com%2Fvpc_flows"
特定端口和协议的 VPC 流日志

resource.type="gce_subnetwork" AND
log_name="projects/[PROJECT_ID]/logs/compute.googleapis.com%2Fvpc_flows" AND
json_payload.connection.src_port="[PORT_ID]" AND
json_payload.connection.protocol="[PROTOCOL]"
特定子网的 VPC 流日志

resource.type="gce_subnetwork" AND
log_name="projects/[PROJECT_ID]/logs/compute.googleapis.com%2Fvpc_flows" AND
resource.labels.subnetwork_name"=[SUBNET_NAME]"
特定子网前缀的 VPC 流日志

resource.type="gce_subnetwork" AND
log_name="projects/[PROJECT_ID]/logs/compute.googleapis.com%2Fvpc_flows" AND
ip_in_net(json_payload.connection.dest_ip,[SUBNET_NAME])
特定虚拟机的 VPC 流日志

resource.type="gce_subnetwork" AND
log_name="projects/[PROJECT_ID]/logs/compute.googleapis.com%2Fvpc_flows" AND
json_payload.src_instance.vm_name="[VM_NAME]"
VPN 网关日志

resource.type="vpn_gateway" AND
resource.labels.gateway_id="[GATEWAY_ID]"
HTTP 负载平衡器 5xx 错误

resource.type="http_load_balancer" AND
http_request.status>=500
HTTP 负载平衡器发送到 PHPMyAdmin 的请求

resource.type="http_load_balancer" AND
http_request.request_url:"phpmyadmin"

安全日志过滤条件

过滤条件名称 表达式
审核日志 - 全部

log_name:"projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com"
审核日志 - 访问透明度 (AXT)

log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Faccess_transparency"
审核日志 - 管理员活动

log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Factivity"
审核日志 - 数据访问

log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Fdata_access"
审核日志 - 系统事件

log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Fsystem_event"

Stackdriver 过滤条件

过滤条件名称 表达式
日志接收器活动

resource.type="logging_sink" AND
log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Factivity"
基于日志的指标创建或更新活动

resource.type="metric" AND
log_name="projects/[PROJECT_ID]/logs/cloudaudit.googleapis.com%2Factivity" AND
proto_payload.method_name:(UpdateLogMetric OR CreateLogMetric)
主机的正常运行时间网址检查

resource.type="uptime_url" AND
resource.labels.host="[URL]"

问题排查

如需详细了解高级过滤条件语法和问题排查说明,请转到高级日志过滤条件

后续步骤

要进一步了解高级过滤条件并自定义过滤条件,请查看高级日志过滤条件

此页内容是否有用?请给出您的反馈和评价:

发送以下问题的反馈:

此网页
Stackdriver Logging
需要帮助?请访问我们的支持页面