


Detailed explanation of examples of zabbix monitoring server time issues
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
The above is the detailed content of Detailed explanation of examples of zabbix monitoring server time issues. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function