mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 06:01:29 +00:00
ajax refresh gc message
This commit is contained in:
parent
7d1b03ee5d
commit
17006cfb26
31
admin.go
31
admin.go
@ -11,6 +11,7 @@ package beego
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"text/template"
|
"text/template"
|
||||||
@ -59,6 +60,7 @@ func init() {
|
|||||||
func adminIndex(rw http.ResponseWriter, r *http.Request) {
|
func adminIndex(rw http.ResponseWriter, r *http.Request) {
|
||||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
||||||
tmpl = template.Must(tmpl.Parse(indexTpl))
|
tmpl = template.Must(tmpl.Parse(indexTpl))
|
||||||
|
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||||
data := make(map[interface{}]interface{})
|
data := make(map[interface{}]interface{})
|
||||||
tmpl.Execute(rw, data)
|
tmpl.Execute(rw, data)
|
||||||
}
|
}
|
||||||
@ -68,6 +70,7 @@ func adminIndex(rw http.ResponseWriter, r *http.Request) {
|
|||||||
func qpsIndex(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(template.New("dashboard").Parse(dashboardTpl))
|
||||||
tmpl = template.Must(tmpl.Parse(qpsTpl))
|
tmpl = template.Must(tmpl.Parse(qpsTpl))
|
||||||
|
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||||
data := make(map[interface{}]interface{})
|
data := make(map[interface{}]interface{})
|
||||||
data["Content"] = toolbox.StatisticsMap.GetMap()
|
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(template.New("dashboard").Parse(dashboardTpl))
|
||||||
tmpl = template.Must(tmpl.Parse(configTpl))
|
tmpl = template.Must(tmpl.Parse(configTpl))
|
||||||
|
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||||
|
|
||||||
data["Content"] = m
|
data["Content"] = m
|
||||||
|
|
||||||
@ -158,6 +162,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
|
|||||||
data["Title"] = "Routers"
|
data["Title"] = "Routers"
|
||||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
||||||
tmpl = template.Must(tmpl.Parse(routerAndFilterTpl))
|
tmpl = template.Must(tmpl.Parse(routerAndFilterTpl))
|
||||||
|
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||||
tmpl.Execute(rw, data)
|
tmpl.Execute(rw, data)
|
||||||
case "filter":
|
case "filter":
|
||||||
resultList := new([][]string)
|
resultList := new([][]string)
|
||||||
@ -250,6 +255,7 @@ func listConf(rw http.ResponseWriter, r *http.Request) {
|
|||||||
data["Title"] = "Filters"
|
data["Title"] = "Filters"
|
||||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
||||||
tmpl = template.Must(tmpl.Parse(routerAndFilterTpl))
|
tmpl = template.Must(tmpl.Parse(routerAndFilterTpl))
|
||||||
|
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||||
tmpl.Execute(rw, data)
|
tmpl.Execute(rw, data)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -302,16 +308,35 @@ func printTree(resultList *[][]string, t *Tree) {
|
|||||||
func profIndex(rw http.ResponseWriter, r *http.Request) {
|
func profIndex(rw http.ResponseWriter, r *http.Request) {
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
command := r.Form.Get("command")
|
command := r.Form.Get("command")
|
||||||
data := make(map[interface{}]interface{})
|
format := r.Form.Get("format")
|
||||||
|
data := make(map[string]interface{})
|
||||||
|
|
||||||
var result bytes.Buffer
|
var result bytes.Buffer
|
||||||
if command != "" {
|
if command != "" {
|
||||||
toolbox.ProcessInput(command, &result)
|
toolbox.ProcessInput(command, &result)
|
||||||
data["Content"] = result.String()
|
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(template.New("dashboard").Parse(dashboardTpl))
|
||||||
tmpl = template.Must(tmpl.Parse(profillingTpl))
|
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)
|
tmpl.Execute(rw, data)
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
@ -353,6 +378,7 @@ func healthcheck(rw http.ResponseWriter, req *http.Request) {
|
|||||||
data["Title"] = "Health Check"
|
data["Title"] = "Health Check"
|
||||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
||||||
tmpl = template.Must(tmpl.Parse(healthCheckTpl))
|
tmpl = template.Must(tmpl.Parse(healthCheckTpl))
|
||||||
|
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||||
tmpl.Execute(rw, data)
|
tmpl.Execute(rw, data)
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -401,6 +427,7 @@ func taskStatus(rw http.ResponseWriter, req *http.Request) {
|
|||||||
data["Title"] = "Tasks"
|
data["Title"] = "Tasks"
|
||||||
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
tmpl := template.Must(template.New("dashboard").Parse(dashboardTpl))
|
||||||
tmpl = template.Must(tmpl.Parse(tasksTpl))
|
tmpl = template.Must(tmpl.Parse(tasksTpl))
|
||||||
|
tmpl = template.Must(tmpl.Parse(defaultScriptsTpl))
|
||||||
tmpl.Execute(rw, data)
|
tmpl.Execute(rw, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
29
adminui.go
29
adminui.go
@ -27,11 +27,35 @@ For detail usage please check our document:
|
|||||||
var profillingTpl = `
|
var profillingTpl = `
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
<h1>{{.Title}}</h1>
|
<h1>{{.Title}}</h1>
|
||||||
<pre>
|
<pre id="content">
|
||||||
{{.Content}}
|
<div>{{.Content}}</div>
|
||||||
</pre>
|
</pre>
|
||||||
{{end}}`
|
{{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 = `
|
var qpsTpl = `
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
<h1>Requests statistics</h1>
|
<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://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="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
|
||||||
|
|
||||||
|
{{template "scripts" .}}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
`
|
`
|
||||||
|
Loading…
Reference in New Issue
Block a user