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
5b1fdf66
authored
Nov 11, 2013
by
Nagy Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Critical values loaded from environmental variables.
Added frequency setup to config file.
parent
237c564b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
40 deletions
+31
-40
config/client.conf
+7
-18
src/client.py
+22
-13
src/cnfparse.py
+0
-7
src/collectables.py
+2
-2
No files found.
config/client.conf
View file @
5b1fdf66
[
Client
]
[
Client
]
Frequency
=
5
Debug
=
True
Debug
=
True
[
Server
]
Address
=
10
.
7
.
0
.
96
Port
=
5672
[
AMQP
]
Queue
=
monitor
User
=
cloud
Pass
=
password
Vhost
=
monitor
[
Metrics
]
[
Metrics
]
cpuUsage
=
True
cpuUsage
=
5
memoryUsage
=
True
memoryUsage
=
5
userCount
=
True
userCount
=
30
swapUsage
=
True
swapUsage
=
10
systemBootTime
=
True
systemBootTime
=
60
packageTraffic
=
True
packageTraffic
=
5
dataTraffic
=
True
dataTraffic
=
5
src/client.py
View file @
5b1fdf66
#!/usr/bin/python
#!/usr/bin/python
import
platform
,
collections
,
time
,
socket
,
pika
,
struct
import
platform
,
collections
,
time
,
socket
,
pika
,
struct
,
os
import
logging
import
logging
logging
.
basicConfig
()
logging
.
basicConfig
()
...
@@ -8,21 +8,18 @@ class Client:
...
@@ -8,21 +8,18 @@ class Client:
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
"""
"""
Constructor of the client requires a configuration provided by cnfparse
modul. It is a dictionary: {server_address, server_port, frequency,
debugMode, amqp_user, amqp_pass, amqp_queue}.
"""
"""
hostname
=
socket
.
gethostname
()
.
split
(
'.'
)
hostname
=
socket
.
gethostname
()
.
split
(
'.'
)
hostname
.
reverse
()
hostname
.
reverse
()
self
.
name
=
"circle."
+
"."
.
join
(
hostname
)
self
.
name
=
"circle."
+
"."
.
join
(
hostname
)
self
.
server_address
=
str
(
config
[
"server_address"
])
self
.
server_address
=
str
(
os
.
getenv
(
"GRAPHITE_SERVER_ADDRESS"
))
self
.
server_port
=
int
(
config
[
"server_port"
])
self
.
server_port
=
int
(
os
.
getenv
(
"GRAPHITE_SERVER_PORT"
))
self
.
delay
=
int
(
config
[
"frequency"
])
self
.
amqp_user
=
str
(
os
.
getenv
(
"AMQP_USER"
))
self
.
amqp_pass
=
str
(
os
.
getenv
(
"AMQP_PASS"
))
self
.
amqp_queue
=
str
(
os
.
getenv
(
"AMQP_QUEUE"
))
self
.
amqp_virtual_host
=
str
(
os
.
getenv
(
"AMQP_VIRTUAL_HOST"
))
self
.
beat
=
1
self
.
debugMode
=
config
[
"debugMode"
]
self
.
debugMode
=
config
[
"debugMode"
]
self
.
amqp_user
=
str
(
config
[
"amqp_user"
])
self
.
amqp_pass
=
str
(
config
[
"amqp_pass"
])
self
.
amqp_queue
=
str
(
config
[
"amqp_queue"
])
self
.
amqp_virtual_host
=
str
(
config
[
"amqp_virtual_host"
])
def
__connect
(
self
):
def
__connect
(
self
):
"""
"""
...
@@ -64,7 +61,8 @@ class Client:
...
@@ -64,7 +61,8 @@ class Client:
"""
"""
metrics
=
[]
metrics
=
[]
for
collector
in
metricCollectors
:
for
collector
in
metricCollectors
:
stat
=
collector
()
if
(
collector
[
1
]
%
self
.
beat
)
is
0
:
stat
=
collector
[
0
]()
metrics
.
append
((
metrics
.
append
((
self
.
name
+
"."
+
stat
.
name
+
self
.
name
+
"."
+
stat
.
name
+
"
%
d"
%
(
stat
.
value
)
+
"
%
d"
%
(
stat
.
value
)
+
...
@@ -72,6 +70,13 @@ class Client:
...
@@ -72,6 +70,13 @@ class Client:
))
))
return
metrics
return
metrics
def
__getMaxBeat
(
self
,
metricCollectors
=
[]):
max
=
0
for
item
in
metricCollectors
:
if
max
<
item
[
1
]:
max
=
item
[
1
]
return
max
def
startReporting
(
self
,
metricCollectors
=
[],
debugMode
=
False
):
def
startReporting
(
self
,
metricCollectors
=
[],
debugMode
=
False
):
"""
"""
Call this method to start reporting to the server, it needs the
Call this method to start reporting to the server, it needs the
...
@@ -87,12 +92,16 @@ class Client:
...
@@ -87,12 +92,16 @@ class Client:
(
self
.
server_address
,
self
.
server_port
,
self
.
delay
,
self
.
name
)
(
self
.
server_address
,
self
.
server_port
,
self
.
delay
,
self
.
name
)
)
)
try
:
try
:
max_beat
=
self
.
__getMaxBeat
(
metricCollectors
)
while
True
:
while
True
:
metrics
=
self
.
__collectFromNode
(
metricCollectors
)
metrics
=
self
.
__collectFromNode
(
metricCollectors
)
if
self
.
debugMode
==
"True"
:
if
self
.
debugMode
==
"True"
:
print
(
metrics
)
print
(
metrics
)
self
.
__send
(
metrics
)
self
.
__send
(
metrics
)
time
.
sleep
(
self
.
delay
)
time
.
sleep
(
1
)
self
.
beat
++
if
self
.
beat
>
max_beat
:
self
.
beat
=
1
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
print
(
"Reporting has stopped by the user. Exiting..."
)
print
(
"Reporting has stopped by the user. Exiting..."
)
finally
:
finally
:
...
...
src/cnfparse.py
View file @
5b1fdf66
...
@@ -6,14 +6,7 @@ def importConf(path_to_file):
...
@@ -6,14 +6,7 @@ def importConf(path_to_file):
config
.
read
(
path_to_file
)
config
.
read
(
path_to_file
)
params
=
{}
params
=
{}
metrics
=
{}
metrics
=
{}
params
[
"frequency"
]
=
config
.
get
(
"Client"
,
"Frequency"
)
params
[
"debugMode"
]
=
config
.
get
(
"Client"
,
"Debug"
)
params
[
"debugMode"
]
=
config
.
get
(
"Client"
,
"Debug"
)
params
[
"server_address"
]
=
config
.
get
(
"Server"
,
"Address"
)
params
[
"server_port"
]
=
config
.
get
(
"Server"
,
"Port"
)
params
[
"amqp_queue"
]
=
config
.
get
(
"AMQP"
,
"Queue"
)
params
[
"amqp_user"
]
=
config
.
get
(
"AMQP"
,
"User"
)
params
[
"amqp_pass"
]
=
config
.
get
(
"AMQP"
,
"Pass"
)
params
[
"amqp_virtual_host"
]
=
config
.
get
(
"AMQP"
,
"Vhost"
)
metrics
[
"cpu.usage"
]
=
config
.
get
(
"Metrics"
,
"cpuUsage"
)
metrics
[
"cpu.usage"
]
=
config
.
get
(
"Metrics"
,
"cpuUsage"
)
metrics
[
"memory.usage"
]
=
config
.
get
(
"Metrics"
,
"memoryUsage"
)
metrics
[
"memory.usage"
]
=
config
.
get
(
"Metrics"
,
"memoryUsage"
)
metrics
[
"user.count"
]
=
config
.
get
(
"Metrics"
,
"userCount"
)
metrics
[
"user.count"
]
=
config
.
get
(
"Metrics"
,
"userCount"
)
...
...
src/collectables.py
View file @
5b1fdf66
...
@@ -33,11 +33,11 @@ class collectables:
...
@@ -33,11 +33,11 @@ class collectables:
@staticmethod
@staticmethod
def
provide
(
requests
=
[]):
def
provide
(
requests
=
[]):
valid_keys
=
collectables
.
listKeys
()
valid_keys
=
collectables
.
listKeys
()
reqs
=
[
request
for
request
,
value
in
requests
.
items
()
if
value
==
"True"
]
reqs
=
[
request
for
request
,
value
in
requests
.
items
()
if
int
(
value
)
>
0
]
collectors
=
[]
collectors
=
[]
for
request
in
reqs
:
for
request
in
reqs
:
for
item
in
collectables
.
__collectables
[
request
]:
for
item
in
collectables
.
__collectables
[
request
]:
collectors
.
append
(
item
.
harvest
)
collectors
.
append
(
[
item
.
harvest
,
value
]
)
seen
=
set
()
seen
=
set
()
seen_add
=
seen
.
add
seen_add
=
seen
.
add
return
[
x
for
x
in
collectors
if
x
not
in
seen
and
not
seen_add
(
x
)]
return
[
x
for
x
in
collectors
if
x
not
in
seen
and
not
seen_add
(
x
)]
...
...
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