目錄
- 問題
- 排查
- 解決
今天跟大家分享一個(gè)關(guān)于 zabbix Timeout 值設(shè)置不當(dāng)導(dǎo)致的問題,這個(gè)問題不知道大家有沒有碰到過
問題
事情經(jīng)過是這樣的:
把某一臺(tái) zabbix agent 的模板由原來的 Template OS Windows by Zabbix agent
換成了 Template OS Windows by Zabbix agent active
Template OS Windows by Zabbix agent active
使用 主動(dòng)模式 主動(dòng)獲取數(shù)據(jù)
Template OS Windows by Zabbix agent
使用 被動(dòng)模式 等待 Server 請(qǐng)求數(shù)據(jù)
也就是說在主動(dòng)模式下,Zabbix Agent 主動(dòng)連接到 Zabbix Server 并發(fā)送監(jiān)控?cái)?shù)據(jù),Zabbix Server 只需監(jiān)聽指定的端口,接收 Agent 發(fā)送過來的數(shù)據(jù)
結(jié)果發(fā)現(xiàn) zabbix server 接收不到數(shù)據(jù)
排查
查看 agent 日志(/var/log/zabbix/zabbix_agentd.log
),發(fā)現(xiàn) ZBX_TCP_READ() timed out
8452:20230620:134942.947 active check configuration update from [192.168.149.129:10051] started to fail (ZBX_TCP_READ() timed out) 8452:20230620:135044.072 active check configuration update from [192.168.149.129:10051] is working again 8452:20230620:140049.959 active check configuration update from [192.168.149.129:10051] started to fail (ZBX_TCP_READ() timed out) 8452:20230620:140149.093 active check configuration update from [192.168.149.129:10051] is working again
而且經(jīng)過進(jìn)一步排查,發(fā)現(xiàn):
- server 節(jié)點(diǎn)運(yùn)行正常,agent 節(jié)點(diǎn)正常運(yùn)行
- server 節(jié)點(diǎn)和 agent 節(jié)點(diǎn)之間可以 ping 通,而且 Telnet 端口可用
綜合上面的現(xiàn)象,懷疑是網(wǎng)絡(luò)原因?qū)е?TCP 建立連接時(shí)間超時(shí),agent 向 server 發(fā)送數(shù)據(jù)失敗
既然是網(wǎng)絡(luò)原因,那為什么我在修改模板(即被動(dòng)模式)之前,server 是能夠向 agent 獲取數(shù)據(jù)的
怎么被動(dòng)模式就沒超時(shí),主動(dòng)模式就超時(shí)了呢?
解決
在 Zabbix 中,timeout(超時(shí))是指在進(jìn)行監(jiān)控?cái)?shù)據(jù)獲取或傳輸時(shí),等待響應(yīng)的時(shí)間限制
在配置文件中如下所示,默認(rèn)值是 3 s
### Option: Timeout
# Spend no more than Timeout seconds on processing
# Timeout=3
我們分別來看下 server 和 agent 關(guān)于超時(shí)時(shí)間的配置
#server 端
Timeout=30#agent 端
Timeout=3
可以看到,sever 端設(shè)置的超時(shí)時(shí)間是 30 s,agent 端設(shè)置的超時(shí)時(shí)間是 3s,這兩個(gè)時(shí)間相差太大了吧
如果 agent 的 timeout 設(shè)置得太短,可能會(huì)導(dǎo)致一些請(qǐng)求無法完成;而如果 server 的 timeout 設(shè)置得太短,可能會(huì)導(dǎo)致 agent 的請(qǐng)求被錯(cuò)誤地判定為超時(shí)
結(jié)合上面的情況,可以得知:
- 主動(dòng)模式下,agent 向 server 發(fā)送數(shù)據(jù)的時(shí)候,agent 端設(shè)置的超時(shí)時(shí)間是 3s,有可能會(huì)出現(xiàn)網(wǎng)絡(luò)原因?qū)е?TCP 建立連接時(shí)間超時(shí),server 端獲取不到數(shù)據(jù),就會(huì)出現(xiàn)上面的問題
- 被動(dòng)模式下,server 向 agent 獲取數(shù)據(jù),但是 server 端設(shè)置的超時(shí)時(shí)間是 30s,這個(gè)超時(shí)時(shí)間可以說是非常大了
我們把 agent 端的超時(shí)時(shí)間改一下,跟 server 端一致
#agent 端
Timeout=30
重啟 agent 后發(fā)現(xiàn)日志沒有報(bào) started to fail (ZBX_TCP_READ() timed out)
錯(cuò),zabbix server 端也能夠獲取數(shù)據(jù)了
總結(jié)一下:
- 在 Zabbix 中,timeout 是指在進(jìn)行監(jiān)控?cái)?shù)據(jù)獲取或傳輸時(shí),等待響應(yīng)時(shí)間的限制
- Agent 和 Server 之間的超時(shí)時(shí)間設(shè)置應(yīng)該相互協(xié)調(diào),并根據(jù)實(shí)際網(wǎng)絡(luò)狀況和環(huán)境來進(jìn)行調(diào)整。如果 Agent 的 timeout 設(shè)置得太短,可能會(huì)導(dǎo)致一些請(qǐng)求無法完成;而如果 Server 的 timeout 設(shè)置得太短,可能會(huì)導(dǎo)致 Agent 的請(qǐng)求被錯(cuò)誤地判定為超時(shí)
- 主動(dòng)模式下 agent 的 timeout 值最好高于 server 配的 timeout 值,被動(dòng)模式下 server 配的 timeout 值最好高于 agent 的 timeout
If used with the passive agent, Timeout value in server configuration may need to be higher than Timeout in the agent configuration file. Otherwise the item may not get any value because the server request to agent timed out first.