Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
ca3e7568
authored
2014-10-09 16:32:56 -0400
by
Bill Davis
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Add ability to get statistics in json format
1 parent
a760e46f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
toolbox/statistics.go
toolbox/statistics_test.go
toolbox/statistics.go
View file @
ca3e756
...
...
@@ -15,6 +15,7 @@
package
toolbox
import
(
"encoding/json"
"fmt"
"sync"
"time"
...
...
@@ -111,6 +112,31 @@ func (m *UrlMap) GetMap() map[string]interface{} {
return
content
}
func
(
m
*
UrlMap
)
GetMapJSON
()
([]
byte
,
error
)
{
return
json
.
Marshal
(
m
)
}
func
(
m
UrlMap
)
MarshalJSON
()
([]
byte
,
error
)
{
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
json
.
Marshal
(
resultLists
)
}
// global statistics data map
var
StatisticsMap
*
UrlMap
...
...
toolbox/statistics_test.go
View file @
ca3e756
...
...
@@ -28,4 +28,10 @@ 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
())
jsonString
,
err
:=
StatisticsMap
.
GetMapJSON
()
if
err
!=
nil
{
t
.
Errorf
(
err
.
Error
())
}
t
.
Log
(
string
(
jsonString
))
}
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment