Zabbix自动清理历史数据

2016年6月21日15:59:11 评论 8,194

随着时间增长监控的机器越来越多,其入库数据量也会越来越大,当数据量到一定时候的时候其反映速度会比较慢;于是我们就需要清理一些历史数据。

#!/bin/bash

User="root"
Passwd="xxxxxx"

HIS_Date=`date -d $(date -d "-90 day" +%Y%m%d) +%s` #取90天之前的时间戳
TRE_Date=`date -d $(date -d "-365 day" +%Y%m%d) +%s` #取365天之前的时间戳

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

optimize table events;

PS:history是详细历史数据表,trends是图形趋势表;可以根据自己需求设置保留时间。

weinxin
聂扬帆博客
一个分享IT运维相关工作经验和实战技巧的个人博客

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: