import pandas as pd import mariadb as mdb ## The following variables must be filled in by the user nc_usr = "" nc_db = "" nc_usr_pwd = "" 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`, TABLE_ROWS AS `Rows`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 ) AS `Size (kB)` FROM information_schema.TABLES WHERE TABLE_SCHEMA='%s' ORDER BY (DATA_LENGTH + INDEX_LENGTH) DESC; """ % nc_db ) df = pd.DataFrame( cur.fetchall(), columns=["table","nr_rows","size_kb"] ) df.query("table in (%s)" % tables_to_monitor).to_json( "/var/lib/zabbix/output/db_metrics.json", orient='columns')