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
82348f5a
authored
Mar 03, 2014
by
Nagy Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Debug format changed. Refactored code. Added metrics.
parent
977465d6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
20 deletions
+39
-20
manage.py
+1
-1
src/client.py
+38
-19
No files found.
manage.py
View file @
82348f5a
...
...
@@ -6,7 +6,7 @@ from src.collectables import collectables
def
main
():
if
len
(
sys
.
argv
)
<
2
:
print
(
"usage: manage.py run
[options]
"
)
print
(
"usage: manage.py run"
)
if
len
(
sys
.
argv
)
is
not
2
and
sys
.
argv
[
1
]
is
not
"run"
:
print
(
"[ERROR] Command cannot be parsed. Exiting..."
)
return
...
...
src/client.py
View file @
82348f5a
#!/usr/bin/python
from
datetime
import
datetime
import
time
import
socket
import
pika
...
...
@@ -46,12 +47,12 @@ class Client:
self
.
amqp_pass
=
str
(
os
.
getenv
(
self
.
env_config
[
'amqp_pass'
]))
self
.
amqp_queue
=
str
(
os
.
getenv
(
self
.
env_config
[
'amqp_queue'
]))
self
.
amqp_vhost
=
str
(
os
.
getenv
(
self
.
env_config
[
'amqp_vhost'
]))
host_check
=
self
.
__check_envvar
(
self
.
server_address
)
port_check
=
self
.
__check_envvar
(
self
.
server_port
)
amqp_pass_check
=
self
.
__check_envvar
(
self
.
amqp_pass
)
amqp_user_check
=
self
.
__check_envvar
(
self
.
amqp_user
)
amqp_queue_check
=
self
.
__check_envvar
(
self
.
amqp_queue
)
amqp_vhost_check
=
self
.
__check_envvar
(
self
.
amqp_vhost
)
host_check
=
Client
.
__check_envvar
(
self
.
server_address
)
port_check
=
Client
.
__check_envvar
(
self
.
server_port
)
amqp_pass_check
=
Client
.
__check_envvar
(
self
.
amqp_pass
)
amqp_user_check
=
Client
.
__check_envvar
(
self
.
amqp_user
)
amqp_queue_check
=
Client
.
__check_envvar
(
self
.
amqp_queue
)
amqp_vhost_check
=
Client
.
__check_envvar
(
self
.
amqp_vhost
)
if
host_check
:
print
((
'
%(host)
s cannot be found in environmental variables.'
)
%
{
'host'
:
self
.
env_config
[
'host'
]}
...
...
@@ -69,8 +70,8 @@ class Client:
'pass'
:
self
.
env_config
[
'amqp_pass'
]}
)
raise
RuntimeError
amqp_pass_check
=
self
.
__check_envvar
(
self
.
amqp_pass
)
amqp_user_check
=
self
.
__check_envvar
(
self
.
amqp_user
)
amqp_pass_check
=
Client
.
__check_envvar
(
self
.
amqp_pass
)
amqp_user_check
=
Client
.
__check_envvar
(
self
.
amqp_user
)
if
amqp_vhost_check
or
amqp_queue_check
:
print
((
'
%(queue)
s or
%(vhost)
s cannot be '
'found in environmental variables.'
)
...
...
@@ -85,7 +86,8 @@ class Client:
self
.
beat
=
1
self
.
valid
=
True
def
__check_envvar
(
variable
):
@classmethod
def
__check_envvar
(
cls
,
variable
):
return
variable
==
"None"
or
variable
==
""
def
connect
(
self
):
...
...
@@ -172,6 +174,11 @@ class Client:
metrics
=
[]
running_vms
=
[]
procList
=
psutil
.
get_process_list
()
beats
=
{
'mem'
:
self
.
beat
%
self
.
kvmMem
,
'cpu'
:
self
.
beat
%
self
.
kvmCPU
,
'net'
:
self
.
beat
%
self
.
kvmNet
}
for
entry
in
procList
:
try
:
entry_name
=
entry
.
name
...
...
@@ -194,24 +201,20 @@ class Client:
memory
[
0
]
+
1
])])
except
IndexError
:
pass
if
((
self
.
beat
%
30
)
is
0
):
metrics
.
append
(
"
%
s.vmcount
%
d
%
d"
%
(
self
.
name
,
len
(
running_vms
),
time
.
time
()))
for
vm
in
running_vms
:
vm_proc
=
psutil
.
Process
(
vm
[
1
])
if
((
(
self
.
beat
%
self
.
kvmCPU
)
is
0
)
and
vm_proc
.
is_running
()):
if
((
beats
[
'cpu'
]
is
0
)
and
vm_proc
.
is_running
()):
mem_perc
=
vm_proc
.
get_memory_percent
()
/
100
*
vm
[
2
]
metrics
.
append
(
"vm.
%
s.memory.usage
%
f
%
d"
%
(
vm
[
0
],
mem_perc
,
time
.
time
()))
if
((
(
self
.
beat
%
self
.
kvmMem
)
is
0
)
and
vm_proc
.
is_running
()):
if
((
beats
[
'mem'
]
is
0
)
and
vm_proc
.
is_running
()):
systemtime
=
vm_proc
.
get_cpu_times
()
.
system
usertime
=
vm_proc
.
get_cpu_times
()
.
user
sumCpu
=
systemtime
+
usertime
metrics
.
append
(
"vm.
%
s.cpu.usage
%
f
%
d"
%
(
vm
[
0
],
sumCpu
,
time
.
time
()))
interfaces_list
=
psutil
.
network_io_counters
(
pernic
=
True
)
if
((
self
.
beat
%
self
.
kvmNet
)
is
0
):
interfaces_list
=
psutil
.
network_io_counters
(
pernic
=
True
)
if
beats
[
'net'
]
is
0
:
for
vm
in
running_vms
:
interfaces_list_enum
=
enumerate
(
interfaces_list
)
for
iname_index
,
iname
in
interfaces_list_enum
:
...
...
@@ -246,6 +249,12 @@ class Client:
'data'
:
interfaces_list
[
iname
]
.
bytes_recv
})
except
psutil
.
NoSuchProcess
:
print
(
'[ERROR LOG] Process lost.'
)
if
(
self
.
beat
%
30
)
is
0
:
metrics
.
append
(
(
'
%(host)
s.vmcount
%(data)
d
%(time)
d'
)
%
{
'host'
:
self
.
name
,
'data'
:
len
(
running_vms
),
'time'
:
time
.
time
()})
return
metrics
def
get_frequency
(
self
,
metricCollectors
=
[]):
...
...
@@ -259,6 +268,16 @@ class Client:
max
=
item
[
1
]
return
max
@classmethod
def
print_metrics
(
cls
,
metrics
):
for
metric
in
metrics
:
parts
=
metric
.
split
(
' '
)
parts
[
2
]
=
datetime
.
fromtimestamp
(
int
(
parts
[
2
]))
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
)
print
(
'********************************************'
)
print
(
'[M]
%(title)
s'
%
{
'title'
:
parts
[
0
]})
print
(
' -> data:
%(data)
s'
%
{
'data'
:
parts
[
1
]})
print
(
' -> time:
%(time)
s'
%
{
'time'
:
parts
[
2
]})
def
run
(
self
,
metricCollectors
=
[]):
"""
Call this method to start reporting to the server, it needs the
...
...
@@ -282,9 +301,9 @@ class Client:
vmMetrics
=
self
.
collect_vms
()
metrics
=
nodeMetrics
+
vmMetrics
if
self
.
debugMode
==
"True"
:
print
(
metrics
)
Client
.
print_metrics
(
metrics
)
if
len
(
metrics
)
is
not
0
:
if
self
.
__
send
(
metrics
)
is
False
:
if
self
.
send
(
metrics
)
is
False
:
raise
RuntimeError
time
.
sleep
(
1
)
self
.
beat
=
self
.
beat
+
1
...
...
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