mirror of
https://github.com/astaxie/beego.git
synced 2024-12-22 22:30:49 +00:00
commit
f4867aad5a
31
admin.go
31
admin.go
@ -11,6 +11,7 @@ package beego
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"text/template"
|
||||
@ -59,6 +60,7 @@ func init() {
|
||||
func adminIndex(rw http.ResponseWriter, r *http.Request) {
|
||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
||||
tmpl = template.Must(tmpl.Parse(indexTpl))
|
||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||
data := make(map[interface{}]interface{})
|
||||
tmpl.Execute(rw, data)
|
||||
}
|
||||
@ -68,6 +70,7 @@ func adminIndex(rw http.ResponseWriter, r *http.Request) {
|
||||
func qpsIndex(rw http.ResponseWriter, r *http.Request) {
|
||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
||||
tmpl = template.Must(tmpl.Parse(qpsTpl))
|
||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||
data := make(map[interface{}]interface{})
|
||||
data["Content"] = toolbox.StatisticsMap.GetMap()
|
||||
|
||||
@ -127,6 +130,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
|
||||
|
||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
||||
tmpl = template.Must(tmpl.Parse(configTpl))
|
||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||
|
||||
data["Content"] = m
|
||||
|
||||
@ -158,6 +162,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
|
||||
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)
|
||||
@ -250,6 +255,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
|
||||
data["Title"] = "Filters"
|
||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
||||
tmpl = template.Must(tmpl.Parse(routerAndFilterTpl))
|
||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||
tmpl.Execute(rw, data)
|
||||
|
||||
default:
|
||||
@ -302,16 +308,35 @@ func printTree(resultList *[][]string, t *Tree) {
|
||||
func profIndex(rw http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
command := r.Form.Get("command")
|
||||
data := make(map[interface{}]interface{})
|
||||
format := r.Form.Get("format")
|
||||
data := make(map[string]interface{})
|
||||
|
||||
var result bytes.Buffer
|
||||
if command != "" {
|
||||
toolbox.ProcessInput(command, &result)
|
||||
data["Content"] = result.String()
|
||||
data["Title"] = command
|
||||
|
||||
if format == "json" && command == "gc summary" {
|
||||
dataJson, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
rw.Header().Set("Content-Type", "application/json")
|
||||
rw.Write(dataJson)
|
||||
return
|
||||
}
|
||||
|
||||
data["Title"] = command
|
||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
||||
tmpl = template.Must(tmpl.Parse(profillingTpl))
|
||||
if command == "gc summary" {
|
||||
tmpl = template.Must(tmpl.Parse(gcAjaxTpl))
|
||||
} else {
|
||||
|
||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||
}
|
||||
tmpl.Execute(rw, data)
|
||||
} else {
|
||||
}
|
||||
@ -353,6 +378,7 @@ func healthcheck(rw http.ResponseWriter, req *http.Request) {
|
||||
data["Title"] = "Health Check"
|
||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
||||
tmpl = template.Must(tmpl.Parse(healthCheckTpl))
|
||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||
tmpl.Execute(rw, data)
|
||||
|
||||
}
|
||||
@ -401,6 +427,7 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) {
|
||||
data["Title"] = "Tasks"
|
||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
||||
tmpl = template.Must(tmpl.Parse(tasksTpl))
|
||||
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||
tmpl.Execute(rw, data)
|
||||
}
|
||||
|
||||
|
29
adminui.go
29
adminui.go
@ -27,11 +27,35 @@ For detail usage please check our document:
|
||||
var profillingTpl = `
|
||||
{{define "content"}}
|
||||
<h1>{{.Title}}</h1>
|
||||
<pre>
|
||||
{{.Content}}
|
||||
<pre id="content">
|
||||
<div>{{.Content}}</div>
|
||||
</pre>
|
||||
{{end}}`
|
||||
|
||||
var defaultScriptsTpl = ``
|
||||
|
||||
var gcAjaxTpl = `
|
||||
{{define "scripts"}}
|
||||
<script type="text/javascript">
|
||||
var app = app || {};
|
||||
(function() {
|
||||
app.$el = $('#content');
|
||||
app.getGc = function() {
|
||||
var that = this;
|
||||
$.ajax("/prof?command=gc%20summary&format=json").done(function(data) {
|
||||
that.$el.append($('<p>' + data.Content + '</p>'));
|
||||
});
|
||||
};
|
||||
$(document).ready(function() {
|
||||
setInterval(function() {
|
||||
app.getGc();
|
||||
}, 3000);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{{end}}
|
||||
`
|
||||
|
||||
var qpsTpl = `
|
||||
{{define "content"}}
|
||||
<h1>Requests statistics</h1>
|
||||
@ -311,6 +335,7 @@ 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>
|
||||
|
||||
{{template "scripts" .}}
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
|
Loading…
Reference in New Issue
Block a user