Zabbix历史数据清理(保留以往每个项目每天一条数据)

部门同事说zabbix数据太大,清理一下历史数据,结果以往数据一条都不见了。-_-!

看了网上的教程也都是说直接truncate两张表history和history_uint


我的想法是,以前的历史数据,每个项目每天保留一条,这样的话可以留一些数据供后期参考


先看一下这两张表

根据itemid日期取每天最小的clock

select itemid,date_format(from_unixtime(clock),'%Y-%m-%d'),count(*),min(clock) from history group by itemid,date_format(from_unixtime(clock), '%Y-%m-%d');

 执行删除

delete from history where (itemid,clock) not in 
(select itemid,min(clock) from history group by itemid,date_format(from_unixtime(clock), '%Y-%m-%d'));
delete from history_uint where (itemid,clock) not in 
(select itemid,min(clock) from history_uint group by itemid,date_format(from_unixtime(clock), '%Y-%m-%d'));
delete from trends_uint where (itemid,clock) not in 
(select itemid,min(clock) from trends_uint group by itemid,date_format(from_unixtime(clock), '%Y-%m-%d'));

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值