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
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
...
@@ -13,3 +13,4 @@ dataTraffic = 10
[
KVM
]
[
KVM
]
cpuUsage
=
5
cpuUsage
=
5
memoryUsage
=
5
memoryUsage
=
5
networkUsage
=
5
src/client.py
View file @
d4be0ad2
...
@@ -33,11 +33,13 @@ class Client:
...
@@ -33,11 +33,13 @@ class Client:
print
(
"GRAPHITE_SERVER_ADDRESS cannot be found in environmental "
print
(
"GRAPHITE_SERVER_ADDRESS cannot be found in environmental "
"variables"
"variables"
)
)
self
.
valid
=
False
return
return
if
os
.
getenv
(
"GRAPHITE_SERVER_PORT"
)
is
""
:
if
os
.
getenv
(
"GRAPHITE_SERVER_PORT"
)
is
""
:
print
(
"GRAPHITE_SERVER_PORT cannot be found in environmental "
print
(
"GRAPHITE_SERVER_PORT cannot be found in environmental "
"variables. (AMQP standard is: 5672"
"variables. (AMQP standard is: 5672"
)
)
self
.
valid
=
False
return
return
if
os
.
getenv
(
"GRAPHITE_AMQP_USER"
)
is
""
or
os
.
getenv
(
if
os
.
getenv
(
"GRAPHITE_AMQP_USER"
)
is
""
or
os
.
getenv
(
"GRAPHITE_AMQP_PASSWORD"
)
is
""
:
"GRAPHITE_AMQP_PASSWORD"
)
is
""
:
...
@@ -45,12 +47,14 @@ class Client:
...
@@ -45,12 +47,14 @@ class Client:
"found in environmental variables. (AMQP standard is: "
"found in environmental variables. (AMQP standard is: "
"guest-guest)"
"guest-guest)"
)
)
self
.
valid
=
False
return
return
if
os
.
getenv
(
"GRAPHITE_AMQP_QUEUE"
)
is
""
or
os
.
getenv
(
if
os
.
getenv
(
"GRAPHITE_AMQP_QUEUE"
)
is
""
or
os
.
getenv
(
"GRAPHITE_AMQP_VHOST"
)
is
""
:
"GRAPHITE_AMQP_VHOST"
)
is
""
:
print
(
"GRAPHITE_AMQP_QUEUE or GRAPHITE_AMQP_VHOST cannot be "
print
(
"GRAPHITE_AMQP_QUEUE or GRAPHITE_AMQP_VHOST cannot be "
"found in environmental variables."
"found in environmental variables."
)
)
self
.
valid
=
False
return
return
self
.
server_address
=
str
(
os
.
getenv
(
"GRAPHITE_SERVER_ADDRESS"
))
self
.
server_address
=
str
(
os
.
getenv
(
"GRAPHITE_SERVER_ADDRESS"
))
self
.
server_port
=
int
(
os
.
getenv
(
"GRAPHITE_SERVER_PORT"
))
self
.
server_port
=
int
(
os
.
getenv
(
"GRAPHITE_SERVER_PORT"
))
...
@@ -61,7 +65,9 @@ class Client:
...
@@ -61,7 +65,9 @@ class Client:
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"
])
self
.
kvmNet
=
int
(
config
[
"kvmNetworkUsage"
])
self
.
beat
=
1
self
.
beat
=
1
self
.
valid
=
True
def
__connect
(
self
):
def
__connect
(
self
):
...
@@ -165,6 +171,11 @@ class Client:
...
@@ -165,6 +171,11 @@ class Client:
memory
[
0
]
+
1
])])
memory
[
0
]
+
1
])])
except
IndexError
:
except
IndexError
:
pass
pass
if
((
self
.
beat
%
30
)
is
0
):
metrics
.
append
((
self
.
name
+
"."
+
"vmcount"
+
"
%
d"
%
len
(
running_vms
)
+
"
%
d"
%
(
time
.
time
())
))
for
vm
in
running_vms
:
for
vm
in
running_vms
:
vm_proc
=
psutil
.
Process
(
vm
[
1
])
vm_proc
=
psutil
.
Process
(
vm
[
1
])
if
((
self
.
beat
%
self
.
kvmCPU
)
is
0
)
and
vm_proc
.
is_running
():
if
((
self
.
beat
%
self
.
kvmCPU
)
is
0
)
and
vm_proc
.
is_running
():
...
@@ -181,13 +192,47 @@ class Client:
...
@@ -181,13 +192,47 @@ class Client:
vm_proc
.
get_cpu_times
()
.
user
)
vm_proc
.
get_cpu_times
()
.
user
)
+
"
%
d"
%
(
time
.
time
())
+
"
%
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
return
metrics
def
getMaxFrequency
(
self
,
metricCollectors
=
[]):
def
getMaxFrequency
(
self
,
metricCollectors
=
[]):
"""
"""
"""
"""
items
=
metricCollectors
+
[[
"kvmCpuUsage"
,
self
.
kvmMem
],
[
items
=
metricCollectors
+
[[
"kvmCpuUsage"
,
self
.
kvmMem
],
[
"kvmMemoryUsage"
,
self
.
kvmCPU
]]
"kvmMemoryUsage"
,
self
.
kvmCPU
]
,
[
"kvmNetworkUsage"
,
self
.
kvmNet
]
]
max
=
items
[
0
][
1
]
max
=
items
[
0
][
1
]
for
item
in
items
:
for
item
in
items
:
if
max
<
item
[
1
]:
if
max
<
item
[
1
]:
...
@@ -200,6 +245,9 @@ class Client:
...
@@ -200,6 +245,9 @@ 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
:
print
(
"[ERROR] An error has occured while connecting to the "
print
(
"[ERROR] An error has occured while connecting to the "
"server on
%
s."
"server on
%
s."
...
...
src/cnfparse.py
View file @
d4be0ad2
...
@@ -17,6 +17,7 @@ def importConf(path_to_file):
...
@@ -17,6 +17,7 @@ def importConf(path_to_file):
metrics
[
"network"
]
=
int
(
config
.
get
(
"Metrics"
,
"dataTraffic"
))
metrics
[
"network"
]
=
int
(
config
.
get
(
"Metrics"
,
"dataTraffic"
))
params
[
"kvmCpuUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"cpuUsage"
))
params
[
"kvmCpuUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"cpuUsage"
))
params
[
"kvmMemoryUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"memoryUsage"
))
params
[
"kvmMemoryUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"memoryUsage"
))
params
[
"kvmNetworkUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"networkUsage"
))
except
configparser
.
NoSectionError
:
except
configparser
.
NoSectionError
:
print
(
"Config file contains error! Reason: Missing section."
)
print
(
"Config file contains error! Reason: Missing section."
)
raise
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