zabbix笔记之异常优化

zabbix异常优化

脚本超时问题

在在使用自定义脚本的时候,有时候发现报错这种报错:Timeout while executing a shell script

设置脚本超时时间

修改zabbix-server和zabbix-agent 配置文件,设置超时时间,zabbix的配置文件默认为3秒,我把它改成30秒了

[root@zabbix ~]#vim /etc/zabbix/zabbix_server.conf
Timeout=30
[root@zabbix ~]#systemctl restart zabbix-server
[root@agent ~]# vim /etc/zabbix/zabbix_agentd.conf
Timeout=30
[root@agent ~]#systemctl restart zabbix-agent

value too …… large 问题

 在用zabbix自带模板监控磁盘空间的时候,当磁盘空间很大的时候(我的是2T)发现item变得不支持了,报错如下:Value 2133522087936.000000 is too small or too large.

[root@zabbix ~]# find / -name "func.inc.php" //找到zabbix定义单位的配置文件
/usr/share/zabbix/include/func.inc.php
[root@zabbix ~]# cp  /usr/share/zabbix/include/func.inc.php  /usr/share/zabbix/include/func.inc.php.bak //备份配置文件
[root@zabbix ~]# vim /usr/share/zabbix/include/func.inc.php //备份配置文件
if ($size > 1073741824) {
 $size = $size / 1073741824;
 $prefix = 'G';
 }
 elseif ($size > 1048576) {
 $size = $size / 1048576;
 $prefix = 'M';
 }

单位异常问题

在使用自定义监控项的时候发现,zabbix取到的值很大的时候,会自动变成K,M,G

 可以通过修改func.inc.php文件来优化这种问题

[root@zabbix ~]# find / -name func.inc.php
 /usr/share/zabbix/include/func.inc.php
 [root@zabbix ~]#cd /usr/share/zabbix/include/
 [root@zabbix include]#cp func.inc.php func.inc.php.bak
 [root@zabbix include]#vim func.inc.php
 $blackList = ['%', 'ms', 'rpm', 'RPM','as'];
# as可以理解为一个单位,可以自定义

 历史数据过大问题

Zabbix运行一段时间时候,会留下大量的历史数据,会发现zabbix的数据库一直增大,运行了将近一年后,数据库达到了30G,可能会造成系统性能下降,查看历史数据速度变慢 所以需要对zabbix的数据库进行优化,来提高数据库的性能

思路:可以通过定位时间来删除历史数据

注意:mysql中的zabbix库中的时间都是用时间戳来记录,因此我们要先将时间格式装换为时间戳格式,再需要根据时间戳来删除数据

时间格式转化

先将标准时间转换为时间戳格式

[root@zabbix scripts]# date +%s -d "2019-9-1"
1567267200
[root@zabbix scripts]# date +%s -d "-30 day" (推荐使用该种方式)
1566908243

MySQL清理数据

按照时间段来删除历史数据

主要清除以下几张表中的数据: 

历史数据表(history history_str history_uint )

趋势表(trends trends_uint enents)

mysql> delete from history where clock <1566908243;
mysql>optimize table history;

清除全部数据的方法

mysql>use zabbix;
mysql>truncate table history;
mysql>optimize table history;
mysql>truncate table history_str;
mysql>optimize table history_str;
mysql>truncate table history_uint;
mysql>optimize table history_uint;
mysql>truncate table trends;
mysql>optimize table trends;
mysql>truncate table trends_uint;
mysql>optimize table trends_uint;
mysql>truncate table events;
ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (`zabbix`.`acknowledges`, CONSTRAINT `c_acknowledges_2` FOREIGN KEY (`eventid`) REFERENCES `zabbix`.`events` (`eventid`))
Mysql中如果表和表之间建立的外键约束,则无法删除表及修改表结构
解决方法:
mysql>  SET foreign_key_checks=0;
truncate table events;
optimize table events;
mysql>  SET foreign_key_checks=1;
mysql>optimize table events;

Zabbix poller processes more than 75% busy问题

有时候会发现zabbix有这种告警:Zabbix poller processes more than 75% busy

1.编辑Zabbix Server的配置文件,增加一行配置StartPollers=10,将StartPollers改成多少取决于服务器的性能和监控的数量

[root@zabbix ~]# vim /etc/zabbix/zabbix_server.conf
StartPollers=10

2.重启Zabbix

[root@zabbix ~]# systemctl restart zabbix-server

自动发现规则优化

我的图不见了,借用的是网图,不太清晰,有机会再截

测试通过读取文件中的信息自动创建监控项,创建结果下图

由于修改了原始的文件信息,再次查看创建的监控项时,系统提示

该时间默认的时30天,上图是已经修改的时间 需要在创建自动发现规则时,修改参数Keep lost resources period;如下图

原文地址:https://www.cnblogs.com/zhangcheng94/p/12183189.html