zabbix清理历史数据

1.查看数据占用空间

cd /data/mysql/zabbix/
du -sh * | grep G

 

2.对应到数据库中就是history_uint和history两个表数据比较大

mysql> select table_name, (data_length+index_length)/1024/1024 as total_mb,table_rows from information_schema.tables where table_schema='zabbix' order by total_mb desc;
+----------------------------+---------------+------------+
| table_name                 | total_mb      | table_rows |
+----------------------------+---------------+------------+
| history_uint               | 2820.17187500 |   28546891 |
| history                    | 2034.39062500 |   19045070 |
| trends_uint                |  119.59375000 |    1579101 |
| trends                     |  107.67187500 |    1420596 |

3.清理数据,保留三个月的数据

mysql> delete from history where clock < 1669824000;
mysql> delete from history_uint where clock < 1669824000;

# delete操作有点慢

4.优化表

mysql> optimize table history;
mysql> optimize table history_uint;

5.数据分区

删除历史数据后,数据量还是很大,继续对数据库进行分区操作,提高效率,网上有写好的分区脚本,直接下载使用

wget https://dl.cactifans.com/zabbix/partitiontables_gt_zbx34.sh

修改脚本参数

# history和trends相关表数据量很大,一个是历史数据,一个是趋势数据,脚本中默认详情数据保留30天,趋势数据保留12个月,如需修改,请修改以下内容:
# How long to keep the daily history
daily_history_min=30
# How long to keep the monthly history (months)
monthly_history_min=12

# 修改数据库连接信息
DBHOST=localhost
DBUSER=zabbix
DBPASS=xxx

增加脚本执行权限:chmod +x partitiontables_gt_zbx34.sh

关闭zabbix-server

执行脚本:./partitiontables_gt_zbx34.sh

 

posted @ 2023-01-31 10:40  chenjianwen  阅读(475)  评论(0编辑  收藏  举报