Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
monitor-client
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
6ac9301d
authored
Feb 11, 2024
by
Szeberényi Imre
Browse files
Options
Browse Files
Download
Plain Diff
ps fix
parents
4395d49b
54443046
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
18 deletions
+26
-18
src/client.py
+26
-18
No files found.
src/client.py
View file @
6ac9301d
...
@@ -10,7 +10,11 @@ import psutil
...
@@ -10,7 +10,11 @@ import psutil
import
time
import
time
import
re
import
re
logging
.
basicConfig
()
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
level
=
os
.
environ
.
get
(
'LOGLEVEL'
,
'INFO'
)
logger
.
setLevel
(
level
)
class
Client
:
class
Client
:
...
@@ -153,8 +157,8 @@ class Client:
...
@@ -153,8 +157,8 @@ class Client:
now
=
time
.
time
()
now
=
time
.
time
()
running_vms
=
[]
running_vms
=
[]
for
entry
in
psutil
.
get_process_list
()
:
try
:
try
:
for
entry
in
psutil
.
get_process_list
()
:
if
entry
.
name
()
in
(
'kvm'
,
'qemu-system-x86_64'
):
if
entry
.
name
()
in
(
'kvm'
,
'qemu-system-x86_64'
):
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-name'
)
parser
.
add_argument
(
'-name'
)
...
@@ -162,31 +166,35 @@ class Client:
...
@@ -162,31 +166,35 @@ class Client:
args
,
unknown
=
parser
.
parse_known_args
(
args
,
unknown
=
parser
.
parse_known_args
(
entry
.
cmdline
()[
1
:])
entry
.
cmdline
()[
1
:])
# for Red Hat style parametering of kvm
# for Red Hat style parametering of kvm
args
.
name
=
re
.
sub
(
r"^guest="
,
""
,
args
.
name
)
if
isinstance
(
args
.
name
,
basestring
):
args
.
name
=
re
.
sub
(
r",debug-threads=.*$"
,
""
,
args
.
name
)
args
.
name
=
re
.
sub
(
r"^guest="
,
""
,
args
.
name
)
args
.
name
=
re
.
sub
(
r",debug-threads=.*$"
,
""
,
args
.
name
)
process
=
self
.
processes
.
get
(
entry
.
pid
,
None
)
process
=
self
.
processes
.
get
(
entry
.
pid
,
None
)
if
not
process
or
process
.
cmdline
()
!=
entry
.
cmdline
():
if
not
process
or
process
.
cmdline
()
!=
entry
.
cmdline
():
process
=
psutil
.
Process
(
entry
.
pid
)
process
=
psutil
.
Process
(
entry
.
pid
)
logger
.
info
(
'New process:
%
s'
,
process
)
logger
.
info
(
'New process:
%
s'
,
process
)
self
.
processes
[
entry
.
pid
]
=
process
self
.
processes
[
entry
.
pid
]
=
process
mem_perc
=
(
float
(
process
.
get_memory_info
()
.
rss
)
mem_perc
=
(
float
(
process
.
get_memory_info
()
.
rss
)
/
(
args
.
memory_size
*
1024
**
2
)
*
90
)
/
(
args
.
memory_size
*
1024
**
2
)
*
90
)
metrics
.
append
(
'vm.
%(name)
s.memory.usage
%(value)
f '
metrics
.
append
(
'vm.
%(name)
s.memory.usage
%(value)
f '
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'value'
:
mem_perc
,
'value'
:
mem_perc
,
'time'
:
now
})
'time'
:
now
})
cpu_perc
=
process
.
get_cpu_percent
()
cpu_perc
=
process
.
get_cpu_percent
()
metrics
.
append
(
'vm.
%(name)
s.cpu.percent
%(value)
f '
metrics
.
append
(
'vm.
%(name)
s.cpu.percent
%(value)
f '
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'value'
:
cpu_perc
,
'value'
:
cpu_perc
,
'time'
:
now
})
'time'
:
now
})
running_vms
.
append
(
args
.
name
)
running_vms
.
append
(
args
.
name
)
except
psutil
.
NoSuchProcess
:
else
:
logger
.
warning
(
'Process
%
d lost.'
,
entry
.
pid
)
logger
.
warning
(
'Pid:
%
d args.name is empty?:
%
s
%
s'
,
entry
.
pid
,
entry
.
name
(),
entry
.
cmdline
())
except
TypeError
:
logger
.
warning
(
'ParseError
%
s.'
,
entry
.
cmdline
())
except
psutil
.
NoSuchProcess
:
logger
.
warning
(
'Process
%
d lost.'
,
entry
.
pid
)
except
TypeError
:
logger
.
warning
(
'ParseError
%
s.'
,
entry
.
cmdline
())
interfaces
=
psutil
.
network_io_counters
(
pernic
=
True
)
interfaces
=
psutil
.
network_io_counters
(
pernic
=
True
)
for
interface
,
data
in
interfaces
.
iteritems
():
for
interface
,
data
in
interfaces
.
iteritems
():
...
...
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