Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
pika
src/client.py
View file @
c992fbfb
...
@@ -107,13 +107,15 @@ class Client:
...
@@ -107,13 +107,15 @@ class Client:
"""
"""
now
=
time
.
time
()
now
=
time
.
time
()
vmem
=
psutil
.
virtual_memory
()
metrics
=
{
metrics
=
{
'cpu.
usage'
:
psutil
.
cpu_percent
(
interval
=
0.0
),
'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'
:
psutil
.
virtual_memory
()
.
percent
,
'memory.usage'
:
vmem
.
percent
,
'memory.used_bytes'
:
(
vmem
.
total
-
vmem
.
available
),
'swap.usage'
:
psutil
.
swap_memory
()
.
percent
,
'swap.usage'
:
psutil
.
swap_memory
()
.
percent
,
'user.count'
:
len
(
psutil
.
get_
users
()),
'user.count'
:
len
(
psutil
.
users
()),
'system.boot_time'
:
psutil
.
get_
boot_time
()
'system.boot_time'
:
psutil
.
boot_time
()
}
}
for
k
,
v
in
psutil
.
disk_io_counters
()
.
__dict__
.
items
():
for
k
,
v
in
psutil
.
disk_io_counters
()
.
__dict__
.
items
():
...
@@ -121,7 +123,11 @@ class Client:
...
@@ -121,7 +123,11 @@ class Client:
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
():
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'
,
for
metric
in
(
'packets_sent'
,
'packets_recv'
,
'bytes_sent'
,
'bytes_recv'
):
'bytes_sent'
,
'bytes_recv'
):
metrics
[
'network.
%
s-
%
s'
%
metrics
[
'network.
%
s-
%
s'
%
...
@@ -145,14 +151,18 @@ class Client:
...
@@ -145,14 +151,18 @@ class Client:
for
entry
in
psutil
.
get_process_list
():
for
entry
in
psutil
.
get_process_list
():
try
:
try
:
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'
)
parser
.
add_argument
(
'--memory-size'
,
'-m '
,
type
=
int
)
parser
.
add_argument
(
'--memory-size'
,
'-m '
,
type
=
int
)
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
)
...
@@ -160,11 +170,10 @@ class Client:
...
@@ -160,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
:
...
@@ -210,6 +219,7 @@ class Client:
...
@@ -210,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