mirror of
https://github.com/astaxie/beego.git
synced 2025-06-27 18:40:19 +00:00
Improve monitoring management module
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@ -60,14 +61,21 @@ func (m *UrlMap) AddStatistics(requestMethod, requestUrl, requestController stri
|
||||
}
|
||||
}
|
||||
|
||||
func (m *UrlMap) GetMap() []byte {
|
||||
func (m *UrlMap) GetMap(rw io.Writer) {
|
||||
m.lock.RLock()
|
||||
defer m.lock.RUnlock()
|
||||
r, err := json.Marshal(m.urlmap)
|
||||
if err != nil {
|
||||
return []byte("")
|
||||
rw.Write([]byte("requestURL avgTime"))
|
||||
for k, v := range m.urlmap {
|
||||
rw.Write([]byte(k + ""))
|
||||
for kk, vv := range v {
|
||||
rw.Write([]byte(kk))
|
||||
rw.Write([]byte(strconv.FormatInt(vv.RequestNum, 10)))
|
||||
rw.Write([]byte(strconv.FormatInt(int64(vv.TotalTime), 10)))
|
||||
rw.Write([]byte(strconv.FormatInt(int64(vv.MaxTime), 10)))
|
||||
rw.Write([]byte(strconv.FormatInt(int64(vv.MinTime), 10)))
|
||||
rw.Write([]byte(strconv.FormatInt(int64(vv.TotalTime)/vv.RequestNum, 10)))
|
||||
}
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
var StatisticsMap *UrlMap
|
||||
|
@ -1,6 +1,7 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@ -13,5 +14,5 @@ func TestStatics(t *testing.T) {
|
||||
StatisticsMap.AddStatistics("POST", "/api/user/astaxie", "&admin.user", time.Duration(1200000))
|
||||
StatisticsMap.AddStatistics("POST", "/api/user/xiemengjun", "&admin.user", time.Duration(1300000))
|
||||
StatisticsMap.AddStatistics("DELETE", "/api/user", "&admin.user", time.Duration(1400000))
|
||||
s := StatisticsMap.GetMap()
|
||||
StatisticsMap.GetMap(os.Stdout)
|
||||
}
|
||||
|
Reference in New Issue
Block a user