2016-11-11 11:09:13 -08:00
|
|
|
#!/srv/newsblur/venv/newsblur/bin/python
|
2011-12-02 16:22:38 -08:00
|
|
|
|
|
|
|
""" Monitors the total table size (data + indexes)
|
|
|
|
for all tables in the specified database."""
|
|
|
|
|
2016-11-11 11:06:33 -08:00
|
|
|
from vendor.munin.postgres import MuninPostgresPlugin
|
2011-12-02 16:22:38 -08:00
|
|
|
|
|
|
|
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()
|
|
|
|
|