From 9770738ef606b30324c6bdcae9a1dd7c2212e4a8 Mon Sep 17 00:00:00 2001 From: Navdeep Gill Date: Fri, 22 Jan 2016 16:37:52 -0800 Subject: [PATCH] Get size of each database in MySQL server for reference --- scripts/db_check.py | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/scripts/db_check.py b/scripts/db_check.py index 7559b8298b35..680f34045399 100644 --- a/scripts/db_check.py +++ b/scripts/db_check.py @@ -25,6 +25,42 @@ def check_connection(self): except mysql.connector.Error as err: print("Something went wrong: {}".format(err)) + ''' + Get size of each database in MySQL server for reference + ''' + def get_db_size(selfs): + db = mysql.connector.connect(user='root', password='0xdata', host='172.16.2.178', database='information_schema') + cursor_h2o = db.cursor() + + cursor_h2o.execute("SELECT table_schema as 'Database', " + "sum(round(((data_length + index_length) / 1024 / 1024 / 1024), 5)) as 'Size in GB' " + "FROM TABLES group by table_schema;") + + results = cursor_h2o.fetchall() + widths = [] + columns = [] + pipe = '|' + separator = '+' + + for cd in cursor_h2o.description: + widths.append(max(cd[2], len(cd[0]))) + columns.append(cd[0]) + + #Reallocate width length + widths[0] = 30 + + for w in widths: + pipe += " %-"+"%ss |" % (w,) + separator += '-'*w + '--+' + + print "\n*****Size of each database in MySQL Server in GB:*****" + print(separator) + print(pipe % tuple(columns)) + print(separator) + for row in results: + print(pipe % row) + print(separator) + ''' Display of tables in the h2o database for reference. Will be displayed in Jenkins logs. @@ -52,7 +88,7 @@ def get_tables_h2o(self): pipe += " %-"+"%ss |" % (w,) separator += '-'*w + '--+' - print "\nTables currently in the h2o database:" + print "\n*****Tables currently in the h2o database:*****" print(separator) print(pipe % tuple(columns)) print(separator) @@ -83,7 +119,7 @@ def get_tables_mrunit(self): pipe += " %-"+"%ss |" % (w,) separator += '-'*w + '--+' - print "\nTables currently in the mr_unit database:" + print "\n*****Tables currently in the mr_unit database:*****" print(separator) print(pipe % tuple(columns)) print(separator) @@ -161,6 +197,7 @@ def get_host(self): if __name__ == '__main__': CheckDB().check_connection() + CheckDB().get_db_size() CheckDB().get_tables_h2o() CheckDB().get_tables_mrunit() CheckDB().get_table_size()