Skip to content

Instantly share code, notes, and snippets.

@adivinho
Created March 6, 2020 16:21
Show Gist options
  • Select an option

  • Save adivinho/f7ec4ac34b5fe0cb07fa0c2b008a46e5 to your computer and use it in GitHub Desktop.

Select an option

Save adivinho/f7ec4ac34b5fe0cb07fa0c2b008a46e5 to your computer and use it in GitHub Desktop.
## Custom query
pg_class:
query: "SELECT datname, COALESCE(sbtest.relname) as relname, COALESCE(sbtest.rows) as rows, COALESCE(sbtest.total) as total, COALESCE(sbtest.index) as index, COALESCE(sbtest.toast,0) as toast FROM pg_database LEFT OUTER JOIN dblink('dbname=sbtest','SELECT current_database(), relname, CAST(reltuples as BIGINT), pg_total_relation_size(oid), pg_indexes_size(oid), pg_total_relation_size(reltoastrelid) FROM pg_class') as sbtest(datname name, relname name, rows BIGINT, total BIGINT, index BIGINT, toast BIGINT) USING (datname) WHERE datname NOT LIKE 'template_' AND datname NOT LIKE 'postgres'"
metrics:
- datname:
usage: "LABEL"
description: "Name of the database that this table is in"
- relname:
usage: "LABEL"
description: "Name of the table, index, view, etc."
- rows:
usage: "GAUGE"
decription: "Number of rows in the table. This is only an estimate used by the planner. It is updated by VACUUM, ANALYZE, and a few DDL commands such as CREATE INDEX"
- total:
usage: "GAUGE"
description: "Total disk space used by the specified table, including all indexes and TOAST data"
- index:
usage: "GAUGE"
description: "Total disk space used by indexes attached to the specified table"
- toast:
usage: "GAUGE"
description: "Total disk space used by TOAST data attached to the specified table"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment