diff --git a/postgres_prometheus_exporter/config/queries.yml b/postgres_prometheus_exporter/config/queries.yml new file mode 100644 index 0000000..a7a159a --- /dev/null +++ b/postgres_prometheus_exporter/config/queries.yml @@ -0,0 +1,24 @@ +pg_stat_user_tables: + query: | + SELECT + current_database() AS datname, + schemaname, + relname, + n_live_tup AS row_count + FROM + pg_stat_user_tables + ORDER BY + n_live_tup DESC + metrics: + - datname: + usage: LABEL + description: Name of this database + - schemaname: + usage: LABEL + description: Name of this schema + - relname: + usage: LABEL + description: Name of this table + - row_count: + usage: GAUGE + description: Estimated number of live rows diff --git a/postgres_prometheus_exporter/resource.tf b/postgres_prometheus_exporter/resource.tf index c4fd5a7..ad4175c 100644 --- a/postgres_prometheus_exporter/resource.tf +++ b/postgres_prometheus_exporter/resource.tf @@ -17,13 +17,16 @@ resource "cloudfoundry_app" "postgres-exporter" { name = "postgres-exporter-${data.cloudfoundry_service_instance.postgres_instance.name}" space = var.monitoring_space_id docker_image = "quay.io/prometheuscommunity/postgres-exporter:${local.docker_image_tag}" + command = "echo \"$${QUERY_DATA}\" > /home/queries.yml; postgres_exporter" routes { route = cloudfoundry_route.postgres_exporter.id } environment = { - DATA_SOURCE_NAME = cloudfoundry_service_key.postgres-key.credentials.uri + DATA_SOURCE_NAME = cloudfoundry_service_key.postgres-key.credentials.uri + PG_EXPORTER_EXTEND_QUERY_PATH = "/home/queries.yml" + QUERY_DATA = file("${path.module}/config/queries.yml") } }