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

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

parent 6a8afab6
...@@ -9,7 +9,7 @@ var ( ...@@ -9,7 +9,7 @@ var (
LogFileName = "agent.log" LogFileName = "agent.log"
DaemonLogFileName = "agent_daemon.log" DaemonLogFileName = "agent_daemon.log"
MountPrefix = "/host" MountPrefix = "/"
MountProc = MountPrefix + "/proc/" MountProc = MountPrefix + "/proc/"
PluginDir = WorkDir + "/plugin" PluginDir = WorkDir + "/plugin"
......
...@@ -105,6 +105,27 @@ func (w *Watch) watchResourcesUsage() { ...@@ -105,6 +105,27 @@ func (w *Watch) watchResourcesUsage() {
getAndPrintHostInfo() getAndPrintHostInfo()
getAndPrintProcessInfo() getAndPrintProcessInfo()
w.getAndPrintContainerInfo() 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() 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