Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
a8ac37f5
Commit
a8ac37f5
authored
Jun 01, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(usage_metrics): add timer metrics
parent
b2c0679a
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
0 deletions
+120
-0
pkg/api/dashboard.go
+2
-0
pkg/metrics/metric_ref.go
+38
-0
pkg/metrics/metrics.go
+3
-0
pkg/metrics/report_usage.go
+8
-0
pkg/metrics/timer.go
+69
-0
No files found.
pkg/api/dashboard.go
View file @
a8ac37f5
...
...
@@ -77,6 +77,8 @@ func GetDashboard(c *middleware.Context) {
}
c
.
JSON
(
200
,
dto
)
metrics
.
M_Api_Dashboard_Get_Timer
.
AddTiming
(
123333
)
}
func
getUserLogin
(
userId
int64
)
string
{
...
...
pkg/metrics/metric_ref.go
View file @
a8ac37f5
...
...
@@ -5,6 +5,11 @@ type comboCounterRef struct {
metricCounter
Counter
}
type
comboTimerRef
struct
{
usageTimer
Timer
metricTimer
Timer
}
func
NewComboCounterRef
(
name
string
)
Counter
{
cr
:=
&
comboCounterRef
{}
cr
.
usageCounter
=
UsageStats
.
GetOrRegister
(
name
,
NewCounter
)
.
(
Counter
)
...
...
@@ -12,6 +17,39 @@ func NewComboCounterRef(name string) Counter {
return
cr
}
func
NewComboTimerRef
(
name
string
)
Timer
{
tr
:=
&
comboTimerRef
{}
tr
.
usageTimer
=
UsageStats
.
GetOrRegister
(
name
,
NewTimer
)
.
(
Timer
)
tr
.
metricTimer
=
MetricStats
.
GetOrRegister
(
name
,
NewTimer
)
.
(
Timer
)
return
tr
}
func
(
t
comboTimerRef
)
Clear
()
{
t
.
metricTimer
.
Clear
()
t
.
usageTimer
.
Clear
()
}
func
(
t
comboTimerRef
)
Avg
()
int64
{
panic
(
"Avg called on combotimer ref"
)
}
func
(
t
comboTimerRef
)
Min
()
int64
{
panic
(
"Avg called on combotimer ref"
)
}
func
(
t
comboTimerRef
)
Max
()
int64
{
panic
(
"Avg called on combotimer ref"
)
}
func
(
t
comboTimerRef
)
Total
()
int64
{
panic
(
"Avg called on combotimer ref"
)
}
func
(
t
comboTimerRef
)
AddTiming
(
timing
int64
)
{
t
.
metricTimer
.
AddTiming
(
timing
)
t
.
usageTimer
.
AddTiming
(
timing
)
}
func
(
c
comboCounterRef
)
Clear
()
{
c
.
usageCounter
.
Clear
()
c
.
metricCounter
.
Clear
()
...
...
pkg/metrics/metrics.go
View file @
a8ac37f5
...
...
@@ -17,6 +17,9 @@ var (
M_Api_User_SignUpCompleted
=
NewComboCounterRef
(
"api.user.signup_completed"
)
M_Api_User_SignUpInvite
=
NewComboCounterRef
(
"api.user.signup_invite"
)
M_Api_Dashboard_Get
=
NewComboCounterRef
(
"api.dashboard.get"
)
M_Api_Dashboard_Get_Timer
=
NewComboTimerRef
(
"api.dashboard_load"
)
M_Api_Dashboard_Post
=
NewComboCounterRef
(
"api.dashboard.post"
)
M_Api_Admin_User_Create
=
NewComboCounterRef
(
"api.admin.user_create"
)
M_Api_Login_Post
=
NewComboCounterRef
(
"api.login.post"
)
...
...
pkg/metrics/report_usage.go
View file @
a8ac37f5
...
...
@@ -52,6 +52,14 @@ func sendMetricUsage(sender MetricSender) {
metrics
[
name
+
".count"
]
=
metric
.
Count
()
metric
.
Clear
()
}
case
Timer
:
if
metric
.
Total
()
>
0
{
metrics
[
name
+
".avg"
]
=
metric
.
Avg
()
metrics
[
name
+
".min"
]
=
metric
.
Min
()
metrics
[
name
+
".max"
]
=
metric
.
Max
()
metrics
[
name
+
".total"
]
=
metric
.
Total
()
metric
.
Clear
()
}
}
})
...
...
pkg/metrics/timer.go
0 → 100644
View file @
a8ac37f5
package
metrics
//import "sync/atomic"
type
Timer
interface
{
AddTiming
(
int64
)
Clear
()
Avg
()
int64
Min
()
int64
Max
()
int64
Total
()
int64
}
func
NewTimer
()
Timer
{
return
&
StandardTimer
{
avg
:
0
,
min
:
0
,
max
:
0
,
total
:
0
,
count
:
0
,
}
}
func
(
this
*
StandardTimer
)
AddTiming
(
time
int64
)
{
if
this
.
min
>
time
{
this
.
min
=
time
}
if
this
.
max
<
time
{
this
.
max
=
time
}
this
.
total
+=
time
this
.
count
++
this
.
avg
=
this
.
total
/
this
.
count
}
func
(
this
*
StandardTimer
)
Clear
()
{
this
.
avg
=
0
this
.
min
=
0
this
.
max
=
0
this
.
total
=
0
this
.
count
=
0
}
func
(
this
*
StandardTimer
)
Avg
()
int64
{
return
this
.
avg
}
func
(
this
*
StandardTimer
)
Min
()
int64
{
return
this
.
min
}
func
(
this
*
StandardTimer
)
Max
()
int64
{
return
this
.
max
}
func
(
this
*
StandardTimer
)
Total
()
int64
{
return
this
.
total
}
type
StandardTimer
struct
{
total
int64
count
int64
avg
int64
min
int64
max
int64
}
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