Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
FalconPlugin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
FalconPlugin
Commits
1aeaf4d3
Commit
1aeaf4d3
authored
Nov 20, 2019
by
李贺
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新进程采集
parent
d4a00d90
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
12 deletions
+30
-12
90_processlist_monitor.py.bak
sys/back/90_processlist_monitor.py.bak
+0
-0
600_processlist_monitor.py
sys/process/600_processlist_monitor.py
+30
-12
No files found.
sys/
process
/90_processlist_monitor.py.bak
→
sys/
back
/90_processlist_monitor.py.bak
View file @
1aeaf4d3
File moved
sys/process/60_processlist_monitor.py
→
sys/process/60
0
_processlist_monitor.py
View file @
1aeaf4d3
'''
@Descripttion:
@Author: leenhem
@Contact: leenhem.lh@gmail.com
@Date: 2019-10-29 18:27:27
@FilePath: /FalconPlugin/sys/process/60_processlist_monitor.py
'''
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from
subprocess
import
Popen
,
PIPE
...
...
@@ -8,18 +15,28 @@ data = []
endpoint
=
"172.30.4.75"
def
get_all_mountpoint
():
data
=
[]
memory_data
=
[]
cpu_data
=
[]
p0
=
Popen
([
'ps'
,
'-aux'
],
stdout
=
PIPE
,
stderr
=
PIPE
)
raw_data
=
Popen
([
'sort'
,
'-k4nr'
],
stdin
=
p0
.
stdout
,
stdout
=
PIPE
,
stderr
=
PIPE
)
raw_data
=
Popen
([
'grep'
,
'-v'
,
'
%
CPU'
],
stdin
=
raw_data
.
stdout
,
stdout
=
PIPE
,
stderr
=
PIPE
)
.
communicate
()[
0
]
p0
=
Popen
([
'ps'
,
'-aux'
],
stdout
=
PIPE
,
stderr
=
PIPE
)
cpu
=
Popen
([
'sort'
,
'-k3nr'
],
stdin
=
p0
.
stdout
,
stdout
=
PIPE
,
stderr
=
PIPE
)
cpu
=
Popen
([
'grep'
,
'-v'
,
'
%
CPU'
],
stdin
=
cpu
.
stdout
,
stdout
=
PIPE
,
stderr
=
PIPE
)
.
communicate
()[
0
]
for
i
in
raw_data
.
split
(
'
\n
'
):
data
.
append
(
i
)
if
len
(
data
)
==
10
:
break
return
data
memory_data
.
append
(
i
)
if
len
(
memory_data
)
==
10
:
break
for
i
in
cpu
.
split
(
'
\n
'
):
cpu_data
.
append
(
i
)
if
len
(
cpu_data
)
==
10
:
break
return
memory_data
,
cpu_data
if
__name__
==
"__main__"
:
list
=
get_all_mountpoint
()
for
i
in
list
:
memory
,
cpu
=
get_all_mountpoint
()
for
i
in
memory
:
process
=
i
.
split
(
' '
)
while
''
in
process
:
process
.
remove
(
''
)
...
...
@@ -30,9 +47,12 @@ if __name__ == "__main__":
"metric"
:
"sys.process.memory.percent"
,
"counterType"
:
"GAUGE"
,
"value"
:
float
(
process
[
3
]),
"step"
:
60
"step"
:
60
0
}
data
.
append
(
tmp_memory_percent
)
for
i
in
cpu
:
while
''
in
process
:
process
.
remove
(
''
)
tmp_cpu_percent
=
{
"endpoint"
:
endpoint
,
"tags"
:
"pid="
+
process
[
1
]
+
",cmd="
+
' '
.
join
(
process
[
10
:]),
...
...
@@ -40,9 +60,7 @@ if __name__ == "__main__":
"metric"
:
"sys.process.cpu.percent"
,
"counterType"
:
"GAUGE"
,
"value"
:
float
(
process
[
2
]),
"step"
:
60
"step"
:
60
0
}
data
.
append
(
tmp_cpu_percent
)
data
.
append
(
tmp_memory_percent
)
print
json
.
dumps
(
data
)
\ No newline at end of file
print
json
.
dumps
(
data
)
\ No newline at end of file
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