Terraform module for pushing Prometheus metrics to Google Cloud Monitoring

Module is based on Cloud Function called by Cloud Scheduler. Each call says which endpoint should be pushed to Google Cloud Monitoring custom metrics.

For further setup, use variable scrape_jobs, e.g.:

module "metrics_push" {
  source     = "../"  # use correct module path
  project_id = var.project
  scrape_jobs = {
    testing : {
      schedule : "* * * * *"
      endpoint : "https://example.com/metrics"
  region = var.region

Each key in scrape_jobs can contain following keys:

  • schedule (required) – cronline
  • endpoint (required) – url to metrics endpoint
  • description – used for scheduler description
  • time_zone – time zone, default “Europe/Prague”

Kuddos for https://github.com/google/go-metrics-stackdriver/blob/main/stackdriver.go on how to handle histograms.

Currently supported Prometheus metrics are:

  • Gauge,
  • Counter,
  • Histogram.

Metrics are kept in Google Cloud Monitoring under following path: custom.googleapis.com/<key>/<metric>, e.g. custom.googleapis.com/testing/app_info where testing was given as a key in scrape_jobs variable.

Before you do anything in this module

Install pre-commit hooks by running following commands:

brew install pre-commit terraform-docs
pre-commit install


Name Version
terraform >= 0.13


Name Version
archive n/a
google n/a
random n/a


No modules.


Name Type
google_cloud_scheduler_job.scrape_job resource
google_cloudfunctions_function.function resource
google_cloudfunctions_function_iam_member.invoker resource
google_project_iam_member.monitoring resource
google_service_account.sa resource
google_storage_bucket.bucket resource
google_storage_bucket_object.archive resource
random_string.random resource
archive_file.dotfiles data source


Name Description Type Default Required
project_id Project ID string n/a yes
region GCP region string n/a yes
scrape_jobs Metrics scraping setup, each item needs key schedule (e.g. * * * * *) and endpoint (https://example.com/metrics) map(map(string)) n/a yes


Name Description
sa Service account used for Cloud Function runtime email


View Github