zoukankan      html  css  js  c++  java
  • Zabbix数据库清理历史数据

    Zabbix清理历史数据

    Zabbix是个很好的监控软件,随着公司监控项目越来越多,数据越来越多,zabbix负载重,可能造成系统性能下降。

    Zabbix里面最大的表就是历史记录表,history,history_str,history_uint,trends

    trends_uint,events。清除数据表之前,做个备份,防患于未然。

    方法一:相对安全

    脚本内容

    #!/bin/bash

    User="root"

    Passwd="123456789"

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

    $(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; "

     

    添加至定时任务,每周执行一次。

    方法二:可以使用truncate命令直接清空数据库,因为 truncate 删除了表,然后根据表结构重新建立它,而 delete 删除的是记录,并没有尝试去修改表。不过truncate命令虽然快,却不像delete命令那样对事务处理是安全的。

    mysql  -uroot -p 输入mysql密码 

    use zabbix; 

      truncate table history;
      optimize table history;
      truncate table history_str;
      optimize table history_str;
      truncate table history_uint;
      optimize table history_uint;
      truncate table trends;
      optimize table trends;
      truncate table trends_uint; 
      optimize table trends_uint; 
      truncate table events;
      optimize table events;
     注意:这些命令会把zabbix所有的监控数据清空,操作前注意备份数据库

  • 相关阅读:
    Performance and Design
    返回数组中不重复的元素
    IE的button元素bug
    (转)Google Closure: 糟糕的JavaScript
    Why do we have an IMG element?
    About this and that
    C#中的Attribute
    C#检查字体是否存储,以及安装
    ZipFile压缩文件后,解压文件后有多层目录的处理方法
    Office系列在线预览
  • 原文地址:https://www.cnblogs.com/sxshaolong/p/10194537.html
Copyright © 2011-2022 走看看