import pandas as pd import mariadb as mdb ## The following variables must be filled in by the user nc_usr = "" nc_usr_pwd = "" nc_db = "" tables_to_monitor = "'oc_filecache','oc_comments','oc_authtoken','oc_circles_event','oc_share'" ## conn = mdb.connect( user=nc_usr, password=nc_usr_pwd, host="localhost", port=3306, database=nc_db ) cur = conn.cursor() cur.execute( """ SELECT TABLE_NAME AS table_name, TABLE_ROWS AS nr_rows, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 ) AS size_kb FROM information_schema.TABLES WHERE TABLE_SCHEMA='%s' ORDER BY size_kb DESC """ % nc_db ) df = pd.DataFrame( cur.fetchall(), columns=["table_name","nr_rows","size_kb"] ) df.query("table_name in (%s)" % tables_to_monitor).to_json( "/var/lib/zabbix/output/db_metrics.json", orient='columns')