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
977465d6
authored
Feb 24, 2014
by
Gregory Nagy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixtures
parent
ec91e24f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
22 deletions
+27
-22
manage.py
+6
-6
src/client.py
+21
-16
No files found.
manage.py
View file @
977465d6
import
sys
import
sys
from
src
import
cnfparse
,
client
,
collectables
from
src
import
cnfparse
from
src
import
client
from
src.collectables
import
collectables
def
main
():
def
main
():
if
len
(
sys
.
argv
)
<
2
:
if
len
(
sys
.
argv
)
<
2
:
print
(
"usage: manage.py run [options]"
)
print
(
"usage: manage.py run [options]"
)
if
len
(
sys
.
argv
)
is
not
2
and
sys
.
argv
[
1
]
is
not
"run"
:
if
len
(
sys
.
argv
)
is
not
2
and
sys
.
argv
[
1
]
is
not
"run"
:
print
(
"[ERROR] Command cannot be parsed. Exiting..."
)
print
(
"[ERROR] Command cannot be parsed. Exiting..."
)
return
return
configuration
,
metrics
=
cnfparse
.
import_conf
(
"config/client.conf"
)
configuration
,
metrics
=
cnfparse
.
importConf
(
"config/client.conf"
)
cli
=
client
.
Client
(
configuration
)
cli
=
client
.
Client
(
configuration
)
cli
.
startReporting
(
metricCollectors
=
collectables
.
provide
(
metrics
)
metricCollectors
=
collectables
.
collectables
.
provide
(
metrics
)
)
cli
.
run
(
metricCollectors
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
src/client.py
View file @
977465d6
...
@@ -46,34 +46,38 @@ class Client:
...
@@ -46,34 +46,38 @@ class Client:
self
.
amqp_pass
=
str
(
os
.
getenv
(
self
.
env_config
[
'amqp_pass'
]))
self
.
amqp_pass
=
str
(
os
.
getenv
(
self
.
env_config
[
'amqp_pass'
]))
self
.
amqp_queue
=
str
(
os
.
getenv
(
self
.
env_config
[
'amqp_queue'
]))
self
.
amqp_queue
=
str
(
os
.
getenv
(
self
.
env_config
[
'amqp_queue'
]))
self
.
amqp_vhost
=
str
(
os
.
getenv
(
self
.
env_config
[
'amqp_vhost'
]))
self
.
amqp_vhost
=
str
(
os
.
getenv
(
self
.
env_config
[
'amqp_vhost'
]))
if
self
.
server_address
is
""
:
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
)
if
host_check
:
print
((
'
%(host)
s cannot be found in environmental variables.'
)
print
((
'
%(host)
s cannot be found in environmental variables.'
)
%
{
'host'
:
self
.
env_config
[
'host'
]}
%
{
'host'
:
self
.
env_config
[
'host'
]}
)
)
self
.
valid
=
False
raise
RuntimeError
return
if
port_check
:
if
self
.
server_port
is
""
:
print
((
'
%(port)
s cannot be found in environmental variables. '
)
print
((
'
%(port)
s cannot be found in environmental variables. '
)
%
{
'port'
:
self
.
env_config
[
'port'
]}
%
{
'port'
:
self
.
env_config
[
'port'
]}
)
)
self
.
valid
=
False
raise
RuntimeError
return
if
amqp_user_check
or
amqp_pass_check
:
if
self
.
amqp_user
is
""
or
self
.
amqp_pass
is
""
:
print
((
'
%(user)
s or
%(pass)
s cannot be '
print
((
'
%(user)
s or
%(pass)
s cannot be '
'found in environmental variables.'
)
'found in environmental variables.'
)
%
{
'user'
:
self
.
env_config
[
'amqp_user'
],
%
{
'user'
:
self
.
env_config
[
'amqp_user'
],
'pass'
:
self
.
env_config
[
'amqp_pass'
]}
'pass'
:
self
.
env_config
[
'amqp_pass'
]}
)
)
self
.
valid
=
False
raise
RuntimeError
return
amqp_pass_check
=
self
.
__check_envvar
(
self
.
amqp_pass
)
if
self
.
amqp_queue
is
""
or
self
.
amqp_vhost
is
""
:
amqp_user_check
=
self
.
__check_envvar
(
self
.
amqp_user
)
if
amqp_vhost_check
or
amqp_queue_check
:
print
((
'
%(queue)
s or
%(vhost)
s cannot be '
print
((
'
%(queue)
s or
%(vhost)
s cannot be '
'found in environmental variables.'
)
'found in environmental variables.'
)
%
{
'queue'
:
self
.
env_config
[
'amqp_queue'
],
%
{
'queue'
:
self
.
env_config
[
'amqp_queue'
],
'vhost'
:
self
.
env_config
[
'amqp_vhost'
]}
'vhost'
:
self
.
env_config
[
'amqp_vhost'
]}
)
)
self
.
valid
=
False
raise
RuntimeError
return
self
.
debugMode
=
config
[
"debugMode"
]
self
.
debugMode
=
config
[
"debugMode"
]
self
.
kvmCPU
=
int
(
config
[
"kvmCpuUsage"
])
self
.
kvmCPU
=
int
(
config
[
"kvmCpuUsage"
])
self
.
kvmMem
=
int
(
config
[
"kvmMemoryUsage"
])
self
.
kvmMem
=
int
(
config
[
"kvmMemoryUsage"
])
...
@@ -81,6 +85,9 @@ class Client:
...
@@ -81,6 +85,9 @@ class Client:
self
.
beat
=
1
self
.
beat
=
1
self
.
valid
=
True
self
.
valid
=
True
def
__check_envvar
(
variable
):
return
variable
==
"None"
or
variable
==
""
def
connect
(
self
):
def
connect
(
self
):
"""
"""
This method creates the connection to the queue of the graphite
This method creates the connection to the queue of the graphite
...
@@ -258,14 +265,12 @@ class Client:
...
@@ -258,14 +265,12 @@ class Client:
metricCollectors parameter that should be provided by the collectables
metricCollectors parameter that should be provided by the collectables
modul to work properly.
modul to work properly.
"""
"""
if
self
.
valid
is
False
:
print
(
"[ERROR] The client cannot be started."
)
raise
RuntimeError
if
self
.
connect
()
is
False
:
if
self
.
connect
()
is
False
:
hostdata
=
self
.
server_address
+
':'
+
s
elf
.
server_port
hostdata
=
self
.
server_address
+
':'
+
s
tr
(
self
.
server_port
)
print
(
"[ERROR] An error has occured while connecting to the "
print
(
"[ERROR] An error has occured while connecting to the "
"server on
%(host)
s."
"server on
%(host)
s."
%
{
'host'
:
hostdata
})
%
{
'host'
:
hostdata
})
return
else
:
else
:
print
(
'[SUCCESS] Connection established to
%(host)
s:
%(port)
s.'
print
(
'[SUCCESS] Connection established to
%(host)
s:
%(port)
s.'
%
{
'host'
:
self
.
server_address
,
%
{
'host'
:
self
.
server_address
,
...
...
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