Repository: getredash/redash

Issue:
Add to status page the size of Redash's DB
```sql
SELECT pg_size_pretty(pg_total_relation_size('query_results'));
```

```sql
SELECT pg_size_pretty(pg_database_size('redash'));
```


Discussion:
@arikfr  Happy to work on this one but I'm not seeing how status.json gets populated, or even where it is. Could you provide a pointer please?
Here:

https://github.com/getredash/redash/blob/2a22b98c77757f378d3a4ed1ec8eceb99f0a8b35/redash/handlers/__init__.py#L15-L20

And it uses the `get_status` method from here:

https://github.com/getredash/redash/blob/2a22b98c77757f378d3a4ed1ec8eceb99f0a8b35/redash/monitor.py#L4

Thanks!

Resolving patch:
diff --git a/redash/monitor.py b/redash/monitor.py
--- a/redash/monitor.py
+++ b/redash/monitor.py
@@ -1,39 +1,72 @@
 from redash import redis_connection, models, __version__, settings
 
 
-def get_status():
-    status = {}
+def get_redis_status():
     info = redis_connection.info()
-    status['redis_used_memory'] = info['used_memory']
-    status['redis_used_memory_human'] = info['used_memory_human']
-    status['version'] = __version__
+    return {'redis_used_memory': info['used_memory'], 'redis_used_memory_human': info['used_memory_human']}
+
+
+def get_object_counts():
+    status = {}
     status['queries_count'] = models.db.session.query(models.Query).count()
     if settings.FEATURE_SHOW_QUERY_RESULTS_COUNT:
         status['query_results_count'] = models.db.session.query(models.QueryResult).count()
         status['unused_query_results_count'] = models.QueryResult.unused().count()
     status['dashboards_count'] = models.Dashboard.query.count()
     status['widgets_count'] = models.Widget.query.count()
+    return status
 
-    status['workers'] = []
-
-    status['manager'] = redis_connection.hgetall('redash:status')
 
+def get_queues():
     queues = {}
     for ds in models.DataSource.query:
         for queue in (ds.queue_name, ds.scheduled_queue_name):
             queues.setdefault(queue, set())
             queues[queue].add(ds.name)
 
-    status['manager']['queues'] = {}
+    return queues
+
+
+def get_queues_status():
+    queues = get_queues()
+
     for queue, sources in queues.iteritems():
-        status['manager']['queues'][queue] = {
+        queues[queue] = {
             'data_sources': ', '.join(sources),
             'size': redis_connection.llen(queue)
         }
     
-    status['manager']['queues']['celery'] = {
+    queues['celery'] = {
         'size': redis_connection.llen('celery'),
         'data_sources': ''
     }
 
+    return queues
+
+
+def get_db_sizes():
+    database_metrics = []
+    queries = [
+        ['Query Results Size', "select pg_total_relation_size('query_results') as size from (select 1) as a"],
+        ['Redash DB Size', "select pg_database_size('postgres') as size"]
+    ]
+    for query_name, query in queries:
+        result = models.db.session.execute(query).first()
+        database_metrics.append([query_name, result[0]])
+
+    return database_metrics
+
+
+def get_status():
+    status = {
+        'version': __version__,
+        'workers': []
+    }
+    status.update(get_redis_status())
+    status.update(get_object_counts())
+    status['manager'] = redis_connection.hgetall('redash:status')
+    status['manager']['queues'] = get_queues_status()
+    status['database_metrics'] = {}
+    status['database_metrics']['metrics'] = get_db_sizes()
+
     return status


Test patch: