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
Commit
5f1cd2ab
authored
Feb 23, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: refactor VmGraphView
parent
78a176f8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
25 deletions
+53
-25
circle/dashboard/templates/dashboard/vm-detail/home.html
+2
-0
circle/dashboard/views.py
+51
-25
No files found.
circle/dashboard/templates/dashboard/vm-detail/home.html
View file @
5f1cd2ab
...
@@ -37,8 +37,10 @@
...
@@ -37,8 +37,10 @@
</div>
<!-- id:vm-details-tags -->
</div>
<!-- id:vm-details-tags -->
</div>
</div>
<div
class=
"col-md-8"
>
<div
class=
"col-md-8"
>
{% if graphite_enabled %}
<img
src=
"{% url "
dashboard
.
views
.
vm-graph
"
instance
.
pk
"
cpu
"
"
6h
"
%}"
style=
"width:100%"
/>
<img
src=
"{% url "
dashboard
.
views
.
vm-graph
"
instance
.
pk
"
cpu
"
"
6h
"
%}"
style=
"width:100%"
/>
<img
src=
"{% url "
dashboard
.
views
.
vm-graph
"
instance
.
pk
"
memory
"
"
6h
"
%}"
style=
"width:100%"
/>
<img
src=
"{% url "
dashboard
.
views
.
vm-graph
"
instance
.
pk
"
memory
"
"
6h
"
%}"
style=
"width:100%"
/>
<img
src=
"{% url "
dashboard
.
views
.
vm-graph
"
instance
.
pk
"
network
"
"
6h
"
%}"
style=
"width:100%"
/>
<img
src=
"{% url "
dashboard
.
views
.
vm-graph
"
instance
.
pk
"
network
"
"
6h
"
%}"
style=
"width:100%"
/>
{% endif %}
</div>
</div>
</div>
</div>
circle/dashboard/views.py
View file @
5f1cd2ab
...
@@ -158,6 +158,7 @@ class VmDetailView(CheckedDetailView):
...
@@ -158,6 +158,7 @@ class VmDetailView(CheckedDetailView):
'port'
:
port
},
'port'
:
port
},
key
=
getenv
(
"PROXY_SECRET"
,
'asdasd'
)),
key
=
getenv
(
"PROXY_SECRET"
,
'asdasd'
)),
context
.
update
({
context
.
update
({
'graphite_enabled'
:
VmGraphView
.
get_graphite_url
()
is
not
None
,
'vnc_url'
:
'
%
s'
%
value
'vnc_url'
:
'
%
s'
%
value
})
})
...
@@ -1569,45 +1570,70 @@ class TransferOwnershipConfirmView(LoginRequiredMixin, View):
...
@@ -1569,45 +1570,70 @@ class TransferOwnershipConfirmView(LoginRequiredMixin, View):
return
(
instance
,
new_owner
)
return
(
instance
,
new_owner
)
class
VmGraphView
(
LoginRequiredMixin
,
View
):
class
GraphViewBase
(
LoginRequiredMixin
,
View
):
def
get
(
self
,
request
,
pk
,
metric
,
time
,
*
args
,
**
kwargs
):
metrics
=
{
'cpu'
:
(
'cactiStyle(alias(derivative(
%
s.cpu.usage),'
'"cpu usage (
%%
)"))'
),
'memory'
:
(
'cactiStyle(alias(
%
s.memory.usage,'
'"memory usage (
%%
)"))'
),
'network'
:
(
'cactiStyle(aliasByMetric('
'derivative(
%
s.network.bytes_*)))'
),
}
@staticmethod
def
get_graphite_url
():
graphite_host
=
getenv
(
"GRAPHITE_HOST"
,
None
)
graphite_host
=
getenv
(
"GRAPHITE_HOST"
,
None
)
graphite_port
=
getenv
(
"GRAPHITE_PORT"
,
None
)
graphite_port
=
getenv
(
"GRAPHITE_PORT"
,
None
)
if
(
graphite_host
in
[
''
,
None
]
or
graphite_port
in
[
''
,
None
]):
if
(
graphite_host
in
[
''
,
None
]
or
graphite_port
in
[
''
,
None
]):
logger
.
debug
(
'GRAPHITE_HOST is empty.'
)
logger
.
debug
(
'GRAPHITE_HOST is empty.'
)
return
None
return
'http://
%
s:
%
s'
%
(
graphite_host
,
graphite_port
)
def
get
(
self
,
request
,
pk
,
metric
,
time
,
*
args
,
**
kwargs
):
graphite_url
=
GraphViewBase
.
get_graphite_url
()
if
graphite_url
is
None
:
raise
Http404
()
raise
Http404
()
if
metric
not
in
[
'cpu'
,
'memory'
,
'network'
]
:
if
metric
not
in
self
.
metrics
.
keys
()
:
raise
SuspiciousOperation
()
raise
SuspiciousOperation
()
try
:
try
:
instance
=
Instance
.
objects
.
get
(
id
=
pk
)
instance
=
self
.
get_object
(
request
,
pk
)
except
Instance
.
DoesNotExist
:
except
self
.
model
.
DoesNotExist
:
raise
Http404
()
raise
Http404
()
if
not
instance
.
has_level
(
request
.
user
,
'user'
):
raise
PermissionDenied
()
targets
=
{
prefix
=
self
.
get_prefix
(
instance
)
'cpu'
:
(
'cactiStyle(alias(derivative(
%
s.cpu.usage),'
target
=
self
.
metrics
[
metric
]
%
prefix
'"cpu usage (
%%
)"))'
),
title
=
self
.
get_title
(
instance
,
metric
)
'memory'
:
(
'cactiStyle(alias(
%
s.memory.usage,'
'"memory usage (
%%
)"))'
),
'network'
:
(
'cactiStyle(aliasByMetric('
'derivative(
%
s.network.bytes_*)))'
),
}
if
metric
not
in
targets
.
keys
():
raise
SuspiciousOperation
()
prefix
=
'vm.
%
s'
%
instance
.
vm_name
target
=
targets
[
metric
]
%
prefix
title
=
'
%
s (
%
s) -
%
s'
%
(
instance
.
name
,
instance
.
vm_name
,
metric
)
params
=
{
'target'
:
target
,
params
=
{
'target'
:
target
,
'from'
:
'-
%
s'
%
time
,
'from'
:
'-
%
s'
%
time
,
'title'
:
title
.
encode
(
'UTF-8'
),
'title'
:
title
.
encode
(
'UTF-8'
),
'width'
:
'500'
,
'width'
:
'500'
,
'height'
:
'200'
}
'height'
:
'200'
}
url
=
(
'http://
%
s:
%
s/render/?
%
s'
%
(
graphite_host
,
graphite_port
,
response
=
requests
.
post
(
'
%
s/render/'
%
graphite_url
,
data
=
params
)
params
))
response
=
requests
.
post
(
url
,
data
=
params
)
return
HttpResponse
(
response
.
content
,
mimetype
=
"image/png"
)
return
HttpResponse
(
response
.
content
,
mimetype
=
"image/png"
)
def
get_prefix
(
self
,
instance
):
raise
NotImplementedError
(
"Subclass must implement abstract method"
)
def
get_title
(
self
,
instance
,
metric
):
raise
NotImplementedError
(
"Subclass must implement abstract method"
)
def
get_object
(
self
,
request
,
pk
):
instance
=
self
.
model
.
objects
.
get
(
id
=
pk
)
if
not
instance
.
has_level
(
request
.
user
,
'user'
):
raise
PermissionDenied
()
return
instance
class
VmGraphView
(
GraphViewBase
):
model
=
Instance
def
get_prefix
(
self
,
instance
):
return
'vm.
%
s'
%
instance
.
vm_name
def
get_title
(
self
,
instance
,
metric
):
return
'
%
s (
%
s) -
%
s'
%
(
instance
.
name
,
instance
.
vm_name
,
metric
)
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