Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
0dd53d40
authored
Feb 03, 2014
by
Gregory Nagy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pep8 namingconvention + cpu_usage, ram_usage
parent
2b8a9a59
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
9 deletions
+36
-9
circle/monitor/calvin/calvin/calvin.py
+2
-6
circle/vm/models/node.py
+34
-3
No files found.
circle/monitor/calvin/calvin/calvin.py
View file @
0dd53d40
...
...
@@ -3,6 +3,7 @@ import os
class
GraphiteHandler
:
def
__init__
(
self
):
if
os
.
getenv
(
"NODE_MONITOR_SERVER"
)
is
""
:
raise
RuntimeError
...
...
@@ -16,19 +17,15 @@ class GraphiteHandler:
def
put
(
self
,
query
):
self
.
__queries
.
append
(
query
)
def
cleanUpQueries
(
self
):
self
.
__queries
=
[]
def
cleanUpResponses
(
self
):
self
.
__responses
=
[]
def
isEmpty
(
self
):
return
len
(
self
.
__queries
)
is
0
def
generateAll
(
self
):
"""
Regenerate the queries before sending.
...
...
@@ -36,7 +33,6 @@ class GraphiteHandler:
for
query
in
self
.
__queries
:
query
.
generate
()
def
send
(
self
):
"""
Generates the corrent query for the Graphite webAPI and flush all the
...
...
@@ -54,7 +50,6 @@ class GraphiteHandler:
self
.
__responses
.
append
(
response
)
self
.
cleanUpQueries
()
def
pop
(
self
):
"""
Pop the first query has got from the server.
...
...
@@ -66,6 +61,7 @@ class GraphiteHandler:
class
Query
:
def
__init__
(
self
):
"""
Query initializaion:
...
...
circle/vm/models/node.py
View file @
0dd53d40
...
...
@@ -16,6 +16,9 @@ from firewall.models import Host
from
..tasks
import
vm_tasks
from
.common
import
Trait
from
monitor.calvin
import
Query
from
monitor.calvin
import
GraphiteHandler
logger
=
getLogger
(
__name__
)
...
...
@@ -60,6 +63,7 @@ class Node(TimeStampedModel):
def
num_cores
(
self
):
"""Number of CPU threads available to the virtual machines.
"""
return
self
.
remote_query
(
vm_tasks
.
get_core_num
)
@property
...
...
@@ -93,13 +97,11 @@ class Node(TimeStampedModel):
def
get_remote_queue_name
(
self
,
queue_id
):
return
self
.
host
.
hostname
+
"."
+
queue_id
def
remote_query
(
self
,
task
,
timeout
=
1
,
raise_
=
False
,
default
=
None
):
def
remote_query
(
self
,
task
,
timeout
=
30
,
raise_
=
False
,
default
=
None
):
"""Query the given task, and get the result.
If the result is not ready in timeout secs, return default value or
raise a TimeoutError."""
if
task
!=
vm_tasks
.
ping
and
not
self
.
online
:
return
default
r
=
task
.
apply_async
(
queue
=
self
.
get_remote_queue_name
(
'vm'
),
expires
=
timeout
+
60
)
try
:
...
...
@@ -110,6 +112,35 @@ class Node(TimeStampedModel):
else
:
return
default
def
get_monitor_info
(
self
):
query
=
Query
()
handler
=
GraphiteHandler
()
query
.
setTarget
(
self
.
host
.
hostname
+
".circle"
)
query
.
setFormat
(
"json"
)
query
.
setRelativeStart
(
5
,
"minutes"
)
metrics
=
[
"cpu.usage"
,
"memory.usage"
,
"network.bytes_sent"
,
"network.bytes_received"
]
collected
=
{}
for
metric
in
metrics
:
query
.
setMetric
(
metric
)
query
.
generate
()
handler
.
put
(
query
)
handler
.
send
()
for
metric
in
metrics
:
response
=
query
.
pop
()
length
=
len
(
response
[
0
][
"datapoints"
])
cache
=
response
[
0
][
"datapoints"
][
length
-
1
][
0
]
if
cache
is
None
:
cache
=
0
collected
[
metric
]
=
cache
return
collected
def
cpu_usage
(
self
):
return
self
.
get_monitor_info
()[
"cpu.usage"
]
def
ram_usage
(
self
):
return
self
.
get_monitor_info
()[
"memory.usage"
]
def
update_vm_states
(
self
):
domains
=
{}
for
i
in
self
.
remote_query
(
vm_tasks
.
list_domains_info
,
timeout
=
5
):
...
...
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