d314d12c by Lei Cao

Added the UI for Admin monitor page

1 parent 14cd9e51
This diff is collapsed. Click to expand it.
1 // Beego (http://beego.me/) 1 // Beego (http://beego.me/)
2 //
3 // @description beego is an open-source, high-performance web framework for the Go programming language. 2 // @description beego is an open-source, high-performance web framework for the Go programming language.
4 //
5 // @link http://github.com/astaxie/beego for the canonical source repository 3 // @link http://github.com/astaxie/beego for the canonical source repository
6 //
7 // @license http://github.com/astaxie/beego/blob/master/LICENSE 4 // @license http://github.com/astaxie/beego/blob/master/LICENSE
8 //
9 // @authors astaxie 5 // @authors astaxie
10 package toolbox 6 package toolbox
11 7
12 import ( 8 import (
13 "fmt" 9 "fmt"
14 "io"
15 "sync" 10 "sync"
16 "time" 11 "time"
17 ) 12 )
...@@ -79,17 +74,29 @@ func (m *UrlMap) AddStatistics(requestMethod, requestUrl, requestController stri ...@@ -79,17 +74,29 @@ func (m *UrlMap) AddStatistics(requestMethod, requestUrl, requestController stri
79 } 74 }
80 75
81 // put url statistics result in io.Writer 76 // put url statistics result in io.Writer
82 func (m *UrlMap) GetMap(rw io.Writer) { 77 func (m *UrlMap) GetMap() [][]string {
83 m.lock.RLock() 78 m.lock.RLock()
84 defer m.lock.RUnlock() 79 defer m.lock.RUnlock()
85 fmt.Fprintf(rw, "| % -50s| % -10s | % -16s | % -16s | % -16s | % -16s | % -16s |\n", "requestUrl", "method", "times", "used", "max used", "min used", "avg used") 80 resultLists := make([][]string, 0)
81
82 var result = []string{"requestUrl", "method", "times", "used", "max used", "min used", "avg used"}
83 resultLists = append(resultLists, result)
86 for k, v := range m.urlmap { 84 for k, v := range m.urlmap {
87 for kk, vv := range v { 85 for kk, vv := range v {
88 fmt.Fprintf(rw, "| % -50s| % -10s | % -16d | % -16s | % -16s | % -16s | % -16s |\n", k, 86 result := []string{
89 kk, vv.RequestNum, toS(vv.TotalTime), toS(vv.MaxTime), toS(vv.MinTime), toS(time.Duration(int64(vv.TotalTime)/vv.RequestNum)), 87 fmt.Sprintf("% -50s", k),
90 ) 88 fmt.Sprintf("% -10s", kk),
89 fmt.Sprintf("% -16d", vv.RequestNum),
90 fmt.Sprintf("% -16s", toS(vv.TotalTime)),
91 fmt.Sprintf("% -16s", toS(vv.MaxTime)),
92 fmt.Sprintf("% -16s", toS(vv.MinTime)),
93 fmt.Sprintf("% -16s", toS(time.Duration(int64(vv.TotalTime)/vv.RequestNum))),
94 }
95 resultLists = append(resultLists, result)
91 } 96 }
92 } 97 }
98 fmt.Println(resultLists)
99 return resultLists
93 } 100 }
94 101
95 // global statistics data map 102 // global statistics data map
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!