Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Lei Li
agent
Commits
4381274d
Commit
4381274d
authored
Oct 15, 2024
by
Lei Li
Browse files
feat: 获取本身程序内存和cpu使用
parent
6a8afab6
Changes
2
Hide whitespace changes
Inline
Side-by-side
cmd/agent/config/config.go
View file @
4381274d
...
@@ -9,12 +9,12 @@ var (
...
@@ -9,12 +9,12 @@ 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"
Version
=
""
Version
=
""
BuildCommit
=
""
BuildCommit
=
""
MonitorLogUnModDuration
=
600
*
time
.
Second
MonitorLogUnModDuration
=
600
*
time
.
Second
...
...
module/resources/resources_watch.go
View file @
4381274d
...
@@ -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
()
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment