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
d4be0ad2
authored
Jan 29, 2014
by
Gregory Nagy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Network monitoring information added to kvm processes.
parent
f161c187
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
1 deletions
+51
-1
config/client.conf
+1
-0
src/client.py
+49
-1
src/cnfparse.py
+1
-0
No files found.
config/client.conf
View file @
d4be0ad2
...
...
@@ -13,3 +13,4 @@ dataTraffic = 10
[
KVM
]
cpuUsage
=
5
memoryUsage
=
5
networkUsage
=
5
src/client.py
View file @
d4be0ad2
...
...
@@ -33,11 +33,13 @@ class Client:
print
(
"GRAPHITE_SERVER_ADDRESS cannot be found in environmental "
"variables"
)
self
.
valid
=
False
return
if
os
.
getenv
(
"GRAPHITE_SERVER_PORT"
)
is
""
:
print
(
"GRAPHITE_SERVER_PORT cannot be found in environmental "
"variables. (AMQP standard is: 5672"
)
self
.
valid
=
False
return
if
os
.
getenv
(
"GRAPHITE_AMQP_USER"
)
is
""
or
os
.
getenv
(
"GRAPHITE_AMQP_PASSWORD"
)
is
""
:
...
...
@@ -45,12 +47,14 @@ class Client:
"found in environmental variables. (AMQP standard is: "
"guest-guest)"
)
self
.
valid
=
False
return
if
os
.
getenv
(
"GRAPHITE_AMQP_QUEUE"
)
is
""
or
os
.
getenv
(
"GRAPHITE_AMQP_VHOST"
)
is
""
:
print
(
"GRAPHITE_AMQP_QUEUE or GRAPHITE_AMQP_VHOST cannot be "
"found in environmental variables."
)
self
.
valid
=
False
return
self
.
server_address
=
str
(
os
.
getenv
(
"GRAPHITE_SERVER_ADDRESS"
))
self
.
server_port
=
int
(
os
.
getenv
(
"GRAPHITE_SERVER_PORT"
))
...
...
@@ -61,7 +65,9 @@ class Client:
self
.
debugMode
=
config
[
"debugMode"
]
self
.
kvmCPU
=
int
(
config
[
"kvmCpuUsage"
])
self
.
kvmMem
=
int
(
config
[
"kvmMemoryUsage"
])
self
.
kvmNet
=
int
(
config
[
"kvmNetworkUsage"
])
self
.
beat
=
1
self
.
valid
=
True
def
__connect
(
self
):
...
...
@@ -165,6 +171,11 @@ class Client:
memory
[
0
]
+
1
])])
except
IndexError
:
pass
if
((
self
.
beat
%
30
)
is
0
):
metrics
.
append
((
self
.
name
+
"."
+
"vmcount"
+
"
%
d"
%
len
(
running_vms
)
+
"
%
d"
%
(
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
():
...
...
@@ -181,13 +192,47 @@ class Client:
vm_proc
.
get_cpu_times
()
.
user
)
+
"
%
d"
%
(
time
.
time
())
))
interfaces_list
=
psutil
.
network_io_counters
(
pernic
=
True
)
interfaces_list_enum
=
enumerate
(
interfaces_list
)
if
((
self
.
beat
%
self
.
kvmNet
)
is
0
)
and
vm_proc
.
is_running
():
for
vm
in
running_vms
:
for
iname_index
,
iname
in
interfaces_list_enum
:
if
vm
[
0
]
in
iname
:
metrics
.
append
((
self
.
name
+
"."
+
"kvm."
+
vm
[
0
]
+
"."
+
"network.packages_sent"
+
"
%
d"
%
interfaces_list
[
iname
]
.
packets_sent
+
"
%
d"
%
(
time
.
time
())
))
metrics
.
append
((
self
.
name
+
"."
+
"kvm."
+
vm
[
0
]
+
"."
+
"network.packages_recv"
+
"
%
d"
%
interfaces_list
[
iname
]
.
packets_recv
+
"
%
d"
%
(
time
.
time
())
))
metrics
.
append
((
self
.
name
+
"."
+
"kvm."
+
vm
[
0
]
+
"."
+
"network"
".bytes_sent"
+
"
%
d"
%
interfaces_list
[
iname
]
.
bytes_sent
+
"
%
d"
%
(
time
.
time
())
))
metrics
.
append
((
self
.
name
+
"."
+
"kvm."
+
vm
[
0
]
+
"."
+
"network.bytes_recv"
+
"
%
d"
%
interfaces_list
[
iname
]
.
bytes_recv
+
"
%
d"
%
(
time
.
time
())
))
return
metrics
def
getMaxFrequency
(
self
,
metricCollectors
=
[]):
"""
"""
items
=
metricCollectors
+
[[
"kvmCpuUsage"
,
self
.
kvmMem
],
[
"kvmMemoryUsage"
,
self
.
kvmCPU
]]
"kvmMemoryUsage"
,
self
.
kvmCPU
]
,
[
"kvmNetworkUsage"
,
self
.
kvmNet
]
]
max
=
items
[
0
][
1
]
for
item
in
items
:
if
max
<
item
[
1
]:
...
...
@@ -200,6 +245,9 @@ class Client:
metricCollectors parameter that should be provided by the collectables
modul to work properly.
"""
if
self
.
valid
is
False
:
print
(
"[ERROR] The client cannot be started."
)
raise
RuntimeError
if
self
.
__connect
()
is
False
:
print
(
"[ERROR] An error has occured while connecting to the "
"server on
%
s."
...
...
src/cnfparse.py
View file @
d4be0ad2
...
...
@@ -17,6 +17,7 @@ def importConf(path_to_file):
metrics
[
"network"
]
=
int
(
config
.
get
(
"Metrics"
,
"dataTraffic"
))
params
[
"kvmCpuUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"cpuUsage"
))
params
[
"kvmMemoryUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"memoryUsage"
))
params
[
"kvmNetworkUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"networkUsage"
))
except
configparser
.
NoSectionError
:
print
(
"Config file contains error! Reason: Missing section."
)
raise
...
...
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