84a4379f by astaxie

Merge pull request #739 from lei-cao/develop

Added the UI for Admin monitor page
2 parents ab71201c c347dd9e
This diff is collapsed. Click to expand it.
...@@ -11,7 +11,6 @@ package toolbox ...@@ -11,7 +11,6 @@ package toolbox
11 11
12 import ( 12 import (
13 "fmt" 13 "fmt"
14 "io"
15 "sync" 14 "sync"
16 "time" 15 "time"
17 ) 16 )
...@@ -79,17 +78,28 @@ func (m *UrlMap) AddStatistics(requestMethod, requestUrl, requestController stri ...@@ -79,17 +78,28 @@ func (m *UrlMap) AddStatistics(requestMethod, requestUrl, requestController stri
79 } 78 }
80 79
81 // put url statistics result in io.Writer 80 // put url statistics result in io.Writer
82 func (m *UrlMap) GetMap(rw io.Writer) { 81 func (m *UrlMap) GetMap() [][]string {
83 m.lock.RLock() 82 m.lock.RLock()
84 defer m.lock.RUnlock() 83 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") 84 resultLists := make([][]string, 0)
85
86 var result = []string{"requestUrl", "method", "times", "used", "max used", "min used", "avg used"}
87 resultLists = append(resultLists, result)
86 for k, v := range m.urlmap { 88 for k, v := range m.urlmap {
87 for kk, vv := range v { 89 for kk, vv := range v {
88 fmt.Fprintf(rw, "| % -50s| % -10s | % -16d | % -16s | % -16s | % -16s | % -16s |\n", k, 90 result := []string{
89 kk, vv.RequestNum, toS(vv.TotalTime), toS(vv.MaxTime), toS(vv.MinTime), toS(time.Duration(int64(vv.TotalTime)/vv.RequestNum)), 91 fmt.Sprintf("% -50s", k),
90 ) 92 fmt.Sprintf("% -10s", kk),
93 fmt.Sprintf("% -16d", vv.RequestNum),
94 fmt.Sprintf("% -16s", toS(vv.TotalTime)),
95 fmt.Sprintf("% -16s", toS(vv.MaxTime)),
96 fmt.Sprintf("% -16s", toS(vv.MinTime)),
97 fmt.Sprintf("% -16s", toS(time.Duration(int64(vv.TotalTime)/vv.RequestNum))),
98 }
99 resultLists = append(resultLists, result)
91 } 100 }
92 } 101 }
102 return resultLists
93 } 103 }
94 104
95 // global statistics data map 105 // 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!