Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
8d20ea04
Commit
8d20ea04
authored
Oct 10, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #852 from pabdavis/statistics-json
[Proposal] Ability to get statistics data unformatted
parents
28231678
5c1e8e42
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
statistics.go
toolbox/statistics.go
+21
-0
statistics_test.go
toolbox/statistics_test.go
+9
-0
No files found.
toolbox/statistics.go
View file @
8d20ea04
...
...
@@ -111,6 +111,27 @@ func (m *UrlMap) GetMap() map[string]interface{} {
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
var
StatisticsMap
*
UrlMap
...
...
toolbox/statistics_test.go
View file @
8d20ea04
...
...
@@ -15,6 +15,7 @@
package
toolbox
import
(
"encoding/json"
"testing"
"time"
)
...
...
@@ -28,4 +29,12 @@ func TestStatics(t *testing.T) {
StatisticsMap
.
AddStatistics
(
"POST"
,
"/api/user/xiemengjun"
,
"&admin.user"
,
time
.
Duration
(
13000
))
StatisticsMap
.
AddStatistics
(
"DELETE"
,
"/api/user"
,
"&admin.user"
,
time
.
Duration
(
1400
))
t
.
Log
(
StatisticsMap
.
GetMap
())
data
:=
StatisticsMap
.
GetMapData
()
b
,
err
:=
json
.
Marshal
(
data
)
if
err
!=
nil
{
t
.
Errorf
(
err
.
Error
())
}
t
.
Log
(
string
(
b
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment