HTTP server

This document describes how to configure your Google Kubernetes Engine deploymentso that you can use Google Cloud Managed Service for Prometheus to collect metrics from theHTTP requests served by your application. This document describeshow to do the following:

These instructions apply only if you are usingmanaged collectionwith Managed Service for Prometheus.

Set up

To collect metrics from your HTTP server that can be displayed ontheApplication dashboard, you must export the following metrics asdescribed:

  • http_requests_total of typecounter, with the labelscode andmethod.
  • http_request_duration_seconds_bucket of typehistogram, with the labelmethod.

For an example that collects these metrics by using the Prometheus Goclient, seeprometheus-example-app.

To verify that your HTTP server is emitting metrics on the expectedendpoints, do the following:

  1. Set up port forwarding by using the following command:
    kubectl -nNAMESPACE_NAME port-forward deploy/HTTP_SERVER_DEPLOYMENT_NAMEPROMETHEUS_PORT_NUMBER
  2. Accesslocalhost: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 Operatorrequires a PodMonitoring resource that corresponds to theHTTP server in the same namespace.

You can use the following PodMonitoring configuration:

apiVersion: monitoring.googleapis.com/v1kind: PodMonitoringmetadata:  name:my-prometheus-http-app  labels:    app.kubernetes.io/name:my-prometheus-http-app    app.kubernetes.io/part-of: google-cloud-managed-prometheusspec:  endpoints:  - port: web    scheme: http    interval: 30s    path: /metrics  selector:    matchLabels:      app.kubernetes.io/name: prometheus-example-app

Ensure that the values of theport andMatchLabelsfields match those of the HTTP application that you want tomonitor.

To apply configuration changes from a local file, run the following command:

kubectl apply -nNAMESPACE_NAME -fFILE_NAME

You can alsouse Terraformto manage your configurations.

View application metrics

To view request, error-rate, and latency metrics from your HTTP application, do the following:

  1. In the Google Cloud console, go to theWorkloads page:

    Go toWorkloads

    If you use the search bar to find this page, then select the result whose subheading isKubernetes Engine.

  2. Click a Deployment in the list of workloads. TheType column in the list indicates the type of the workload.
  3. On theDeployment details page, click theObservability tab.
  4. SelectApplication in the dashboard selector.

For more information, seeUse application performance metrics.

Troubleshooting

For information about troubleshooting metric ingestion problemsin Managed Service for Prometheus, seeProblems with collection from exporters inTroubleshooting ingestion-side problems.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-18 UTC.