Stackdriver Prometheus Exporter
repository·master·Indexed 43 days ago
https://github.com/prometheus-community/stackdriver_exporterA 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.
What's inside Stackdriver Exporter
- The Google Stackdriver Prometheus Exporter is a proxy that allows Prometheus to scrape Google Stackdriver Monitoring metrics. Every time Prometheus scrapes the exporter, the exporter requests the specific metric's time-series from the Stackdriver API.
How Stackdriver Metrics are Converted to Prometheus
masterMetrics gathered from Google Stackdriver Monitoring are transformed into Prometheus format using these rules:
Naming Convention:
stackdriver_<subsystem>_<name>namespace: Constant prefixstackdriver.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 accumulatingCounterifmonitoring.aggregate-deltasis enabled). - DISTRIBUTION $\rightarrow$ Prometheus
Histogram(note:_sumtime series is not supported).
Supported Types:
BOOL,INT64,DOUBLE, andDISTRIBUTION.STRINGandMONEYtypes are discarded.How to aggregate DELTA metrics
masterBy default, Stackdriver
DELTAmetrics are reported as PrometheusGaugemetrics. However, this can produce inaccurate data for rate calculations. To treat them as accumulating counters, enable themonitoring.aggregate-deltasflag.Challenges with Aggregation
- 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.
- 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 (default30m). Increasing this helps with slow-moving metrics but increases memory usage.
Warning: If you use
honor_timestamps: truein 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.Use Filters to refine metric collection
masterYou can apply specific filters to your metric collection using the
--monitoring.filtersflag. The format for a filter is<targeted_metric_prefix>:<filter_query>.- The
targeted_metric_prefixmust be a prefix of one or moremonitoring.metrics-prefixes. - The
filter_queryis applied to the final Monitoring API call usingANDlogic. - 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"'- The
Configure TLS and Basic Authentication
masterTo enable TLS or basic authentication, use the
--web.config.fileflag to point to a configuration file. The file format follows the exporter-toolkit specification.`--web.config.file <path_to_config> `Install the stackdriver_exporter from source
masterIf you have Go installed on your local machine, you can install the exporter directly using
go install.$ go install github.com/prometheus-community/stackdriver_exporter $ stackdriver_exporter <flags>Run the stackdriver_exporter using Docker
masterYou can run the exporter as a Docker container by mapping port 9255. Pass any necessary flags as arguments to the container command.
$ docker run -p 9255:9255 prometheuscommunity/stackdriver-exporter <flags>Deploy the stackdriver_exporter to Cloud Foundry
masterTo deploy to Cloud Foundry:
- Clone the repository.
- Navigate to the directory.
- Modify the included application manifest file with your desired properties.
- Use
cf pushto deploy.
$ git clone https://github.com/prometheus-community/stackdriver_exporter.git $ cd stackdriver_exporter # ... modify manifest ... $ cf pushConfigure Credentials and Permissions for Stackdriver Exporter
masterThe 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.viewerrole contains the necessary permissions. - Legacy Access Scopes: If using legacy scopes, the
https://www.googleapis.com/auth/monitoring.readscope is required.
- IAM Role: The
Install the stackdriver_exporter via Binaries
masterDownload the pre-compiled binaries for your specific platform and run the executable with the required flags.
$ ./stackdriver_exporter <flags>Deploy the stackdriver_exporter using BOSH
masterThe exporter can be deployed using the Prometheus BOSH Release.Install the stackdriver_exporter on Kubernetes using Helm
masterThe exporter can be deployed to Kubernetes using the Helm chart available in the
prometheus-communityrepository.- Add the prometheus-community helm repository.
- 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