diff --git a/zabbix-agent-scripts/get_db_metrics.py b/zabbix-agent-scripts/get_db_metrics.py index 4367929..6e96641 100644 --- a/zabbix-agent-scripts/get_db_metrics.py +++ b/zabbix-agent-scripts/get_db_metrics.py @@ -3,11 +3,11 @@ import mariadb as mdb ## The following variables must be filled in by the user -nc_usr = "" -nc_db = "" +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, @@ -20,18 +20,18 @@ 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; + 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","nr_rows","size_kb"] + columns=["table_name","nr_rows","size_kb"] ) -df.query("table in (%s)" % tables_to_monitor).to_json( "/var/lib/zabbix/output/db_metrics.json", +df.query("table_name in (%s)" % tables_to_monitor).to_json( "/var/lib/zabbix/output/db_metrics.json", orient='columns')