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
c992fbfb
authored
Sep 23, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix-graphs' into 'master'
Fix Graphs
parents
beee6ccb
08fc87fc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
13 deletions
+23
-13
requirements.txt
+1
-1
src/client.py
+22
-12
No files found.
requirements.txt
View file @
c992fbfb
psutil
==
1.2
.1
psutil
==
2.1
.1
pika
src/client.py
View file @
c992fbfb
...
...
@@ -107,13 +107,15 @@ class Client:
"""
now
=
time
.
time
()
vmem
=
psutil
.
virtual_memory
()
metrics
=
{
'cpu.
usage'
:
psutil
.
cpu_percent
(
interval
=
0.0
),
'cpu.
percent'
:
psutil
.
cpu_percent
(
),
'cpu.times'
:
psutil
.
cpu_times
()
.
user
+
psutil
.
cpu_times
()
.
system
,
'memory.usage'
:
psutil
.
virtual_memory
()
.
percent
,
'memory.usage'
:
vmem
.
percent
,
'memory.used_bytes'
:
(
vmem
.
total
-
vmem
.
available
),
'swap.usage'
:
psutil
.
swap_memory
()
.
percent
,
'user.count'
:
len
(
psutil
.
get_
users
()),
'system.boot_time'
:
psutil
.
get_
boot_time
()
'user.count'
:
len
(
psutil
.
users
()),
'system.boot_time'
:
psutil
.
boot_time
()
}
for
k
,
v
in
psutil
.
disk_io_counters
()
.
__dict__
.
items
():
...
...
@@ -121,7 +123,11 @@ class Client:
interfaces
=
psutil
.
network_io_counters
(
pernic
=
True
)
for
interface
,
data
in
interfaces
.
iteritems
():
if
not
interface
.
startswith
(
'cloud-'
):
if
not
(
interface
.
startswith
(
'cloud'
)
or
interface
.
endswith
(
'-EXT'
)
or
interface
.
startswith
(
'net'
)
or
interface
.
startswith
(
'link'
)
or
interface
in
(
'lo'
,
'firewall'
,
'virbr0'
,
'ovs-system'
)):
for
metric
in
(
'packets_sent'
,
'packets_recv'
,
'bytes_sent'
,
'bytes_recv'
):
metrics
[
'network.
%
s-
%
s'
%
...
...
@@ -145,14 +151,18 @@ class Client:
for
entry
in
psutil
.
get_process_list
():
try
:
if
entry
.
name
in
(
'kvm'
,
'qemu-system-x86_64'
):
if
entry
.
name
()
in
(
'kvm'
,
'qemu-system-x86_64'
):
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
'-name'
)
parser
.
add_argument
(
'--memory-size'
,
'-m '
,
type
=
int
)
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
()
/
100
*
args
.
memory_size
)
...
...
@@ -160,11 +170,10 @@ class Client:
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'value'
:
mem_perc
,
'time'
:
now
})
user_time
,
system_time
=
process
.
get_cpu_times
()
sum_time
=
system_time
+
user_time
metrics
.
append
(
'vm.
%(name)
s.cpu.usage
%(value)
f '
cpu_perc
=
process
.
get_cpu_percent
()
metrics
.
append
(
'vm.
%(name)
s.cpu.percent
%(value)
f '
'
%(time)
d'
%
{
'name'
:
args
.
name
,
'value'
:
sum_time
,
'value'
:
cpu_perc
,
'time'
:
now
})
running_vms
.
append
(
args
.
name
)
except
psutil
.
NoSuchProcess
:
...
...
@@ -210,6 +219,7 @@ class Client:
modul to work properly.
"""
self
.
connect
()
self
.
processes
=
{}
try
:
while
True
:
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