This document describes how to configure your Google Kubernetes Engine deployment so that you can use Google Cloud Managed Service for Prometheus to collect metrics from the gRPC requests served by your application. This document describes how to do the following:
- Set up the gRPC Prometheus middleware for Go and Java.
- Configure a PodMonitoring resource for Managed Service for Prometheus to collect the exported metrics.
- View the Application dashboard for your GKE Deployment.
These instructions apply only if you are using managed collection with Managed Service for Prometheus.
For more information about gRPC, see grpc.io.
Set up
To collect metrics from your gRPC server, you must configure the appropriate gRPC middleware.
- If you are using Go, then see go-grpc-middleware.
- If you are using Java, then see java-grpc-prometheus.
To verify that your gRPC server is emitting metrics on the expected endpoints, do the following:
- Set up port forwarding by using the following command:
kubectl -n NAMESPACE_NAME port-forward deploy/GRPC_SERVER_DEPLOYMENT_NAME PROMETHEUS_PORT_NUMBER
- Access
localhost:PROMETHEUS_PORT_NUMBER
by using the browser or thecurl
utility in another terminal session.
Define a PodMonitoring resource
For target discovery, the Managed Service for Prometheus Operator requires a PodMonitoring resource that corresponds to the gRPC server in the same namespace.
You can use the following PodMonitoring configuration:
apiVersion: monitoring.googleapis.com/v1 kind: PodMonitoring metadata: name: my-prometheus-grpc-app labels: app.kubernetes.io/name: my-prometheus-grpc-app app.kubernetes.io/part-of: google-cloud-managed-prometheus spec: endpoints: - port: prometheus scheme: http interval: 30s path: /metrics selector: matchLabels: app.kubernetes.io/name: my-prometheus-grpc-app
Ensure that the values of the port
and MatchLabels
fields match those of the gRPC application that you want to
monitor.
To apply configuration changes from a local file, run the following command:
kubectl apply -n NAMESPACE_NAME -f FILE_NAME
You can also use Terraform to manage your configurations.
View application metrics
To view request, error-rate, and latency metrics from your gRPC application, do the following:
-
In the Google Cloud console, go to the Workloads page:
If you use the search bar to find this page, then select the result whose subheading is Kubernetes Engine.
- Click a Deployment in the list of workloads. The Type column in the list indicates the type of the workload.
- On the Deployment details page, click the Observability tab.
- Select Application in the dashboard selector.
For more information, see Use application performance metrics.
Troubleshooting
For information about troubleshooting metric ingestion problems in Managed Service for Prometheus, see Problems with collection from exporters in Troubleshooting ingestion-side problems.