[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# gRPC server\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThis document describes how to configure your Google Kubernetes Engine deployment\nso that you can use Google Cloud Managed Service for Prometheus to collect metrics from the\ngRPC requests served by your application. This document describes\nhow to do the following:\n\n- [Set up the gRPC Prometheus middleware for\n Go and Java.](#setup)\n- [Configure a PodMonitoring resource](#podmonitoring) for Managed Service for Prometheus to collect the exported metrics.\n- [View the **Application** dashboard](#view-dashboard) for your GKE Deployment.\n\n\u003cbr /\u003e\n\nThese instructions apply only if you are using [managed collection](/stackdriver/docs/managed-prometheus/setup-managed)\nwith Managed Service for Prometheus.\n\nFor more information about gRPC, see\n[grpc.io](https://grpc.io).\n\nSet up\n------\n\nTo collect metrics from your gRPC server, you must configure the\nappropriate gRPC middleware.\n\n- If you are using Go, then see [go-grpc-middleware](https://github.com/grpc-ecosystem/go-grpc-middleware).\n- If you are using Java, then see [java-grpc-prometheus](https://github.com/grpc-ecosystem/java-grpc-prometheus).\n\n\u003cbr /\u003e\n\nTo verify that your gRPC server is emitting metrics on the expected\nendpoints, do the following:\n\n1. Set up port forwarding by using the following command: \n\n ```\n kubectl -n NAMESPACE_NAME port-forward deploy/GRPC_SERVER_DEPLOYMENT_NAME PROMETHEUS_PORT_NUMBER\n \n ```\n2. Access `localhost:`\u003cvar translate=\"no\"\u003ePROMETHEUS_PORT_NUMBER\u003c/var\u003e by using the browser or the `curl` utility in another terminal session.\n\n\u003cbr /\u003e\n\nDefine a PodMonitoring resource\n-------------------------------\n\nFor target discovery, the Managed Service for Prometheus Operator\nrequires a PodMonitoring resource that corresponds to the\ngRPC server in the same namespace.\n\nYou can use the following PodMonitoring configuration: \n\n```\napiVersion: monitoring.googleapis.com/v1\nkind: PodMonitoring\nmetadata:\n name: my-prometheus-grpc-app\n labels:\n app.kubernetes.io/name: my-prometheus-grpc-app\n app.kubernetes.io/part-of: google-cloud-managed-prometheus\nspec:\n endpoints:\n - port: prometheus\n scheme: http\n interval: 30s\n path: /metrics\n selector:\n matchLabels:\n app.kubernetes.io/name: my-prometheus-grpc-app\n```\n\nEnsure that the values of the `port` and `MatchLabels`\nfields match those of the gRPC application that you want to\nmonitor.\n\nTo apply configuration changes from a local file, run the following command: \n\n```\nkubectl apply -n NAMESPACE_NAME -f FILE_NAME\n```\n\n\u003cbr /\u003e\n\nYou can also\n[use Terraform](/stackdriver/docs/managed-prometheus/setup-managed#terraform-scrape)\nto manage your configurations.\n\nView application metrics\n------------------------\n\nTo view request, error-rate, and latency metrics from your gRPC\napplication, do the following:\n\n1. In the Google Cloud console, go to the **Workloads** page:\n\n [Go to **Workloads**](https://console.cloud.google.com/kubernetes/workload/overview)\n\n \u003cbr /\u003e\n\n If you use the search bar to find this page, then select the result whose subheading is\n **Kubernetes Engine**.\n2. Click a Deployment in the list of workloads. The **Type** column in the list indicates the type of the workload.\n3. On the **Deployment details** page, click the **Observability** tab.\n4. Select **Application** in the dashboard selector.\n\n\u003cbr /\u003e\n\nFor more information, see [Use application performance metrics](/stackdriver/docs/solutions/gke/app-performance-metrics).\n\nTroubleshooting\n---------------\n\nFor information about troubleshooting metric ingestion problems\nin Managed Service for Prometheus, see\n[Problems with collection from exporters](/stackdriver/docs/managed-prometheus/troubleshooting#exporter-problems) in [Troubleshooting ingestion-side problems](/stackdriver/docs/managed-prometheus/troubleshooting#ingest-problems)."]]