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
743a2c72
authored
Jan 23, 2014
by
Gregory Nagy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added collection from running kvm processes
parent
34d2ee59
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
3 deletions
+36
-3
src/client.py
+32
-2
src/cnfparse.py
+2
-0
src/metrics.py
+2
-1
No files found.
src/client.py
View file @
743a2c72
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
import
time
import
time
import
socket
import
socket
import
pika
import
pika
# import struct
import
psutil
import
logging
import
logging
import
os
import
os
...
@@ -77,7 +77,36 @@ class Client:
...
@@ -77,7 +77,36 @@ class Client:
+
"
%
d"
%
(
time
.
time
())
+
"
%
d"
%
(
time
.
time
())
))
))
return
metrics
return
metrics
def
__collectFromVMs
(
self
):
metrics
=
[]
running_vms
=
[]
for
entry
in
psutil
.
get_process_list
():
if
entry
.
name
in
"kvm"
:
search
=
[
cmd_param_index
for
cmd_param_index
,
cmd_param
in
enumerate
(
entry
.
as_dict
()[
"cmdline"
])
if
cmd_param
==
"-name"
]
memory
=
[
cmd_param_index
for
cmd_param_index
,
cmd_param
in
enumerate
(
entry
.
as_dict
()[
"cmdline"
])
if
cmd_param
==
"-m"
]
running_vms
.
append
([
entry
.
as_dict
()[
"cmdline"
][
search
[
0
]
+
1
],
entry
.
pid
,
int
(
entry
.
as_dict
()[
"cmdline"
][
memory
[
0
]
+
1
])])
for
vm
in
running_vms
:
vm_proc
=
psutil
.
Process
(
vm
[
1
])
metrics
.
append
((
self
.
name
+
"."
+
"kvm."
+
vm
[
0
]
+
"."
+
"memory.usage."
+
"
%
d"
%
(
vm_proc
.
get_memory_percent
()
/
100
*
vm
[
2
])
+
"
%
d"
%
(
time
.
time
())
))
metrics
.
append
((
self
.
name
+
"."
+
"kvm."
+
vm
[
0
]
+
"."
+
"cpu.usage"
+
"
%
d"
%
(
vm_proc
.
get_cpu_times
()
.
system
+
vm_proc
.
get_cpu_times
()
.
user
)
+
"
%
d"
%
(
time
.
time
())
))
return
metrics
def
getMaxFrequency
(
self
,
metricCollectors
=
[]):
def
getMaxFrequency
(
self
,
metricCollectors
=
[]):
max
=
metricCollectors
[
0
][
1
]
max
=
metricCollectors
[
0
][
1
]
for
item
in
metricCollectors
:
for
item
in
metricCollectors
:
...
@@ -103,6 +132,7 @@ class Client:
...
@@ -103,6 +132,7 @@ class Client:
maxFrequency
=
self
.
getMaxFrequency
(
metricCollectors
)
maxFrequency
=
self
.
getMaxFrequency
(
metricCollectors
)
while
True
:
while
True
:
metrics
=
self
.
__collectFromNode
(
metricCollectors
)
metrics
=
self
.
__collectFromNode
(
metricCollectors
)
metrics
.
append
(
self
.
__collectFromVMs
())
if
self
.
debugMode
==
"True"
:
if
self
.
debugMode
==
"True"
:
print
(
metrics
)
print
(
metrics
)
self
.
__send
(
metrics
)
self
.
__send
(
metrics
)
...
...
src/cnfparse.py
View file @
743a2c72
...
@@ -15,6 +15,8 @@ def importConf(path_to_file):
...
@@ -15,6 +15,8 @@ def importConf(path_to_file):
metrics
[
"system.boot_time"
]
=
int
(
config
.
get
(
"Metrics"
,
metrics
[
"system.boot_time"
]
=
int
(
config
.
get
(
"Metrics"
,
"systemBootTime"
))
"systemBootTime"
))
metrics
[
"network"
]
=
int
(
config
.
get
(
"Metrics"
,
"dataTraffic"
))
metrics
[
"network"
]
=
int
(
config
.
get
(
"Metrics"
,
"dataTraffic"
))
metrics
[
"kvmCpuUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"cpuUsage"
))
metrics
[
"kvmMemoryUsage"
]
=
int
(
config
.
get
(
"KVM"
,
"memoryUsage"
))
except
configparser
.
NoSectionError
:
except
configparser
.
NoSectionError
:
print
(
"Config file contains error! Reason: Missing section."
)
print
(
"Config file contains error! Reason: Missing section."
)
raise
raise
...
...
src/metrics.py
View file @
743a2c72
...
@@ -91,4 +91,4 @@ class std (Collection):
...
@@ -91,4 +91,4 @@ class std (Collection):
class
boot_time
(
Collection
.
Group
.
Metric
):
class
boot_time
(
Collection
.
Group
.
Metric
):
name
=
"system.boot_time"
name
=
"system.boot_time"
collector_function
=
ps
.
get_boot_time
collector_function
=
ps
.
get_boot_time
\ No newline at end of file
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