From a1130b0e7c13afd5c9e76a35b7ec6e9e20629f74 Mon Sep 17 00:00:00 2001 From: Paul Chu Date: Sun, 20 Dec 2020 12:34:21 +0800 Subject: [PATCH] =?UTF-8?q?MOD:=20agent=20=E6=96=87=E4=BB=B6=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=20rw=20=E6=8E=A2=E6=B5=8B=20(#465)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/agent/agent.go | 2 -- src/modules/agent/core/clients.go | 2 +- src/modules/agent/sys/funcs/fsstat.go | 20 +++++++++++++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/modules/agent/agent.go b/src/modules/agent/agent.go index 17c85f4b..83c7106d 100644 --- a/src/modules/agent/agent.go +++ b/src/modules/agent/agent.go @@ -10,7 +10,6 @@ import ( "github.com/didi/nightingale/src/common/loggeri" "github.com/didi/nightingale/src/modules/agent/cache" "github.com/didi/nightingale/src/modules/agent/config" - "github.com/didi/nightingale/src/modules/agent/core" "github.com/didi/nightingale/src/modules/agent/http" "github.com/didi/nightingale/src/modules/agent/log/worker" "github.com/didi/nightingale/src/modules/agent/report" @@ -85,7 +84,6 @@ func main() { udp.Start() } - core.InitRpcClients() http.Start() endingProc() diff --git a/src/modules/agent/core/clients.go b/src/modules/agent/core/clients.go index 789c32d3..d0b08740 100644 --- a/src/modules/agent/core/clients.go +++ b/src/modules/agent/core/clients.go @@ -12,7 +12,7 @@ type RpcClientContainer struct { var rpcClients *RpcClientContainer -func InitRpcClients() { +func init() { rpcClients = &RpcClientContainer{ M: make(map[string]*rpc.Client), } diff --git a/src/modules/agent/sys/funcs/fsstat.go b/src/modules/agent/sys/funcs/fsstat.go index c27742fc..8243fa73 100644 --- a/src/modules/agent/sys/funcs/fsstat.go +++ b/src/modules/agent/sys/funcs/fsstat.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io/ioutil" + "math/rand" "os" "path/filepath" "time" @@ -68,7 +69,7 @@ func FsRWMetrics() []*dataobj.MetricValue { continue } - file := filepath.Join(du.FsFile, ".fs-detect") + file := filepath.Join(du.FsFile, ".fs-detect."+genRandStr()) now := time.Now().Format("2006-01-02 15:04:05") content := "FS-RW" + now err = CheckFS(file, content) @@ -114,3 +115,20 @@ func CheckFS(file string, content string) error { } return nil } + +func genRandStr() string { + const len = 5 + var letters []byte = []byte("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") + + randBytes := make([]byte, len) + if _, err := rand.Read(randBytes); err != nil { + return fmt.Sprintf("%d", rand.Int63()) + } + + for i := 0; i < len; i++ { + pos := randBytes[i] % 62 + randBytes[i] = letters[pos] + } + + return string(randBytes) +}