45

使用zabbix如何自动清理30天前的数据

 5 years ago
source link: https://www.linuxprobe.com/zabbix-del-30-data.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

zabbix属于一个细度化的监控工具,其入库数据随着细度的增加相应的入库数据量也会较大,当数据量到一定时候的时候其反映速度会比较慢,尽管其监控服务在配置时可以指定数据的保存周期, 但是了解下通过直接操作数据库进行数据删除还是有必要的。

通过数据库进行删除的脚本如下:

#!/bin/bash
User="root"
Passwd="361way"
Date=`date -d $(date -d "-30 day" +%Y%m%d) +%s` #取30天之前的时间戳
$(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 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;
"

注:其中histroy是详细的历史数据,trends是图表趋势数据。一般情况下,根据我的自定义,会将histroy数据保留7天,trend数据保留365天。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK