Commit 4381274d authored by Lei Li's avatar Lei Li
Browse files

feat: 获取本身程序内存和cpu使用

parent 6a8afab6
......@@ -9,12 +9,12 @@ var (
LogFileName = "agent.log"
DaemonLogFileName = "agent_daemon.log"
MountPrefix = "/host"
MountPrefix = "/"
MountProc = MountPrefix + "/proc/"
PluginDir = WorkDir + "/plugin"
Version = ""
Version = ""
BuildCommit = ""
MonitorLogUnModDuration = 600 * time.Second
......
......@@ -105,6 +105,27 @@ func (w *Watch) watchResourcesUsage() {
getAndPrintHostInfo()
getAndPrintProcessInfo()
w.getAndPrintContainerInfo()
if w.curMemUsage == 0.0 {
proc, err := process.NewProcess(int32(os.Getpid()))
if err != nil {
l.Error("Error:", err)
return
}
memInfo, err := proc.MemoryInfo()
if err != nil {
l.Error("Error:", err)
return
} else {
w.curMemUsage = float64(memInfo.RSS)
}
// 获取CPU使用率
cpuPercent, err := proc.CPUPercent()
if err != nil {
l.Error("Error:", err)
return
}
l.Infof("resources watch mem usage:%s, cpu usage:%.2f%%", unit.ByteSize(uint64(w.curMemUsage)), cpuPercent)
}
w.printResourcesUsage()
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment