iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📑

Collecting GKE Workload Metrics with Google Managed Prometheus

に公開

Goal

This article explains how to collect metrics from workloads on GKE using Google Managed Prometheus.

Prerequisites

It is assumed that a workload that outputs metrics is already deployed on GKE.

Steps

Enable Google Managed Prometheus on GKE

In this case, we will manage GKE with Terraform.
Set monitoring_config.managed_prometheus.enabled = true in the google_container_cluster resource.
https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/container_cluster#managed_prometheus

With this setting, the PodMonitoring CRD (podmonitorings.monitoring.googleapis.com) is added to GKE.

Confirm that Managed Prometheus is enabled on the UI as well.

Deploy PodMonitoring

To collect metrics with Google Managed Prometheus, you need to deploy a PodMonitoring resource as shown below.

apiVersion: monitoring.googleapis.com/v1alpha1
kind: PodMonitoring
metadata:
  name: XXX
spec:
  selector:
    matchLabels:
      app: XXX
  endpoints:
  - port: metrics
    path: /metrics
    interval: 1m

Specify labels for the target Pod in spec.selector.
In spec.endpoints, specify the port where the Pod is exporting metrics.

Check in Cloud Monitoring

You can check the metrics in the Metrics explorer of Cloud Monitoring.

Check pricing

Please check the following documentation for Google Managed Prometheus pricing.
It costs $0.06 per 1 million samples.
https://cloud.google.com/managed-prometheus#pricing

The SKU is A4E4-DF03-CDB6.

Discussion