zabbix监控服务器时间问题
zabbix中有自带对linux服务器时间进行监控的模板,用的key是system.localtime返回当前的系统时间,而配置tigger报警时是用的fuzzytime(N)方法,该方法是将返回的系统时间与监控服务器的时间进行对比,如果大于N,则报警。
存在一下3个问题:
1、监控服务器并不一定是ntp服务器:这种情况下也就说是系统时间是与非NTP服务器对比的时间。
2、取到被监控系统的时间,然后再返回给监控服务器,当监控项数量大,或监控出现延时队列的时候。就会产生误报。
3、对于windows server服务器没有相应的模版。
正好业务上有一批搭载系统为windows server的服务器,而业务对时间要求比较高。
下面是我的解决办法:
第一,利用下面的bat脚本设置windos时间同步服务器
@echo off
@REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\Parameters /v NtpServer /t REG_SZ /d "10.13.255.1,0x9\0 10.13.255.2,0x9\0 0.cn.pool.ntp.org,0x9" /f
@echo off
@REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\Parameters /v Type /t REG_SZ /d NTP /f
@echo off
echo ------------------------------------
@echo off
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\TimeProviders\NtpClient /v SpecialPollInterval /t REG_DWORD /d 60 /f
@echo off
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\Config /v MaxAllowPhaseOffset /t REG_DWORD /d 3600 /f
@echo off
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\Config /v MaxNegPhaseCorrection /t REG_DWORD /d 3600 /f
@echo off
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\Config /v MaxPosPhaseCorrection /t REG_DWORD /d 3600 /f
@echo off
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\Config /v PhaseCorrectRate /t REG_DWORD /d 7 /f
@echo off
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\Config /v MinPollInterval /t REG_DWORD /d 3 /f
@echo off
REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\Config /v MaxPollInterval /t REG_DWORD /d 4 /f
@echo off
sc triggerinfo w32time start/networkon
@echo off
gpupdate /force
@echo off
w32tm /resync
@echo off
net stop w32time
net start w32time
说明:
"10.13.255.1,0x9\0 10.13.255.2,0x9\0 0.cn.pool.ntp.org,0x9"
以上地址只适用于本人的托管机房
第二编写用于对比时间的python脚本
import time
import ntplib
import sys
import os def main():
try:
ntp_client = ntplib.NTPClient()
response = ntp_client.request('s2g.time.edu.cn')
ntp_timeStamp = response.tx_time
ntp_date = time.strftime('%Y-%m-%d', time.localtime(ntp_timeStamp))
ntp_time = time.strftime('%X', time.localtime(ntp_timeStamp))
except:
print u'无法获取到s2g.time.edu.cn上面的时间戳'
sys.exit() '''获取本地服务器时间戳'''
local_timeStamp = time.time() '''获取之间的差值'''
diff = abs(ntp_timeStamp - local_timeStamp)
print diff if __name__ == '__main__':
main()
windows下可以使用pyinstaller打包成exe可执行文件
第三在zabbix_agentd.conf中添加自定义的key
UserParameter=custom.timediff.count,"D:\bat\get_time.exe"
重启zabbix服务
第四添加监控和触发器,本人设置当时间不一致超过3秒就出发报警。
这个,相信大家都会,就不多说了
第五触发报警后,可在服务器上执行
同步时间
w32tm /resync
最新文章
- 从零自学Hadoop(19):HBase介绍及安装
- linux终端常用快捷键
- How to:如何让Installshield显示正确的软件所需空间--网友冰块先生贡献
- Yii2中系统定义的常用路径别名,如果获取web的url
- 自己动手跑起web项目
- Windows命令行中使用SSH连接Linux
- ASP.NET MVC @helper使用说明
- U盘、移动硬盘提示格式化的处理
- Codevs 3286 火柴排队 2013年NOIP全国联赛提高组 树状数组,逆序对
- 关于ios8斯坦福公开课第二课
- Android Resource介绍和使用
- python之数据库操作(sqlite)
- 记录 制作校园网登陆脚本 python编写 附源码
- Python常见面试题
- spring框架加载完成后执行上下文刷新事件(ContextRefreshedEvent)
- 阿里官方Java代码规范标准《阿里巴巴Java开发手册》下载
- 一个小动画,颠覆你的CSS世界观
- sqlserver2012 清除日志
- docker容器日志清理
- FindLine把多行查找改为多行替换