Stackdriver Prometheus Exporter

repository·master·Indexed 43 days ago

https://github.com/prometheus-community/stackdriver_exporter

A Prometheus exporter that acts as a proxy for Google Stackdriver Monitoring metrics, fetching time-series data from the Stackdriver API upon request from Prometheus. It supports mapping GAUGE, CUMULATIVE, DELTA, and DISTRIBUTION types to Prometheus formats and provides configurable filtering via the --monitoring.filters flag.

Tokens
5.6K
Snippets
12
Records
21
Agent score
5%

What's inside Stackdriver Exporter

  1. How Stackdriver Metrics are Converted to Prometheus

    master

    Metrics gathered from Google Stackdriver Monitoring are transformed into Prometheus format using these rules:

    Naming Convention: stackdriver_<subsystem>_<name>

    • namespace: Constant prefix stackdriver.
    • subsystem: Normalized monitored resource type (e.g., gce_instance).
    • name: Normalized metric type (e.g., compute_googleapis_com_instance_cpu_usage_time).

    Labels: Labels are an aggregation of the metric unit, metric type labels, and monitored resource labels.

    Metric Mapping:

    • GAUGE $\rightarrow$ Prometheus Gauge.
    • CUMULATIVE $\rightarrow$ Prometheus Counter.
    • DELTA $\rightarrow$ Prometheus Gauge (or an accumulating Counter if monitoring.aggregate-deltas is enabled).
    • DISTRIBUTION $\rightarrow$ Prometheus Histogram (note: _sum time series is not supported).

    Supported Types: BOOL, INT64, DOUBLE, and DISTRIBUTION. STRING and MONEY types are discarded.

  2. How to aggregate DELTA metrics

    master

    By default, Stackdriver DELTA metrics are reported as Prometheus Gauge metrics. However, this can produce inaccurate data for rate calculations. To treat them as accumulating counters, enable the monitoring.aggregate-deltas flag.

    Challenges with Aggregation

    1. Start-up Delay: When the exporter starts, it has no persisted state. The first sample is treated as the starting value of a counter rather than an increment from zero. It may take several scrape cycles for rates to stabilize.
    2. Slow Moving Metrics: If a metric doesn't change for a long time (default 5m), Prometheus marks the series as stale. When the metric finally changes, it appears as a new series rather than an increment.

    Solutions

    • monitoring.aggregate-deltas: Converts DELTA metrics into in-memory counters.
    • monitoring.aggregate-deltas-ttl: Controls how long a delta metric is kept in memory after GCP stops reporting it (default 30m). Increasing this helps with slow-moving metrics but increases memory usage.

    Warning: If you use honor_timestamps: true in your Prometheus scrape config, the feature that continues to export metrics not collected during a scrape may cause ingestion errors if GCP has late-arriving data.

  3. Use Filters to refine metric collection

    master

    You can apply specific filters to your metric collection using the --monitoring.filters flag. The format for a filter is <targeted_metric_prefix>:<filter_query>.

    • The targeted_metric_prefix must be a prefix of one or more monitoring.metrics-prefixes.
    • The filter_query is applied to the final Monitoring API call using AND logic.
    • String values containing special characters (like :) must be enclosed in double quotes ".

    Example: Filtering specific Pub/Sub and Compute metrics

    stackdriver_exporter \
     --google.project-ids=my-test-project \
     --monitoring.metrics-prefixes='pubsub.googleapis.com/subscription' \
     --monitoring.metrics-prefixes='compute.googleapis.com/instance/cpu' \
     --monitoring.metrics-prefixes='cloudsql.googleapis.com/database' \
     --monitoring.filters='pubsub.googleapis.com/subscription:resource.labels.subscription_id=monitoring.regex.full_match("us-west4.*my-team-subs.*")' \
     --monitoring.filters='compute.googleapis.com/instance/cpu:resource.labels.instance=monitoring.regex.full_match("us-west4.*my-team-subs.*")' \
     --monitoring.filters='cloudsql.googleapis.com/database:resource.labels.database_id="my-test-project:my-database-name"'
    stackdriver_exporter \
     --google.project-ids=my-test-project \
     --monitoring.metrics-prefixes='pubsub.googleapis.com/subscription' \
     --monitoring.metrics-prefixes='compute.googleapis.com/instance/cpu' \
     --monitoring.metrics-prefixes='cloudsql.googleapis.com/database' \
     --monitoring.filters='pubsub.googleapis.com/subscription:resource.labels.subscription_id=monitoring.regex.full_match("us-west4.*my-team-subs.*")' \
     --monitoring.filters='compute.googleapis.com/instance/cpu:resource.labels.instance=monitoring.regex.full_match("us-west4.*my-team-subs.*")' \
     --monitoring.filters='cloudsql.googleapis.com/database:resource.labels.database_id="my-test-project:my-database-name"'
  4. Deploy the stackdriver_exporter to Cloud Foundry

    master

    To deploy to Cloud Foundry:

    1. Clone the repository.
    2. Navigate to the directory.
    3. Modify the included application manifest file with your desired properties.
    4. Use cf push to deploy.
    $ git clone https://github.com/prometheus-community/stackdriver_exporter.git
    $ cd stackdriver_exporter
    # ... modify manifest ...
    $ cf push
  5. Configure Credentials and Permissions for Stackdriver Exporter

    master

    The exporter uses the Google Golang Client Library for authentication. You can provide credentials using Google Application Default Credentials.

    Required Permissions:

    • IAM Role: The roles/monitoring.viewer role contains the necessary permissions.
    • Legacy Access Scopes: If using legacy scopes, the https://www.googleapis.com/auth/monitoring.read scope is required.
  6. Install the stackdriver_exporter on Kubernetes using Helm

    master

    The exporter can be deployed to Kubernetes using the Helm chart available in the prometheus-community repository.

    1. Add the prometheus-community helm repository.
    2. Install the chart using a release name of your choice.
    helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
    helm install [RELEASE_NAME] prometheus-community/prometheus-stackdriver-exporter