GCP Metrics Collection :: Kloudfuse Docs

GCP Metrics Collection

Kloudfuse integrates with the GCP cloud service to collect metrics.

Complete these tasks to successfully collect metrics:

Create Credentials File

  1. In the Google Cloud console, navigate to Menu > IAM & Admin > Service Accounts.

  2. Select your service account, or create a new one.

Ensure that the service account has Monitoring Viewer permissions to collect GCP metrics.

  1. Select Keys > Add key > Create new key.

  2. Select JSON, then click Create.

  3. Click Close.

Create Kubernetes Secret

The credentials file must be named credentials.json when creating the Kubernetes secret.

Create a Kubernetes secret from the credentials file:

kubectl create secret generic kfuse-sd-secret --from-file=credentials.json -n kfuse

Configure Kloudfuse to Collect Metrics

Enable Cloud Exporter

First, enable the cloud exporter service in the global configuration:

global:
  cloud-exporter:
    enabled: true
  gcpConfig:
    secretName: "kfuse-sd-secret"

Configure GCP Metrics Collection

There are two methods to provide GCP credentials for metrics collection:

Method 1: Using Kubernetes Secret (Recommended for Production)

This is the recommended approach for production environments as it keeps sensitive credentials secure.

  1. Update the helm values using the following configuration.
kfuse-cloud-exporter:
     prometheus-stackdriver-exporter:
       enabled: true
       stackdriver:
         httpTimeout: 30s
         maxRetries: 3
         projectId: "YOUR PROJECT ID" (1)
         ## projectId: "<project1-id>, <project2-id>, <project3-id>" (2)
         metrics:
           typePrefixes: "compute.googleapis.com"
1 projectId singular: GCP project id
2 projectId multiple: GCP project ids when working with multiple projects

Method 2: Using Direct secretKey (Quick Setup Only)

This method embeds credentials directly in the configuration file. Only use this for quick testing or proof-of-concept setups. Never use this approach in production environments.
  1. Convert the JSON credentials file to base64:
base64 -w 0 credentials.json
  1. Update the helm values with the base64-encoded credentials:
kfuse-cloud-exporter:
     prometheus-stackdriver-exporter:
       enabled: true
       secretKey: "<BASE64_ENCODED_CREDENTIALS>" (1)
       stackdriver:
         httpTimeout: 30s
         maxRetries: 3
         projectId: "YOUR PROJECT ID"
         metrics:
           typePrefixes: "compute.googleapis.com"
1 secretKey: Base64-encoded service account JSON credentials (not recommended for production)
  1. Update the corresponding projectId of the GCP account and update the typePrefixes to collect the metrics from relevant services of GCP; see Google Cloud documentation on Google Cloud metrics.

Configure GCP Metrics Enrichment

Kloudfuse can enrich GCP metrics with custom labels and metadata from your GCP resources. This feature adds resource labels (like custom tags) from GCE instances to the corresponding metrics, providing better context for monitoring and alerting.

Prerequisites

Create IAM Role and Service Account

Create a service account in your GCP project with the required permissions for Kloudfuse to scrape additional labels from GCP resources.

# Create service account
gcloud iam service-accounts create kfuse-gcp-enrichment \
    --display-name="Kloudfuse GCP Enrichment" \
    --description="Service account for Kloudfuse GCP metrics enrichment"

# Assign Monitoring Viewer role for metrics collection
gcloud projects add-iam-policy-binding YOUR-PROJECT-ID \
    --member="serviceAccount:kfuse-gcp-enrichment@YOUR-PROJECT-ID.iam.gserviceaccount.com" \
    --role="roles/monitoring.viewer"

# Assign Compute Viewer role for GCE instance label enrichment
gcloud projects add-iam-policy-binding YOUR-PROJECT-ID \
    --member="serviceAccount:kfuse-gcp-enrichment@YOUR-PROJECT-ID.iam.gserviceaccount.com" \
    --role="roles/compute.viewer"

# Create JSON key file
gcloud iam service-accounts keys create kfuse-gcp-credentials.json \
    --iam-account=kfuse-gcp-enrichment@YOUR-PROJECT-ID.iam.gserviceaccount.com

Required IAM Role Permissions

IAM Role Purpose Required For
roles/monitoring.viewer Provides read-only access to GCP monitoring metrics Metrics collection (required for all configurations)
roles/compute.viewer Provides read-only access to GCE instance metadata and labels Metrics enrichment (required only when enrichment is enabled)

Enable GCP Metrics Enrichment

To enable automatic enrichment of GCP metrics with resource labels, add the following configuration to your helm values:

Global Configuration

Add the GCP configuration under the global section:

global:
  enrichmentEnabled: (1)
    - gcp
  gcpConfig:
    secretName: "kfuse-sd-secret" (2)
1 enrichmentEnabled: Enable enrichment for cloud providers (include "gcp" to enable GCP metrics enrichment)
2 secretName: The Kubernetes secret containing GCP credentials (same as used for metrics collection)

Ingester Configuration

Configure the ingester service to scrape and enrich GCP resources:

ingester:
  config:
    gcpScrapeIntervalMinutes: 30 (1)
    gcpProjectConfigs:
      - projectId: "YOUR-PROJECT-ID" (2)
        zones: (3)
          - "us-west1-b"
          - "us-central1-a"
          - "europe-west1-b"
        services: (4)
          - "GCE"
    gcpZones: (5)
      - "us-west1-b"
      - "us-central1-a"
      - "europe-west1-b"
    gcpServices: (6)
      - "GCE"
1 gcpScrapeIntervalMinutes: How often to scrape GCP resources for label enrichment (default: 30 minutes, minimum: 5 minutes)
2 projectId: GCP project ID to scrape resources from
3 zones: List of GCP zones/regions where your resources are deployed for this specific project
4 services: Services to enable enrichment for this specific project (currently supports "GCE" for Compute Engine)
5 gcpZones: Default list of zones used when zones are not specified for a project in gcpProjectConfigs
6 gcpServices: Default list of services used when services are not specified for a project in gcpProjectConfigs

Multi-Project Configuration

To enable enrichment across multiple GCP projects, configure multiple project entries under gcpProjectConfigs:

ingester:
  config:
    gcpScrapeIntervalMinutes: 30
    gcpProjectConfigs:
      - projectId: "project-1" (1)
        zones: ["us-west1-b"] (2)
        services: ["GCE"] (3)
      - projectId: "project-2" (4)
        zones: ["europe-west1-b"] (5)
        services: ["GCE"] (6)
1 First GCP project ID to scrape resources from
2 Zones to scrape in the first project
3 Services to enable for the first project
4 Second GCP project ID to scrape resources from
5 Zones to scrape in the second project
6 Services to enable for the second project
The enrichment process runs periodically based on gcpScrapeIntervalMinutes (default: every 30 minutes) to update the resource labels cache. New resources or label changes may take up to this interval to appear in metrics.