1
0
mirror of https://github.com/astaxie/beego.git synced 2025-06-11 10:00:38 +00:00

Added the UI for Admin monitor page

This commit is contained in:
Lei Cao
2014-08-14 17:35:23 +08:00
parent 14cd9e51ac
commit d314d12c77
3 changed files with 592 additions and 123 deletions

View File

@ -1,17 +1,12 @@
// Beego (http://beego.me/)
//
// @description beego is an open-source, high-performance web framework for the Go programming language.
//
// @link http://github.com/astaxie/beego for the canonical source repository
//
// @license http://github.com/astaxie/beego/blob/master/LICENSE
//
// @authors astaxie
package toolbox
import (
"fmt"
"io"
"sync"
"time"
)
@ -79,17 +74,29 @@ func (m *UrlMap) AddStatistics(requestMethod, requestUrl, requestController stri
}
// put url statistics result in io.Writer
func (m *UrlMap) GetMap(rw io.Writer) {
func (m *UrlMap) GetMap() [][]string {
m.lock.RLock()
defer m.lock.RUnlock()
fmt.Fprintf(rw, "| % -50s| % -10s | % -16s | % -16s | % -16s | % -16s | % -16s |\n", "requestUrl", "method", "times", "used", "max used", "min used", "avg used")
resultLists := make([][]string, 0)
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 {
fmt.Fprintf(rw, "| % -50s| % -10s | % -16d | % -16s | % -16s | % -16s | % -16s |\n", k,
kk, vv.RequestNum, toS(vv.TotalTime), toS(vv.MaxTime), toS(vv.MinTime), toS(time.Duration(int64(vv.TotalTime)/vv.RequestNum)),
)
result := []string{
fmt.Sprintf("% -50s", k),
fmt.Sprintf("% -10s", kk),
fmt.Sprintf("% -16d", vv.RequestNum),
fmt.Sprintf("% -16s", toS(vv.TotalTime)),
fmt.Sprintf("% -16s", toS(vv.MaxTime)),
fmt.Sprintf("% -16s", toS(vv.MinTime)),
fmt.Sprintf("% -16s", toS(time.Duration(int64(vv.TotalTime)/vv.RequestNum))),
}
resultLists = append(resultLists, result)
}
}
fmt.Println(resultLists)
return resultLists
}
// global statistics data map