Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
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
Show 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,25 +1570,9 @@ class TransferOwnershipConfirmView(LoginRequiredMixin, View):
...
@@ -1569,25 +1570,9 @@ 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
):
graphite_host
=
getenv
(
"GRAPHITE_HOST"
,
None
)
graphite_port
=
getenv
(
"GRAPHITE_PORT"
,
None
)
if
(
graphite_host
in
[
''
,
None
]
or
graphite_port
in
[
''
,
None
]):
logger
.
debug
(
'GRAPHITE_HOST is empty.'
)
raise
Http404
()
if
metric
not
in
[
'cpu'
,
'memory'
,
'network'
]:
raise
SuspiciousOperation
()
try
:
instance
=
Instance
.
objects
.
get
(
id
=
pk
)
except
Instance
.
DoesNotExist
:
raise
Http404
()
if
not
instance
.
has_level
(
request
.
user
,
'user'
):
raise
PermissionDenied
()
target
s
=
{
metric
s
=
{
'cpu'
:
(
'cactiStyle(alias(derivative(
%
s.cpu.usage),'
'cpu'
:
(
'cactiStyle(alias(derivative(
%
s.cpu.usage),'
'"cpu usage (
%%
)"))'
),
'"cpu usage (
%%
)"))'
),
'memory'
:
(
'cactiStyle(alias(
%
s.memory.usage,'
'memory'
:
(
'cactiStyle(alias(
%
s.memory.usage,'
...
@@ -1596,18 +1581,59 @@ class VmGraphView(LoginRequiredMixin, View):
...
@@ -1596,18 +1581,59 @@ class VmGraphView(LoginRequiredMixin, View):
'derivative(
%
s.network.bytes_*)))'
),
'derivative(
%
s.network.bytes_*)))'
),
}
}
if
metric
not
in
targets
.
keys
():
@staticmethod
def
get_graphite_url
():
graphite_host
=
getenv
(
"GRAPHITE_HOST"
,
None
)
graphite_port
=
getenv
(
"GRAPHITE_PORT"
,
None
)
if
(
graphite_host
in
[
''
,
None
]
or
graphite_port
in
[
''
,
None
]):
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
()
if
metric
not
in
self
.
metrics
.
keys
():
raise
SuspiciousOperation
()
raise
SuspiciousOperation
()
prefix
=
'vm.
%
s'
%
instance
.
vm_name
try
:
target
=
targets
[
metric
]
%
prefix
instance
=
self
.
get_object
(
request
,
pk
)
title
=
'
%
s (
%
s) -
%
s'
%
(
instance
.
name
,
instance
.
vm_name
,
metric
)
except
self
.
model
.
DoesNotExist
:
raise
Http404
()
prefix
=
self
.
get_prefix
(
instance
)
target
=
self
.
metrics
[
metric
]
%
prefix
title
=
self
.
get_title
(
instance
,
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