diff --git a/zabbix-agent-scripts/get_db_metrics.py b/zabbix-agent-scripts/get_db_metrics.py index 5b9c031..4367929 100644 --- a/zabbix-agent-scripts/get_db_metrics.py +++ b/zabbix-agent-scripts/get_db_metrics.py @@ -2,13 +2,21 @@ import mariadb as mdb -conn = mdb.connect(user="ncmonitor_usr", - password="oosi975nrlemtdn9395krwfd", - host="localhost", - port=3306, - database="nextcloud_db") +## 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'" +###### -cur=conn.cursor() +conn = mdb.connect( user=nc_usr, + password=nc_usr_pwd, + host="localhost", + port=3306, + database=nc_db + ) + +cur = conn.cursor() cur.execute( """ @@ -16,13 +24,14 @@ TABLE_ROWS AS `Rows`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 ) AS `Size (kB)` FROM information_schema.TABLES - WHERE TABLE_SCHEMA='nextcloud_db' + 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 = pd.DataFrame( cur.fetchall(), + columns=["table","nr_rows","size_kb"] + ) -tables_to_monitor = "'oc_filecache','oc_comments','oc_authtoken','oc_circles_event','oc_share'" - -df.query("table in (%s)" % tables_to_monitor).to_json("/var/lib/zabbix/output/db_metrics.json",orient='columns') +df.query("table in (%s)" % tables_to_monitor).to_json( "/var/lib/zabbix/output/db_metrics.json", + orient='columns')