[[["易于理解","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-05。"],[],[],null,["# View and manage client-side metrics\n\nThis page offers information about viewing and managing client-side metrics.\nClient-side metrics offer latency information about\nthe client's RPC requests to Spanner.\n\nSpanner provides client-side metrics that you can use along\nwith server-side metrics to optimize performance and\ntroubleshoot performance issues if they occur.\n\nClient-side metrics are measured from the time a request leaves your\napplication to the time your application receives the response.\nIn contrast, server-side metrics are measured from the time\nSpanner receives a request until the last byte of data\nis sent to the client.\n\nAccess client-side metrics\n--------------------------\n\nClient-side metrics are available on the following client libraries:\n\n- [Java](/java/docs/reference/google-cloud-spanner/latest/overview) in version 6.81.0 and later.\n- [Go](https://pkg.go.dev/cloud.google.com/go/spanner) in version 1.71.0 and later.\n\nClient-side metrics are available after you enable the\nCloud Monitoring API.\n\n[Enable the Monitoring API](https://console.cloud.google.com/flows/enableapi?apiid=monitoring.googleapis.com)\n\nClient-side metrics are available for users or service\naccounts that are granted the Identity and Access Management (IAM) `monitoring.timeSeries.create`\npermission. This permission is included in the following Spanner\nIAM roles:\n\n- [Cloud Spanner Admin](/iam/docs/understanding-roles#spanner.admin) (`roles/spanner.admin`)\n- [Cloud Spanner Database Admin](/iam/docs/understanding-roles#spanner.databaseAdmin) (`roles/spanner.databaseAdmin`)\n- [Cloud Spanner Database Reader](/iam/docs/understanding-roles#spanner.databaseReader) (`roles/spanner.databaseReader`)\n- [Cloud Spanner Database User](/iam/docs/understanding-roles#spanner.databaseUser) (`roles/spanner.databaseUser`)\n\nFor more information about granting roles, see\n[Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\nYou might also be able to get the required `monitoring.timeSeries.create`\nIAM permission through\n[custom roles](/iam/docs/creating-custom-roles).\n\nView metrics in the Metrics Explorer\n------------------------------------\n\n1. In the Google Cloud console, go to the Metrics Explorer page.\n\n [Go to Metrics Explorer](https://console.cloud.google.com/projectselector/monitoring/metrics-explorer?supportedpurview=project,folder,organizationId)\n2. Select your project.\n\n3. Click **Select a metric**.\n\n4. Search for `spanner.googleapis.com/client`.\n\n5. Select the metric, and then click **Apply**.\n\nFor more information about grouping or aggregating your metric, see\n[Build queries using menus](/monitoring/charts/metrics-selector#basic-advanced-mode).\n\nYour application needs to run for at least a minute before you can view any\npublished metrics.\n\nOpt out of client-side metrics\n------------------------------\n\nIf you are already using OpenTelemetry to capture custom client metrics,\nyou can choose to opt out of using client-side metrics by\nusing the following code: \n\n### Java\n\n Spanner spanner =\n SpannerOptions.newBuilder()\n .setProjectId(\"test-project\")\n .setBuiltInMetricsEnabled(false)\n .build()\n .getService();\n\n### Go\n\n client, err := spanner.NewClientWithConfig(ctx, database, spanner.ClientConfig{\n DisableNativeMetrics: true,\n })\n\nPricing\n-------\n\nThere is no charge to view client-side metrics in Cloud Monitoring.\nUse of the Monitoring API might incur charges.\nFor more information, see [Google Cloud Observability pricing](/stackdriver/pricing).\n\nWhat's next\n-----------\n\n- [Client-side metrics descriptions](/spanner/docs/client-side-metrics-descriptions)\n- [Trace collection overview](/spanner/docs/tracing-overview)"]]