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
d22b8ada
authored
Feb 11, 2014
by
Bach Dániel
Committed by
Őry Máté
Feb 11, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: fix graphite errors
fixes #58 fixes #56
parent
5a4a29e7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
16 deletions
+17
-16
circle/dashboard/urls.py
+1
-1
circle/dashboard/views.py
+16
-15
No files found.
circle/dashboard/urls.py
View file @
d22b8ada
...
@@ -66,7 +66,7 @@ urlpatterns = patterns(
...
@@ -66,7 +66,7 @@ urlpatterns = patterns(
url
(
r'^group/list/$'
,
GroupList
.
as_view
(),
url
(
r'^group/list/$'
,
GroupList
.
as_view
(),
name
=
'dashboard.views.group-list'
),
name
=
'dashboard.views.group-list'
),
url
((
r'^vm/(?P<pk>\d+)/graph/(?P<metric>cpu|memory|network)/'
url
((
r'^vm/(?P<pk>\d+)/graph/(?P<metric>cpu|memory|network)/'
r'(?P<time>[0-9]
+
[hdwy])$'
),
r'(?P<time>[0-9]
{1,2}
[hdwy])$'
),
VmGraphView
.
as_view
(),
VmGraphView
.
as_view
(),
name
=
'dashboard.views.vm-graph'
),
name
=
'dashboard.views.vm-graph'
),
)
)
circle/dashboard/views.py
View file @
d22b8ada
...
@@ -3,6 +3,7 @@ import json
...
@@ -3,6 +3,7 @@ import json
import
logging
import
logging
import
re
import
re
from
datetime
import
datetime
from
datetime
import
datetime
import
requests
from
django.contrib.auth.models
import
User
,
Group
from
django.contrib.auth.models
import
User
,
Group
from
django.contrib.messages
import
warning
from
django.contrib.messages
import
warning
...
@@ -1345,8 +1346,12 @@ class TransferOwnershipConfirmView(LoginRequiredMixin, View):
...
@@ -1345,8 +1346,12 @@ class TransferOwnershipConfirmView(LoginRequiredMixin, View):
class
VmGraphView
(
LoginRequiredMixin
,
View
):
class
VmGraphView
(
LoginRequiredMixin
,
View
):
def
get
(
self
,
request
,
pk
,
metric
,
time
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
pk
,
metric
,
time
,
*
args
,
**
kwargs
):
from
urllib
import
urlencode
graphite_host
=
getenv
(
"GRAPHITE_HOST"
,
None
)
import
urllib2
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'
]:
if
metric
not
in
[
'cpu'
,
'memory'
,
'network'
]:
raise
SuspiciousOperation
()
raise
SuspiciousOperation
()
...
@@ -1371,17 +1376,13 @@ class VmGraphView(LoginRequiredMixin, View):
...
@@ -1371,17 +1376,13 @@ class VmGraphView(LoginRequiredMixin, View):
prefix
=
'vm.
%
s'
%
instance
.
vm_name
prefix
=
'vm.
%
s'
%
instance
.
vm_name
target
=
targets
[
metric
]
%
prefix
target
=
targets
[
metric
]
%
prefix
title
=
'
%
s (
%
s) -
%
s'
%
(
instance
.
name
,
instance
.
vm_name
,
metric
)
title
=
'
%
s (
%
s) -
%
s'
%
(
instance
.
name
,
instance
.
vm_name
,
metric
)
params
=
{
'target'
:
target
,
params
=
urlencode
({
'target'
:
target
,
'from'
:
'-
%
s'
%
time
,
'from'
:
'-
%
s'
%
time
,
'title'
:
title
.
encode
(
'UTF-8'
),
'title'
:
title
.
encode
(
'UTF-8'
)})
'width'
:
'500'
,
url
=
(
'http://
%
s:
%
s/render/?width=500&height=200&
%
s'
'height'
:
'200'
}
%
(
getenv
(
"GRAPHITE_HOST"
),
url
=
(
'http://
%
s:
%
s/render/?
%
s'
%
(
graphite_host
,
graphite_port
,
getenv
(
"GRAPHITE_PORT"
),
params
))
params
))
response
=
requests
.
post
(
url
,
data
=
params
)
print
url
return
HttpResponse
(
response
.
content
,
mimetype
=
"image/png"
)
response
=
urllib2
.
urlopen
(
urllib2
.
Request
(
url
))
return
HttpResponse
(
response
.
read
(),
mimetype
=
"image/png"
)
print
pk
,
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