From bfe8398eacf77f86c3dc38bcb20bb6f627023041 Mon Sep 17 00:00:00 2001 From: yangbinnnn Date: Mon, 2 Jul 2018 22:30:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9agent=20=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E7=9A=84lastUpdate=20=E6=9B=B4=E6=96=B0=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原来只在AgentVersion,IP, PluginVersion 变化时,才做缓存更新, 这样一个问题的是没有准确记录agent 的心跳时间,从而导致基于lastUpdate 的一些判断没有意义, 比如DeleteStaleAgents 或者基于lasteUpdate 实现的agent.alive 存活状态就无法实现 --- modules/hbs/cache/agents.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/hbs/cache/agents.go b/modules/hbs/cache/agents.go index 25d10bbf1..c44f9af19 100644 --- a/modules/hbs/cache/agents.go +++ b/modules/hbs/cache/agents.go @@ -19,10 +19,11 @@ package cache // 提供http接口查询机器信息,排查重名机器的时候比较有用 import ( - "github.com/open-falcon/falcon-plus/common/model" - "github.com/open-falcon/falcon-plus/modules/hbs/db" "sync" "time" + + "github.com/open-falcon/falcon-plus/common/model" + "github.com/open-falcon/falcon-plus/modules/hbs/db" ) type SafeAgents struct { @@ -48,10 +49,12 @@ func (this *SafeAgents) Put(req *model.AgentReportRequest) { agentInfo.ReportRequest.PluginVersion != req.PluginVersion { db.UpdateAgent(val) - this.Lock() - this.M[req.Hostname] = val - this.Unlock() } + + // 更新hbs 时间 + this.Lock() + this.M[req.Hostname] = val + this.Unlock() } func (this *SafeAgents) Get(hostname string) (*model.AgentUpdateInfo, bool) {