a9b6a0b8 by astaxie

improve the output fomate

1 parent 2758c6da
1 package admin 1 package admin
2 2
3 import ( 3 import (
4 "fmt"
4 "io" 5 "io"
5 "strconv"
6 "sync" 6 "sync"
7 "time" 7 "time"
8 ) 8 )
...@@ -64,16 +64,12 @@ func (m *UrlMap) AddStatistics(requestMethod, requestUrl, requestController stri ...@@ -64,16 +64,12 @@ func (m *UrlMap) AddStatistics(requestMethod, requestUrl, requestController stri
64 func (m *UrlMap) GetMap(rw io.Writer) { 64 func (m *UrlMap) GetMap(rw io.Writer) {
65 m.lock.RLock() 65 m.lock.RLock()
66 defer m.lock.RUnlock() 66 defer m.lock.RUnlock()
67 rw.Write([]byte("requestURL avgTime")) 67 fmt.Fprintf(rw, "| % -30s| % -10s | % -16s | % -16s | % -16s | % -16s | % -16s |\n", "requestUrl", "method", "times", "used (s)", "avg used (μs)", "max used (μs)", "min used (μs)")
68 for k, v := range m.urlmap { 68 for k, v := range m.urlmap {
69 rw.Write([]byte(k + ""))
70 for kk, vv := range v { 69 for kk, vv := range v {
71 rw.Write([]byte(kk)) 70 fmt.Fprintf(rw, "| % -30s| % -10s | % -16d | % -16f | % -16f | % -16f | % -16f |\n", k,
72 rw.Write([]byte(strconv.FormatInt(vv.RequestNum, 10))) 71 kk, vv.RequestNum, vv.TotalTime, vv.MaxTime, vv.MinTime, int64(vv.TotalTime)/vv.RequestNum,
73 rw.Write([]byte(strconv.FormatInt(int64(vv.TotalTime), 10))) 72 )
74 rw.Write([]byte(strconv.FormatInt(int64(vv.MaxTime), 10)))
75 rw.Write([]byte(strconv.FormatInt(int64(vv.MinTime), 10)))
76 rw.Write([]byte(strconv.FormatInt(int64(vv.TotalTime)/vv.RequestNum, 10)))
77 } 73 }
78 } 74 }
79 } 75 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!