Skip to content

Commit

Permalink
Merge pull request #56 from DFE-Digital/add-postgres-table-row-counts
Browse files Browse the repository at this point in the history
Adding postgres table row count metrics
  • Loading branch information
RMcVelia authored Mar 3, 2022
2 parents 62d021f + 6cff466 commit e510c0a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
24 changes: 24 additions & 0 deletions postgres_prometheus_exporter/config/queries.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion postgres_prometheus_exporter/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down

0 comments on commit e510c0a

Please sign in to comment.