Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
421b796f
Commit
421b796f
authored
Aug 24, 2014
by
Lei Cao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added data table admin ui
parent
17006cfb
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
161 additions
and
149 deletions
+161
-149
admin.go
admin.go
+60
-62
adminui.go
adminui.go
+93
-83
statistics.go
toolbox/statistics.go
+8
-4
No files found.
admin.go
View file @
421b796f
...
...
@@ -137,121 +137,116 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
tmpl
.
Execute
(
rw
,
data
)
case
"router"
:
resultList
:=
new
([][]
string
)
content
:=
make
(
map
[
string
]
interface
{}
)
var
result
=
[]
string
{
fmt
.
Sprintf
(
"header"
),
var
fields
=
[]
string
{
fmt
.
Sprintf
(
"Router Pattern"
),
fmt
.
Sprintf
(
"Methods"
),
fmt
.
Sprintf
(
"Controller"
),
}
*
resultList
=
append
(
*
resultList
,
result
)
content
[
"Fields"
]
=
fields
methods
:=
[]
string
{}
methodsData
:=
make
(
map
[
string
]
interface
{})
for
method
,
t
:=
range
BeeApp
.
Handlers
.
routers
{
var
result
=
[]
string
{
fmt
.
Sprintf
(
"success"
),
fmt
.
Sprintf
(
"Method: %s"
,
method
),
fmt
.
Sprintf
(
""
),
fmt
.
Sprintf
(
""
),
}
*
resultList
=
append
(
*
resultList
,
result
)
resultList
:=
new
([][]
string
)
printTree
(
resultList
,
t
)
methods
=
append
(
methods
,
method
)
methodsData
[
method
]
=
resultList
}
data
[
"Content"
]
=
resultList
content
[
"Data"
]
=
methodsData
content
[
"Methods"
]
=
methods
data
[
"Content"
]
=
content
data
[
"Title"
]
=
"Routers"
tmpl
:=
template
.
Must
(
template
.
New
(
"dashboard"
)
.
Parse
(
dashboardTpl
))
tmpl
=
template
.
Must
(
tmpl
.
Parse
(
routerAndFilterTpl
))
tmpl
=
template
.
Must
(
tmpl
.
Parse
(
defaultScriptsTpl
))
tmpl
.
Execute
(
rw
,
data
)
case
"filter"
:
resultList
:=
new
([][]
string
)
content
:=
make
(
map
[
string
]
interface
{}
)
var
result
=
[]
string
{
fmt
.
Sprintf
(
"header"
),
var
fields
=
[]
string
{
fmt
.
Sprintf
(
"Router Pattern"
),
fmt
.
Sprintf
(
"Filter Function"
),
}
*
resultList
=
append
(
*
resultList
,
result
)
content
[
"Fields"
]
=
fields
filterTypes
:=
[]
string
{}
filterTypeData
:=
make
(
map
[
string
]
interface
{})
if
BeeApp
.
Handlers
.
enableFilter
{
var
result
=
[]
string
{
fmt
.
Sprintf
(
"success"
),
fmt
.
Sprintf
(
"Before Router"
),
fmt
.
Sprintf
(
""
),
}
*
resultList
=
append
(
*
resultList
,
result
)
var
filterType
string
if
bf
,
ok
:=
BeeApp
.
Handlers
.
filters
[
BeforeRouter
];
ok
{
filterType
=
"Before Router"
filterTypes
=
append
(
filterTypes
,
filterType
)
resultList
:=
new
([][]
string
)
for
_
,
f
:=
range
bf
{
var
result
=
[]
string
{
fmt
.
Sprintf
(
""
),
fmt
.
Sprintf
(
"%s"
,
f
.
pattern
),
fmt
.
Sprintf
(
"%s"
,
utils
.
GetFuncName
(
f
.
filterFunc
)),
}
*
resultList
=
append
(
*
resultList
,
result
)
}
}
result
=
[]
string
{
fmt
.
Sprintf
(
"success"
),
fmt
.
Sprintf
(
"Before Exec"
),
fmt
.
Sprintf
(
""
),
filterTypeData
[
filterType
]
=
resultList
}
*
resultList
=
append
(
*
resultList
,
result
)
if
bf
,
ok
:=
BeeApp
.
Handlers
.
filters
[
BeforeExec
];
ok
{
filterType
=
"Before Exec"
filterTypes
=
append
(
filterTypes
,
filterType
)
resultList
:=
new
([][]
string
)
for
_
,
f
:=
range
bf
{
var
result
=
[]
string
{
fmt
.
Sprintf
(
""
),
fmt
.
Sprintf
(
"%s"
,
f
.
pattern
),
fmt
.
Sprintf
(
"%s"
,
utils
.
GetFuncName
(
f
.
filterFunc
)),
}
*
resultList
=
append
(
*
resultList
,
result
)
}
filterTypeData
[
filterType
]
=
resultList
}
result
=
[]
string
{
fmt
.
Sprintf
(
"success"
),
fmt
.
Sprintf
(
"AfterExec Exec"
),
fmt
.
Sprintf
(
""
),
}
*
resultList
=
append
(
*
resultList
,
result
)
if
bf
,
ok
:=
BeeApp
.
Handlers
.
filters
[
AfterExec
];
ok
{
filterType
=
"After Exec"
filterTypes
=
append
(
filterTypes
,
filterType
)
resultList
:=
new
([][]
string
)
for
_
,
f
:=
range
bf
{
var
result
=
[]
string
{
fmt
.
Sprintf
(
""
),
fmt
.
Sprintf
(
"%s"
,
f
.
pattern
),
fmt
.
Sprintf
(
"%s"
,
utils
.
GetFuncName
(
f
.
filterFunc
)),
}
*
resultList
=
append
(
*
resultList
,
result
)
}
filterTypeData
[
filterType
]
=
resultList
}
result
=
[]
string
{
fmt
.
Sprintf
(
"success"
),
fmt
.
Sprintf
(
"Finish Router"
),
fmt
.
Sprintf
(
""
),
}
*
resultList
=
append
(
*
resultList
,
result
)
if
bf
,
ok
:=
BeeApp
.
Handlers
.
filters
[
FinishRouter
];
ok
{
filterType
=
"Finish Router"
filterTypes
=
append
(
filterTypes
,
filterType
)
resultList
:=
new
([][]
string
)
for
_
,
f
:=
range
bf
{
var
result
=
[]
string
{
fmt
.
Sprintf
(
""
),
fmt
.
Sprintf
(
"%s"
,
f
.
pattern
),
fmt
.
Sprintf
(
"%s"
,
utils
.
GetFuncName
(
f
.
filterFunc
)),
}
*
resultList
=
append
(
*
resultList
,
result
)
}
filterTypeData
[
filterType
]
=
resultList
}
}
data
[
"Content"
]
=
resultList
content
[
"Data"
]
=
filterTypeData
content
[
"Methods"
]
=
filterTypes
data
[
"Content"
]
=
content
data
[
"Title"
]
=
"Filters"
tmpl
:=
template
.
Must
(
template
.
New
(
"dashboard"
)
.
Parse
(
dashboardTpl
))
tmpl
=
template
.
Must
(
tmpl
.
Parse
(
routerAndFilterTpl
))
...
...
@@ -276,7 +271,6 @@ func printTree(resultList *[][]string, t *Tree) {
if
v
,
ok
:=
l
.
runObject
.
(
*
controllerInfo
);
ok
{
if
v
.
routerType
==
routerTypeBeego
{
var
result
=
[]
string
{
fmt
.
Sprintf
(
""
),
fmt
.
Sprintf
(
"%s"
,
v
.
pattern
),
fmt
.
Sprintf
(
"%s"
,
v
.
methods
),
fmt
.
Sprintf
(
"%s"
,
v
.
controllerType
),
...
...
@@ -284,7 +278,6 @@ func printTree(resultList *[][]string, t *Tree) {
*
resultList
=
append
(
*
resultList
,
result
)
}
else
if
v
.
routerType
==
routerTypeRESTFul
{
var
result
=
[]
string
{
fmt
.
Sprintf
(
""
),
fmt
.
Sprintf
(
"%s"
,
v
.
pattern
),
fmt
.
Sprintf
(
"%s"
,
v
.
methods
),
fmt
.
Sprintf
(
""
),
...
...
@@ -292,7 +285,6 @@ func printTree(resultList *[][]string, t *Tree) {
*
resultList
=
append
(
*
resultList
,
result
)
}
else
if
v
.
routerType
==
routerTypeHandler
{
var
result
=
[]
string
{
fmt
.
Sprintf
(
""
),
fmt
.
Sprintf
(
"%s"
,
v
.
pattern
),
fmt
.
Sprintf
(
""
),
fmt
.
Sprintf
(
""
),
...
...
@@ -347,13 +339,15 @@ func profIndex(rw http.ResponseWriter, r *http.Request) {
func
healthcheck
(
rw
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
data
:=
make
(
map
[
interface
{}]
interface
{})
resultList
:=
new
([][]
string
)
var
result
=
[]
string
{
fmt
.
Sprintf
(
"header"
),
var
result
=
[]
string
{}
fields
:=
[]
string
{
fmt
.
Sprintf
(
"Name"
),
fmt
.
Sprintf
(
"Message"
),
fmt
.
Sprintf
(
"Status"
),
}
*
resultList
=
append
(
*
resultList
,
result
)
resultList
:=
new
([][]
string
)
content
:=
make
(
map
[
string
]
interface
{})
for
name
,
h
:=
range
toolbox
.
AdminCheckList
{
if
err
:=
h
.
Check
();
err
!=
nil
{
...
...
@@ -374,7 +368,9 @@ func healthcheck(rw http.ResponseWriter, req *http.Request) {
*
resultList
=
append
(
*
resultList
,
result
)
}
data
[
"Content"
]
=
resultList
content
[
"Fields"
]
=
fields
content
[
"Data"
]
=
resultList
data
[
"Content"
]
=
content
data
[
"Title"
]
=
"Health Check"
tmpl
:=
template
.
Must
(
template
.
New
(
"dashboard"
)
.
Parse
(
dashboardTpl
))
tmpl
=
template
.
Must
(
tmpl
.
Parse
(
healthCheckTpl
))
...
...
@@ -405,17 +401,17 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) {
}
// List Tasks
content
:=
make
(
map
[
string
]
interface
{})
resultList
:=
new
([][]
string
)
var
result
=
[]
string
{
fmt
.
Sprintf
(
"header"
),
var
result
=
[]
string
{
}
var
fields
=
[]
string
{
fmt
.
Sprintf
(
"Task Name"
),
fmt
.
Sprintf
(
"Task Spec"
),
fmt
.
Sprintf
(
"Task Function"
),
fmt
.
Sprintf
(
""
),
}
*
resultList
=
append
(
*
resultList
,
result
)
for
tname
,
tk
:=
range
toolbox
.
AdminTaskList
{
result
=
[]
string
{
fmt
.
Sprintf
(
""
),
fmt
.
Sprintf
(
"%s"
,
tname
),
fmt
.
Sprintf
(
"%s"
,
tk
.
GetStatus
()),
fmt
.
Sprintf
(
"%s"
,
tk
.
GetPrev
()
.
String
()),
...
...
@@ -423,7 +419,9 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) {
*
resultList
=
append
(
*
resultList
,
result
)
}
data
[
"Content"
]
=
resultList
content
[
"Fields"
]
=
fields
content
[
"Data"
]
=
resultList
data
[
"Content"
]
=
content
data
[
"Title"
]
=
"Tasks"
tmpl
:=
template
.
Must
(
template
.
New
(
"dashboard"
)
.
Parse
(
dashboardTpl
))
tmpl
=
template
.
Must
(
tmpl
.
Parse
(
tasksTpl
))
...
...
adminui.go
View file @
421b796f
...
...
@@ -56,31 +56,35 @@ var gcAjaxTpl = `
{{end}}
`
var
qpsTpl
=
`
{{define "content"}}
var
qpsTpl
=
`{{define "content"}}
<h1>Requests statistics</h1>
<table class="table table-striped table-hover ">
{{range $i, $slice := .Content}}
<tr>
{{range $j, $elem := $slice}}
{{if eq $i 0}}
<th>
{{else}}
<td>
{{end}}
{{$elem}}
{{if eq $i 0}}
</th>
{{else}}
</td>
{{end}}
{{end}}
<thead>
<tr>
{{range .Content.Fields}}
<th>
{{.}}
</th>
{{end}}
</tr>
</thead>
<tbody>
{{range $i, $elem := .Content.Data}}
<tr>
{{range $elem}}
<td>
{{.}}
</td>
{{end}}
</tr>
{{end}}
</tbody>
</tr>
{{end}}
</table>
{{end}}
`
{{end}}`
var
configTpl
=
`
{{define "content"}}
...
...
@@ -93,49 +97,51 @@ var configTpl = `
{{end}}
`
var
routerAndFilterTpl
=
`
{{define "content"}}
var
routerAndFilterTpl
=
`
{{define "content"}}
<h1>{{.Title}}</h1>
<table class="table table-striped table-hover ">
{{range $i, $slice := .Content}}
<tr>
{{ $header := index $slice 0}}
{{if eq "header" $header }}
{{range $j, $elem := $slice}}
{{if ne $j 0}}
{{range .Content.Methods}}
<div class="panel panel-default">
<div class="panel-heading lead success"><strong>{{.}}</strong></div>
<div class="panel-body">
<table class="table table-striped table-hover ">
<thead>
<tr>
{{range $.Content.Fields}}
<th>
{{$elem}}
</th>
{{end}}
{{end}}
{{else if eq "success" $header}}
{{range $j, $elem := $slice}}
{{if ne $j 0}}
<th class="success">
{{$elem}}
{{.}}
</th>
{{end}}
{{end}}
{{else}}
{{range $j, $elem := $slice}}
{{if ne $j 0}}
</tr>
</thead>
<tbody>
{{$slice := index $.Content.Data .}}
{{range $i, $elem := $slice}}
<tr>
{{range $elem}}
<td>
{{$elem
}}
{{.
}}
</td>
{{end}}
</tr>
{{end}}
{{end}}
</tbody>
</tr>
{{end}}
</table>
</div>
</div>
{{end}}
`
var
tasksTpl
=
`
{{define "content"}}
{{end}}`
var
tasksTpl
=
`{{define "content"}}
<h1>{{.Title}}</h1>
...
...
@@ -156,59 +162,51 @@ bg-warning
<table class="table table-striped table-hover ">
{{range $i, $slice := .Content}}
<thead>
<tr>
{{range .Content.Fields}}
<th>
{{.}}
</th>
{{end}}
</tr>
</thead>
{{ $header := index $slice 0}}
{{if eq "header" $header }}
{{range $j, $elem := $slice}}
{{if ne $j 0}}
<th>
{{$elem}}
</th>
{{end}}
{{end}}
<th>
Run Task
</th>
{{else}}
{{range $j, $elem := $slice}}
{{if ne $j 0}}
<tbody>
{{range $i, $slice := .Content.Data}}
<tr>
{{range $slice}}
<td>
{{
$elem
}}
{{
.
}}
</td>
{{end}}
{{end}}
<td>
<a class="btn btn-primary btn-sm" href="/task?taskname={{index $slice 1}}">Run</a>
</td>
{{end}}
</tr>
{{end}}
</tbody>
</table>
{{end}}
`
{{end}}
`
var
healthCheckTpl
=
`
{{define "content"}}
<h1>{{.Title}}</h1>
<table class="table table-striped table-hover ">
{{range $i, $slice := .Content}}
{{ $header := index $slice 0}}
{{if eq "header" $header }}
<thead>
<tr>
{{range $j, $elem := $slice}}
{{if ne $j 0}}
{{range .Content.Fields}}
<th>
{{
$elem
}}
{{
.
}}
</th>
{{end}}
{{end}}
{{end}}
</tr>
{{else}}
</thead>
<tbody>
{{range $i, $slice := .Content.Data}}
{{ $header := index $slice 0}}
{{ if eq "success" $header}}
<tr class="success">
{{else if eq "error" $header}}
...
...
@@ -223,10 +221,13 @@ var healthCheckTpl = `
</td>
{{end}}
{{end}}
<td>
{{$header}}
</td>
</tr>
{{end}}
{{end}}
</tbody>
</table>
{{end}}`
...
...
@@ -247,6 +248,7 @@ Welcome to Beego Admin Dashboard
</title>
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<link href="//cdn.datatables.net/plug-ins/725b2a2115b/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet">
<style type="text/css">
ul.nav li.dropdown:hover > ul.dropdown-menu {
...
...
@@ -334,7 +336,15 @@ Healthcheck
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="//cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>
<script src="//cdn.datatables.net/plug-ins/725b2a2115b/integration/bootstrap/3/dataTables.bootstrap.js
"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.table').dataTable();
});
</script>
{{template "scripts" .}}
</body>
</html>
...
...
toolbox/statistics.go
View file @
421b796f
...
...
@@ -78,13 +78,16 @@ func (m *UrlMap) AddStatistics(requestMethod, requestUrl, requestController stri
}
// put url statistics result in io.Writer
func
(
m
*
UrlMap
)
GetMap
()
[][]
string
{
func
(
m
*
UrlMap
)
GetMap
()
map
[
string
]
interface
{}
{
m
.
lock
.
RLock
()
defer
m
.
lock
.
RUnlock
()
var
fields
=
[]
string
{
"requestUrl"
,
"method"
,
"times"
,
"used"
,
"max used"
,
"min used"
,
"avg used"
}
resultLists
:=
make
([][]
string
,
0
)
content
:=
make
(
map
[
string
]
interface
{})
content
[
"Fields"
]
=
fields
var
result
=
[]
string
{
"requestUrl"
,
"method"
,
"times"
,
"used"
,
"max used"
,
"min used"
,
"avg used"
}
resultLists
=
append
(
resultLists
,
result
)
for
k
,
v
:=
range
m
.
urlmap
{
for
kk
,
vv
:=
range
v
{
result
:=
[]
string
{
...
...
@@ -99,7 +102,8 @@ func (m *UrlMap) GetMap() [][]string {
resultLists
=
append
(
resultLists
,
result
)
}
}
return
resultLists
content
[
"Data"
]
=
resultLists
return
content
}
// global statistics data map
...
...
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