NewsBlur/config/munin/postgres_table_sizes
2016-11-11 11:09:13 -08:00

26 lines
725 B
Python
Executable file

#!/srv/newsblur/venv/newsblur/bin/python
""" Monitors the total table size (data + indexes)
for all tables in the specified database."""
from vendor.munin.postgres import MuninPostgresPlugin
class PostgresTableSizes(MuninPostgresPlugin):
vlabel = "Table Size"
title = "Table Sizes"
@property
def fields(self):
return [(table, {"label": table}) for table in self.tables()]
def execute(self):
tables = {}
for table in self.tables():
cursor = self.cursor()
cursor.execute("SELECT pg_total_relation_size(%s);", (table,))
tables[table] = cursor.fetchone()[0]
return tables
if __name__ == "__main__":
PostgresTableSizes().run()