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
08fc87fc
authored
Sep 19, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve cpu.percent metric
parent
186489f5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
6 deletions
+10
-6
src/client.py
+10
-6
No files found.
src/client.py
View file @
08fc87fc
...
@@ -109,7 +109,7 @@ class Client:
...
@@ -109,7 +109,7 @@ class Client:
now
=
time
.
time
()
now
=
time
.
time
()
vmem
=
psutil
.
virtual_memory
()
vmem
=
psutil
.
virtual_memory
()
metrics
=
{
metrics
=
{
'cpu.
usage
'
:
psutil
.
cpu_percent
(),
'cpu.
percent
'
:
psutil
.
cpu_percent
(),
'cpu.times'
:
psutil
.
cpu_times
()
.
user
+
psutil
.
cpu_times
()
.
system
,
'cpu.times'
:
psutil
.
cpu_times
()
.
user
+
psutil
.
cpu_times
()
.
system
,
'memory.usage'
:
vmem
.
percent
,
'memory.usage'
:
vmem
.
percent
,
'memory.used_bytes'
:
(
vmem
.
total
-
vmem
.
available
),
'memory.used_bytes'
:
(
vmem
.
total
-
vmem
.
available
),
...
@@ -158,7 +158,11 @@ class Client:
...
@@ -158,7 +158,11 @@ class Client:
args
,
unknown
=
parser
.
parse_known_args
(
args
,
unknown
=
parser
.
parse_known_args
(
entry
.
cmdline
()[
1
:])
entry
.
cmdline
()[
1
:])
process
=
psutil
.
Process
(
entry
.
pid
)
process
=
self
.
processes
.
get
(
entry
.
pid
,
None
)
if
not
process
or
process
.
cmdline
()
!=
entry
.
cmdline
():
process
=
psutil
.
Process
(
entry
.
pid
)
logger
.
info
(
'New process:
%
s'
,
process
)
self
.
processes
[
entry
.
pid
]
=
process
mem_perc
=
(
process
.
get_memory_percent
()
mem_perc
=
(
process
.
get_memory_percent
()
/
100
*
args
.
memory_size
)
/
100
*
args
.
memory_size
)
...
@@ -166,11 +170,10 @@ class Client:
...
@@ -166,11 +170,10 @@ class Client:
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'value'
:
mem_perc
,
'value'
:
mem_perc
,
'time'
:
now
})
'time'
:
now
})
user_time
,
system_time
=
process
.
get_cpu_times
()
cpu_perc
=
process
.
get_cpu_percent
()
sum_time
=
system_time
+
user_time
metrics
.
append
(
'vm.
%(name)
s.cpu.percent
%(value)
f '
metrics
.
append
(
'vm.
%(name)
s.cpu.usage
%(value)
f '
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'value'
:
sum_time
,
'value'
:
cpu_perc
,
'time'
:
now
})
'time'
:
now
})
running_vms
.
append
(
args
.
name
)
running_vms
.
append
(
args
.
name
)
except
psutil
.
NoSuchProcess
:
except
psutil
.
NoSuchProcess
:
...
@@ -216,6 +219,7 @@ class Client:
...
@@ -216,6 +219,7 @@ class Client:
modul to work properly.
modul to work properly.
"""
"""
self
.
connect
()
self
.
connect
()
self
.
processes
=
{}
try
:
try
:
while
True
:
while
True
:
metrics
=
self
.
collect_node
()
+
self
.
collect_vms
()
metrics
=
self
.
collect_node
()
+
self
.
collect_vms
()
...
...
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