zabbix 清理历史数据

Posted on Posted in zabbix

zabbix 清理历史数据

查看zabbix库中每个表的大小

SELECT table_name AS "Tables", round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB" FROM information_schema.TABLES WHERE table_schema = 'zabbix' ORDER BY (data_length + index_length) DESC;

清理脚本

#!/bin/bash

User="zabbixuser"
Passwd="zabbixpassword"

Date=`date -d $(date -d "-7 day" +%Y%m%d) +%s` #取7天之前的时间戳
# Date=`date +%s -d "20180701"` # 或者定一个日期,获取时间戳

$(which mysql) -u${User} -p${Passwd} -e "
use zabbix;
DELETE FROM history WHERE 'clock' < $Date;
optimize table history;
DELETE FROM history_str WHERE 'clock' < $Date;
optimize table history_str;
DELETE FROM history_uint WHERE 'clock' < $Date;
optimize table history_uint;
DELETE FROM history_text WHERE 'clock' < $Date;
optimize table history_text;
DELETE FROM  trends WHERE 'clock' < $Date;
optimize table  trends;
DELETE FROM trends_uint WHERE 'clock' < $Date;
optimize table trends_uint;
DELETE FROM events WHERE 'clock' < $Date;
optimize table events;
"

第二种方法,清理表

truncate table history;
truncate table history_uint;
truncate table history_str;
truncate table history_text;
truncate table trends;
truncate table trends_uint;
truncate table events;
» 转载请注明来源:呢喃 » zabbix 清理历史数据