From 3b6b79229f40643f43efe780c43e03fc9b78fb55 Mon Sep 17 00:00:00 2001 From: shortcutme Date: Wed, 29 Aug 2018 19:58:18 +0200 Subject: [PATCH] Db table stats --- plugins/Stats/StatsPlugin.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/Stats/StatsPlugin.py b/plugins/Stats/StatsPlugin.py index dfa6a7d7..793bf15b 100644 --- a/plugins/Stats/StatsPlugin.py +++ b/plugins/Stats/StatsPlugin.py @@ -1,6 +1,7 @@ import time import cgi import os +import json from Plugin import PluginManager from Config import config @@ -169,7 +170,15 @@ class UiRequestPlugin(object): # Db yield "

Db:
" for db in sys.modules["Db.Db"].opened_dbs: - yield "- %.3fs: %s
" % (time.time() - db.last_query_time, db.db_path.encode("utf8")) + tables = [row["name"] for row in db.execute("SELECT name FROM sqlite_master WHERE type = 'table'").fetchall()] + table_rows = {} + for table in tables: + table_rows[table] = db.execute("SELECT COUNT(*) AS c FROM %s" % table).fetchone()["c"] + db_size = os.path.getsize(db.db_path) / 1024.0 / 1024.0 + yield "- %.3fs: %s %.3fMB, table rows: %s
" % ( + time.time() - db.last_query_time, db.db_path.encode("utf8"), db_size, json.dumps(table_rows, sort_keys=True) + ) + # Sites yield "

Sites:"