Heim  >  Artikel  >  Betrieb und Instandhaltung  >  Ausführliche Erläuterung von Beispielen für Zabbix-Überwachungsserverzeitprobleme

Ausführliche Erläuterung von Beispielen für Zabbix-Überwachungsserverzeitprobleme

PHP中文网
PHP中文网Original
2018-05-16 13:53:256428Durchsuche

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脚本

#!/usr/bin/env python
# -*- coding:UTF-8 -*-
import time
import ntplib
 
def get_time():
    ntp_client = ntplib.NTPClient()
    response = ntp_client.request('s2g.time.edu.cn')
    wtime = time.strftime('%Y%m%d%H%M%S', time.localtime(response.tx_time))
    return wtime
if __name__ == '__main__':
    networktime = get_time()
    local_time = time.strftime('%Y%m%d%H%M%S')
    difference = abs(int(networktime) - int(local_time))
    print difference

windows下可以使用pyinstaller打包成exe可执行文件

第三在zabbix_agentd.conf中添加自定义的key

UserParameter=custom.timediff.count,"D:\bat\get_time.exe"

重启zabbix服务

第四添加监控和触发器,本人设置当时间不一致超过3秒就出发报警。

这个,相信大家都会,就不多说了

第五触发报警后,可在服务器上执行

同步时间

w32tm /resync

Das obige ist der detaillierte Inhalt vonAusführliche Erläuterung von Beispielen für Zabbix-Überwachungsserverzeitprobleme. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn