Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
6db3151f
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6db3151f
编写于
9月 06, 2017
作者:
P
Pawel Chojnacki
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce missing Action concept
上级
c97dc61a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
62 addition
and
33 deletion
+62
-33
lib/gitlab/metrics/method_call.rb
lib/gitlab/metrics/method_call.rb
+19
-16
lib/gitlab/metrics/subscribers/active_record.rb
lib/gitlab/metrics/subscribers/active_record.rb
+2
-2
lib/gitlab/metrics/subscribers/rails_cache.rb
lib/gitlab/metrics/subscribers/rails_cache.rb
+35
-9
lib/gitlab/metrics/transaction.rb
lib/gitlab/metrics/transaction.rb
+6
-6
未找到文件。
lib/gitlab/metrics/method_call.rb
浏览文件 @
6db3151f
...
...
@@ -4,26 +4,29 @@ module Gitlab
class
MethodCall
attr_reader
:real_time
,
:cpu_time
,
:call_count
# name - The full name of the method (including namespace) such as
# `User#sign_in`.
#
def
self
.
call_real_duration_histogram
@call_real_duration_histogram
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_method_call_real_duration_milliseconds
,
'Method calls real duration'
,
{
call_name:
nil
},
[
1
,
2
,
5
,
10
,
20
,
50
,
100
,
1000
])
@call_real_duration_histogram
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_method_call_real_duration_seconds
,
'Method calls real duration'
,
{
action:
nil
,
call_name:
nil
},
[
1000
,
2000
,
5000
,
10000
,
20000
,
50000
,
100000
,
1000000
]
)
end
def
self
.
call_cpu_duration_histogram
@call_duration_histogram
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_method_call_cpu_duration_milliseconds
,
'Method calls cpu duration'
,
{
call_name:
nil
},
[
1
,
2
,
5
,
10
,
20
,
50
,
100
,
1000
])
@call_duration_histogram
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_method_call_cpu_duration_seconds
,
'Method calls cpu duration'
,
{
action:
nil
,
call_name:
nil
},
[
1000
,
2000
,
5000
,
10000
,
20000
,
50000
,
100000
,
1000000
]
)
end
def
initialize
(
name
)
# name - The full name of the method (including namespace) such as
# `User#sign_in`.
#
def
initialize
(
name
,
action
)
@action
=
action
@name
=
name
@real_time
=
0
@cpu_time
=
0
...
...
@@ -41,8 +44,8 @@ module Gitlab
@call_count
+=
1
if
above_threshold?
self
.
class
.
call_real_duration_histogram
.
observe
({
call_name:
@name
},
@real_time
)
self
.
class
.
call_cpu_duration_histogram
.
observe
({
call_name:
@name
},
@cpu_time
)
self
.
class
.
call_real_duration_histogram
.
observe
({
call_name:
@name
,
action:
@action
},
@real_time
)
self
.
class
.
call_cpu_duration_histogram
.
observe
({
call_name:
@name
,
action:
@action
},
@cpu_time
)
end
retval
...
...
lib/gitlab/metrics/subscribers/active_record.rb
浏览文件 @
6db3151f
...
...
@@ -8,14 +8,14 @@ module Gitlab
def
self
.
metric_sql_duration_seconds
@metric_sql_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_sql_duration_seconds
,
'SQL
duration seconds
'
,
'SQL
time
'
,
{},
[
0.001
,
0.002
,
0.005
,
0.01
,
0.02
,
0.05
,
0.1
,
0.500
,
2.0
,
10.0
]
)
end
def
sql
(
event
)
self
.
class
.
metric_sql_duration_secodnds
.
observe
({},
event
.
duration
/
1000.0
)
self
.
class
.
metric_sql_duration_secodnds
.
observe
({},
event
.
duration
/
1000.0
)
return
unless
current_transaction
current_transaction
.
increment
(
:sql_duration
,
event
.
duration
,
false
)
...
...
lib/gitlab/metrics/subscribers/rails_cache.rb
浏览文件 @
6db3151f
...
...
@@ -6,54 +6,80 @@ module Gitlab
class
RailsCache
<
ActiveSupport
::
Subscriber
attach_to
:active_support
def
self
.
metric_cache_duration_seconds
@metric_cache_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_cache_duration_seconds
,
'Cache access time'
,
{
action:
nil
,
operation:
nil
},
[
0.001
,
0.002
,
0.005
,
0.01
,
0.02
,
0.05
,
0.1
,
0.500
,
2.0
,
10.0
]
)
end
def
self
.
metric_cache_read_hit_total
@metric_cache_read_hit_total
||=
Gitlab
::
Metrics
.
counter
(
:gitlab_cache_read_hit_total
,
'Cache read hit'
,
{
action:
nil
})
end
def
self
.
metric_cache_read_miss_total
@metric_cache_read_miss_total
||=
Gitlab
::
Metrics
.
counter
(
:gitlab_cache_read_miss_total
,
'Cache read miss'
,
{
action:
nil
})
end
def
cache_read
(
event
)
increment
(
:cache_
read
,
event
.
duration
)
observe
(
:
read
,
event
.
duration
)
return
unless
current_transaction
return
if
event
.
payload
[
:super_operation
]
==
:fetch
if
event
.
payload
[
:hit
]
self
.
class
.
metric_cache_read_hit_total
.
increment
({
action:
action
})
current_transaction
.
increment
(
:cache_read_hit_count
,
1
)
else
self
.
class
.
metric_cache_read_miss_total
.
increment
({
action:
action
})
current_transaction
.
increment
(
:cache_read_miss_count
,
1
)
end
end
def
cache_write
(
event
)
increment
(
:cache_
write
,
event
.
duration
)
observe
(
:
write
,
event
.
duration
)
end
def
cache_delete
(
event
)
increment
(
:cache_
delete
,
event
.
duration
)
observe
(
:
delete
,
event
.
duration
)
end
def
cache_exist?
(
event
)
increment
(
:cache_
exists
,
event
.
duration
)
observe
(
:
exists
,
event
.
duration
)
end
def
cache_fetch_hit
(
event
)
return
unless
current_transaction
self
.
class
.
metric_cache_read_hit_total
.
increment
({
action:
action
})
current_transaction
.
increment
(
:cache_read_hit_count
,
1
)
end
def
cache_generate
(
event
)
return
unless
current_transaction
self
.
class
.
metric_cache_read_miss_total
.
increment
({
action:
action
})
current_transaction
.
increment
(
:cache_read_miss_count
,
1
)
end
def
increment
(
key
,
duration
)
def
observe
(
key
,
duration
)
return
unless
current_transaction
current_transaction
.
increment
(
:cache_duration
,
duration
)
current_transaction
.
increment
(
:cache_count
,
1
)
current_transaction
.
increment
(
"
#{
key
}
_duration"
.
to_sym
,
duration
)
current_transaction
.
increment
(
"
#{
key
}
_count"
.
to_sym
,
1
)
metric_cache_duration_seconds
.
observe
({
operation:
key
,
action:
action
},
duration
/
1000.1
)
current_transaction
.
increment
(
:cache_duration
,
duration
,
false
)
current_transaction
.
increment
(
:cache_count
,
1
,
false
)
current_transaction
.
increment
(
"
#{
key
}
_duration"
.
to_sym
,
duration
,
false
)
current_transaction
.
increment
(
"
#{
key
}
_count"
.
to_sym
,
1
,
false
)
end
private
def
action
current_transaction
&
.
action
end
def
current_transaction
Transaction
.
current
end
...
...
lib/gitlab/metrics/transaction.rb
浏览文件 @
6db3151f
...
...
@@ -43,8 +43,8 @@ module Gitlab
def
self
.
metric_transaction_duration_seconds
@metric_transaction_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_transaction_duration_seconds
,
'Transaction duration
seconds
'
,
{},
'Transaction duration'
,
{
action:
nil
},
[
0.001
,
0.002
,
0.005
,
0.01
,
0.02
,
0.05
,
0.1
,
0.500
,
2.0
,
10.0
]
)
end
...
...
@@ -53,7 +53,7 @@ module Gitlab
@metric_transaction_allocated_memory_bytes
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_transaction_allocated_memory_bytes
,
'Transaction allocated memory bytes'
,
{},
{
action:
nil
},
[
500000
,
1000000
,
2000000
,
5000000
,
10000000
,
20000000
,
100000000
]
)
end
...
...
@@ -69,8 +69,8 @@ module Gitlab
@memory_after
=
System
.
memory_usage
@finished_at
=
System
.
monotonic_time
Transaction
.
metric_transaction_duration_seconds
.
observe
({},
duration
*
1000
)
Transaction
.
metric_transaction_allocated_memory_bytes
.
observe
({},
allocated_memory
/
2
^
20
)
Transaction
.
metric_transaction_duration_seconds
.
observe
({
action:
action
},
duration
*
1000
)
Transaction
.
metric_transaction_allocated_memory_bytes
.
observe
({
action:
action
},
allocated_memory
/
2
^
20
)
Thread
.
current
[
THREAD_KEY
]
=
nil
end
...
...
@@ -94,7 +94,7 @@ module Gitlab
# Returns a MethodCall object for the given name.
def
method_call_for
(
name
)
unless
method
=
@methods
[
name
]
@methods
[
name
]
=
method
=
MethodCall
.
new
(
name
)
@methods
[
name
]
=
method
=
MethodCall
.
new
(
name
,
action
)
end
method
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录