[[["易于理解","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-11。"],[],[],null,["# Bucket-scoped log-based metrics\n\nThis document summarizes the characteristics of bucket-scoped log-based metrics\nand describes how they differ from project-scoped log-based metrics.\n\nCharacteristics of bucket-scoped log-based metrics\n--------------------------------------------------\n\nBucket-scoped log-based metrics are user-defined log-based metrics\nthat evaluate log entries routed to a specific log bucket. With bucket-scoped\nlog-based metrics, you can create log-based metrics that extract data from\nlogs in the following cases:\n\n- Logs that are routed from one project to a bucket in another project.\n- Logs that are routed into a bucket through an aggregated sink.\n\nLike project-scoped log-based metrics, bucket-scoped log-based metrics\nare defined within a Google Cloud project, not at the folder or organization\nlevel. If you want to track the folder or organization from which a log\nentry was routed to the bucket, then you can define labels in the\nlog-based metric to record that information.\n\n- For general information about log-based metrics, see [Log-based metrics\n overview](/logging/docs/logs-based-metrics).\n- For information about routing and sinks, see [Routing and storage\n overview](/logging/docs/routing/overview).\n\nBucket-scoped log-based metrics have several differences from project-scoped\nlog based metrics.\n\nProjects and metrics scopes\n---------------------------\n\nBucket-scoped log-based metrics are defined in the same project that contains\nthe source bucket. By default, only the project that defines a bucket-scoped\nlog-based metric can see the metric data for the log bucket.\nHowever, if your project appears in the metrics scope of other projects,\nthose projects can also see your metrics.\n\nThe Google Cloud projects that route\nlogs to the bucket **do not** need to be in the metrics scope of any\nproject.\n\nFor more information about\nlog-based-metrics and metrics scopes,\nsee [Visibility to metrics scopes](/logging/docs/logs-based-metrics#lbm-scoping).\n\nWhen the logs are received at\nthe bucket, the routed log metric data derived is visible to\nany project that includes the bucket's project in its metrics scope.\nIf a project routing logs is not in the metrics scope of any project,\nthen other information in the routing project is not visible.\n\nWhen using bucket-scoped log-based metrics, the following statements apply:\n\n- You define the log-based metric in the project with the destination bucket.\n- Your bucket-scoped log-based metrics evaluates all log entries routed to the bucket, regardless of whether the log is from the same project as the bucket or from a different project.\n- The metric data is visible to any other project that includes the project with the bucket in its metrics scope.\n- Projects routing logs don't need to be in any project's metrics scope.\n\nMonitored-resource type: `logging_bucket`\n-----------------------------------------\n\nBucket-scoped log-based metrics use the monitored-resource type\n`logging_bucket` when writing time-series data to Cloud Monitoring. The\n[`logging_bucket` resource type](/monitoring/api/resources#tag_logging_bucket) includes the following\nlabels:\n\n- `project_id`: The identifier of your Google Cloud project, a string like `my-test-project`.\n- `bucket_id`: The name of the log bucket associated with the log-based metric, a string like `my-test-bucket`.\n- `location`: The location of the log bucket.\n- `monitored_resource_type`: The type of the monitored resource that produced this log entry; the value comes from the `type` field from the [`MonitoredResource`](/logging/docs/reference/v2/rest/v2/MonitoredResource) structure contained in the [`resource`\n field of the log entry](/logging/docs/reference/v2/rest/v2/LogEntry#FIELDS.resource).\n- `source_resource_container`: The identifier for the project, folder, or organization from which the log entry was sent, a string in one of the following forms:\n - `projects/`\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\n - `organizations/`\u003cvar translate=\"no\"\u003eORGANIZATION_ID\u003c/var\u003e\n - `folders/`\u003cvar translate=\"no\"\u003eFOLDER_ID\u003c/var\u003e"]]