设为首页 加入收藏

TOP

zabbix监控服务器时间问题
2017-10-11 16:20:01 】 浏览:7963
Tags: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

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Hyper-V2:向VM增加虚拟硬盘 下一篇Hyper-V3:虚拟机的配置

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目