From fbb11de178ed9cd52798b8ea16666443dcb6d1fa Mon Sep 17 00:00:00 2001 From: 710leo <710leo@gmail.com> Date: Wed, 13 May 2020 16:09:44 +0800 Subject: [PATCH] Fix parse port collect file --- src/modules/collector/stra/port.go | 7 +++++-- src/modules/collector/stra/proc.go | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/modules/collector/stra/port.go b/src/modules/collector/stra/port.go index 9c55b27a..7765d163 100644 --- a/src/modules/collector/stra/port.go +++ b/src/modules/collector/stra/port.go @@ -3,6 +3,7 @@ package stra import ( "fmt" "os" + "path/filepath" "strconv" "strings" "time" @@ -51,13 +52,15 @@ func GetPortCollects() map[int]*model.PortCollect { continue } - service, err := file.ToTrimString(StraConfig.PortPath + "/" + f) + filePath := filepath.Join(portPath, f) + + service, err := file.ToTrimString(filePath) if err != nil { logger.Warning(err) continue } - info, err := os.Stat(f) + info, err := os.Stat(filePath) if err != nil { logger.Warning(err) continue diff --git a/src/modules/collector/stra/proc.go b/src/modules/collector/stra/proc.go index dbdef350..f825ecdf 100644 --- a/src/modules/collector/stra/proc.go +++ b/src/modules/collector/stra/proc.go @@ -3,6 +3,7 @@ package stra import ( "fmt" "os" + "path/filepath" "strconv" "strings" "time" @@ -37,7 +38,8 @@ func GetProcCollects() map[string]*model.ProcCollect { } } - files, err := file.FilesUnder(StraConfig.ProcPath) + procPath := StraConfig.ProcPath + files, err := file.FilesUnder(procPath) if err != nil { logger.Error(err) return procs @@ -51,13 +53,14 @@ func GetProcCollects() map[string]*model.ProcCollect { continue } - service, err := file.ToTrimString(StraConfig.ProcPath + "/" + f) + filePath := filepath.Join(procPath, f) + service, err := file.ToTrimString(filePath) if err != nil { logger.Warning(err) continue } - info, err := os.Stat(f) + info, err := os.Stat(filePath) if err != nil { logger.Warning(err) continue