Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
4be6cc58
Commit
4be6cc58
authored
Oct 15, 2019
by
Qingyu Zhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add request cpu time prometheus metrics
parent
a40fa70a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
0 deletions
+33
-0
lib/gitlab/metrics/system.rb
lib/gitlab/metrics/system.rb
+13
-0
lib/gitlab/metrics/transaction.rb
lib/gitlab/metrics/transaction.rb
+12
-0
spec/lib/gitlab/metrics/transaction_spec.rb
spec/lib/gitlab/metrics/transaction_spec.rb
+8
-0
No files found.
lib/gitlab/metrics/system.rb
View file @
4be6cc58
...
...
@@ -63,6 +63,19 @@ module Gitlab
def
self
.
monotonic_time
Process
.
clock_gettime
(
Process
::
CLOCK_MONOTONIC
,
:float_second
)
end
def
self
.
thread_cpu_time
return
unless
defined?
(
Process
::
CLOCK_THREAD_CPUTIME_ID
)
Process
.
clock_gettime
(
Process
::
CLOCK_THREAD_CPUTIME_ID
,
:float_second
)
end
def
self
.
thread_cpu_duration
(
start_time
)
end_time
=
thread_cpu_time
return
unless
start_time
&&
end_time
end_time
-
start_time
end
end
end
end
lib/gitlab/metrics/transaction.rb
View file @
4be6cc58
...
...
@@ -44,6 +44,10 @@ module Gitlab
duration
.
in_milliseconds
.
to_i
end
def
thread_cpu_duration
System
.
thread_cpu_duration
(
@thread_cputime_start
)
end
def
allocated_memory
@memory_after
-
@memory_before
end
...
...
@@ -53,12 +57,14 @@ module Gitlab
@memory_before
=
System
.
memory_usage
@started_at
=
System
.
monotonic_time
@thread_cputime_start
=
System
.
thread_cpu_time
yield
ensure
@memory_after
=
System
.
memory_usage
@finished_at
=
System
.
monotonic_time
self
.
class
.
gitlab_transaction_cputime_seconds
.
observe
(
labels
,
thread_cpu_duration
)
self
.
class
.
gitlab_transaction_duration_seconds
.
observe
(
labels
,
duration
)
self
.
class
.
gitlab_transaction_allocated_memory_bytes
.
observe
(
labels
,
allocated_memory
*
1024.0
)
...
...
@@ -142,6 +148,12 @@ module Gitlab
"
#{
labels
[
:controller
]
}
#
#{
labels
[
:action
]
}
"
if
labels
&&
!
labels
.
empty?
end
define_histogram
:gitlab_transaction_cputime_seconds
do
docstring
'Transaction thread cputime'
base_labels
BASE_LABELS
buckets
[
0.1
,
0.25
,
0.5
,
1.0
,
2.5
,
5.0
]
end
define_histogram
:gitlab_transaction_duration_seconds
do
docstring
'Transaction duration'
base_labels
BASE_LABELS
...
...
spec/lib/gitlab/metrics/transaction_spec.rb
View file @
4be6cc58
...
...
@@ -27,6 +27,14 @@ describe Gitlab::Metrics::Transaction do
end
end
describe
'#thread_cpu_duration'
do
it
'returns the duration of a transaction in seconds'
do
transaction
.
run
{
}
expect
(
transaction
.
thread_cpu_duration
).
to
be
>
0
end
end
describe
'#allocated_memory'
do
it
'returns the allocated memory in bytes'
do
transaction
.
run
{
'a'
*
32
}
...
...
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