Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
3b146480
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,发现更多精彩内容 >>
提交
3b146480
编写于
8月 22, 2017
作者:
P
Pawel Chojnacki
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Transaction and method instrumentation
上级
4c04444e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
58 addition
and
26 deletion
+58
-26
lib/gitlab/metrics/method_call.rb
lib/gitlab/metrics/method_call.rb
+38
-6
lib/gitlab/metrics/samplers/ruby_sampler.rb
lib/gitlab/metrics/samplers/ruby_sampler.rb
+2
-10
lib/gitlab/metrics/transaction.rb
lib/gitlab/metrics/transaction.rb
+18
-10
未找到文件。
lib/gitlab/metrics/method_call.rb
浏览文件 @
3b146480
...
...
@@ -7,13 +7,28 @@ module Gitlab
# name - The full name of the method (including namespace) such as
# `User#sign_in`.
#
# series - The series to use for storing the data.
def
initialize
(
name
,
series
)
def
self
.
call_real_duration_histogram
@call_real_duration_histogram
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_method_call_real_duration_milliseconds
,
'Method calls real duration'
,
{},
[
1
,
2
,
5
,
10
,
20
,
50
,
100
,
1000
])
end
def
self
.
call_cpu_duration_histogram
@call_duration_histogram
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_method_call_cpu_duration_milliseconds
,
'Method calls cpu duration'
,
{},
[
1
,
2
,
5
,
10
,
20
,
50
,
100
,
1000
])
end
def
initialize
(
name
,
tags
=
{})
@name
=
name
@series
=
series
@real_time
=
0
@cpu_time
=
0
@call_count
=
0
@tags
=
tags
end
# Measures the real and CPU execution time of the supplied block.
...
...
@@ -26,17 +41,34 @@ module Gitlab
@cpu_time
+=
System
.
cpu_time
-
start_cpu
@call_count
+=
1
if
above_threshold?
self
.
class
.
call_real_duration_histogram
.
observe
(
labels
,
@real_time
)
self
.
class
.
call_cpu_duration_histogram
.
observe
(
labels
,
@cpu_time
)
end
retval
end
def
labels
@labels
||=
@tags
.
merge
(
source_label
).
merge
({
call_name:
@name
})
end
def
source_label
if
Sidekiq
.
server?
{
source:
'sidekiq'
}
else
{
source:
'rails'
}
end
end
# Returns a Metric instance of the current method call.
def
to_metric
Metric
.
new
(
@
series
,
Instrumentation
.
series
,
{
duration:
real_time
,
duration:
real_time
,
cpu_duration:
cpu_time
,
call_count:
call_count
call_count:
call_count
},
method:
@name
)
...
...
lib/gitlab/metrics/samplers/ruby_sampler.rb
浏览文件 @
3b146480
...
...
@@ -17,7 +17,7 @@ module Gitlab
end
def
labels
worker_label
.
merge
(
source_label
)
{}
end
def
initialize
(
interval
)
...
...
@@ -53,7 +53,7 @@ module Gitlab
metrics
[
:memory_usage
].
set
(
labels
,
System
.
memory_usage
)
metrics
[
:file_descriptors
].
set
(
labels
,
System
.
file_descriptor_count
)
metrics
[
:sampler_duration
].
observe
(
source_label
,
(
System
.
monotonic_time
-
start_time
)
/
1000.0
)
metrics
[
:sampler_duration
].
observe
(
labels
.
merge
(
worker_label
)
,
(
System
.
monotonic_time
-
start_time
)
/
1000.0
)
ensure
GC
::
Profiler
.
clear
end
...
...
@@ -94,14 +94,6 @@ module Gitlab
end
end
def
source_label
if
Sidekiq
.
server?
{
source:
'sidekiq'
}
else
{
source:
'rails'
}
end
end
def
worker_label
return
{}
unless
defined?
(
Unicorn
::
Worker
)
worker_no
=
::
Prometheus
::
Client
::
Support
::
Unicorn
.
worker_id
...
...
lib/gitlab/metrics/transaction.rb
浏览文件 @
3b146480
...
...
@@ -21,15 +21,15 @@ module Gitlab
@metrics
=
[]
@methods
=
{}
@started_at
=
nil
@started_at
=
nil
@finished_at
=
nil
@values
=
Hash
.
new
(
0
)
@tags
=
{}
@tags
=
{}
@action
=
action
@memory_before
=
0
@memory_after
=
0
@memory_after
=
0
end
def
duration
...
...
@@ -44,12 +44,17 @@ module Gitlab
Thread
.
current
[
THREAD_KEY
]
=
self
@memory_before
=
System
.
memory_usage
@started_at
=
System
.
monotonic_time
@started_at
=
System
.
monotonic_time
yield
ensure
@memory_after
=
System
.
memory_usage
@finished_at
=
System
.
monotonic_time
@finished_at
=
System
.
monotonic_time
Gitlab
::
Metrics
.
histogram
(
"gitlab_method_duration_seconds"
.
to_sym
,
"Method duration seconds"
,
@tags
).
observe
({},
)
self
.
class
.
prometheus_gauge
(
:duration
).
set
(
@tags
,
duration
)
self
.
class
.
prometheus_gauge
(
:allocated_memory
).
set
(
@tags
,
allocated_memory
)
Thread
.
current
[
THREAD_KEY
]
=
nil
end
...
...
@@ -66,16 +71,14 @@ module Gitlab
# event_name - The name of the event (e.g. "git_push").
# tags - A set of tags to attach to the event.
def
add_event
(
event_name
,
tags
=
{})
@metrics
<<
Metric
.
new
(
EVENT_SERIES
,
{
count:
1
},
{
event:
event_name
}.
merge
(
tags
),
:event
)
Gitlab
::
Metrics
.
counter
(
"gitlab_event_
#{
event_name
}
"
.
to_sym
,
"Event
#{
event_name
}
"
,
tags
).
increment
({})
@metrics
<<
Metric
.
new
(
EVENT_SERIES
,
{
count:
1
},
labels
,
:event
)
end
# Returns a MethodCall object for the given name.
def
method_call_for
(
name
)
unless
method
=
@methods
[
name
]
@methods
[
name
]
=
method
=
MethodCall
.
new
(
name
,
Instrumentation
.
series
)
@methods
[
name
]
=
method
=
MethodCall
.
new
(
name
)
end
method
...
...
@@ -103,11 +106,16 @@ module Gitlab
@values
.
each
do
|
name
,
value
|
values
[
name
]
=
value
self
.
class
.
prometheus_gauge
(
name
).
set
(
@tags
,
value
)
end
add_metric
(
'transactions'
,
values
,
@tags
)
end
def
self
.
prometheus_gauge
(
name
)
Gitlab
::
Metrics
.
gauge
(
"gitlab_transaction_
#{
name
}
"
.
to_sym
,
"Gitlab Transaction
#{
name
}
"
)
end
def
submit
submit
=
@metrics
.
dup
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录