mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 23:40:56 +00:00
Merge pull request #852 from pabdavis/statistics-json
[Proposal] Ability to get statistics data unformatted
This commit is contained in:
commit
8d20ea04b0
@ -111,6 +111,27 @@ func (m *UrlMap) GetMap() map[string]interface{} {
|
|||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *UrlMap) GetMapData() []map[string]interface{} {
|
||||||
|
|
||||||
|
resultLists := make([]map[string]interface{}, 0)
|
||||||
|
|
||||||
|
for k, v := range m.urlmap {
|
||||||
|
for kk, vv := range v {
|
||||||
|
result := map[string]interface{}{
|
||||||
|
"request_url": k,
|
||||||
|
"method": kk,
|
||||||
|
"times": vv.RequestNum,
|
||||||
|
"total_time": toS(vv.TotalTime),
|
||||||
|
"max_time": toS(vv.MaxTime),
|
||||||
|
"min_time": toS(vv.MinTime),
|
||||||
|
"avg_time": toS(time.Duration(int64(vv.TotalTime) / vv.RequestNum)),
|
||||||
|
}
|
||||||
|
resultLists = append(resultLists, result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultLists
|
||||||
|
}
|
||||||
|
|
||||||
// global statistics data map
|
// global statistics data map
|
||||||
var StatisticsMap *UrlMap
|
var StatisticsMap *UrlMap
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
package toolbox
|
package toolbox
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -28,4 +29,12 @@ func TestStatics(t *testing.T) {
|
|||||||
StatisticsMap.AddStatistics("POST", "/api/user/xiemengjun", "&admin.user", time.Duration(13000))
|
StatisticsMap.AddStatistics("POST", "/api/user/xiemengjun", "&admin.user", time.Duration(13000))
|
||||||
StatisticsMap.AddStatistics("DELETE", "/api/user", "&admin.user", time.Duration(1400))
|
StatisticsMap.AddStatistics("DELETE", "/api/user", "&admin.user", time.Duration(1400))
|
||||||
t.Log(StatisticsMap.GetMap())
|
t.Log(StatisticsMap.GetMap())
|
||||||
|
|
||||||
|
data := StatisticsMap.GetMapData()
|
||||||
|
b, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Log(string(b))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user